Give me a sheet of paper and something to write with, and I'll turn the world upside down — Nietzsche

ProgrammingJul 2021

I’ve had a somewhat liberating epiphany recently: The methods built-in to a programming language can also be written using simple procedures like if-else statements and loops. Built-in methods exist to bundle complicated procedures into one simple function — this makes programming easier. But they are also simply solutions to common problems, so a programmer doesn’t have to program them over and over again.

In realizing this, I find myself recalling my first programming experiences with C at Harvard’s CS50. This is a language with a kind of brute yet beautiful simplicity. Then came Python, Swift, and now Javascript. But across all these, what I’m recognizing is that programming is problem solving, whether I use simple or complex tools.

With this, I don’t mean to be reductionist towards any programming language in particular. I love Python’s elegance, Swift’s clarity, and Javascript’s messy-beautiful versatility. But what I’m getting now is quite something else.

In design, there are thousands of nuts and bolts to every tool. Sketch and Figma are full of smart details meant to make a designer’s life easier. But I also know, by virtue of my experience, that all I need is a blank canvas, the rectangle tool, type and color. Not to be overly simplistic, but even that could be reduced to a sheet of paper and a pen.

Tools are helpful, but the work happens in thinking about and experimenting on a problem enough that eventually a solution starts to emerge — despite the tool. My crazy insight is that programming seems to be the same.

To concretize this epiphany, I wrote my own version of Javascript;s Array.prototype.splice(). I did it knowing that I am but a simple student. I’m sure my algorithm could be made better, cleaner, faster, more efficient, et al. — read: impostor syndrome. But what a fun experience to realize, in practice, that a method like splice is really just a beautiful function, like my own beautiful functions.

Splice is a robust method. With one single line of code, I can shorten an array, remove items at specific index positions, or even insert multiple new items at a location. It works in place and therefore on the array itself.

In my own version of splice, I built a couple of smaller methods that perform all the major procedures like shorten an array, delete an item(s) at a particular location, and insert as many elements as passed onto the function sequentially into the array.

A method to shorten the array

Methods to delete an item(s)

A method to insert an item(s)

Finally, they all come together as a single splice method with a nice O(n) asymptotic complexity. Like in Javascript’s original splice, my splice method takes in as many arguments as needed, and based on that updates its behavior internally with no outside input.

All in all, lot’s to learn – but that was fun.

No items found.