Sunday, March 16, 2014

Programming languages are an artist's medium.

I'm an opinionated programmer, and I like that about myself. I often find myself in the next debate about best practices, ways a program could be written differently, and ways that languages could be designed differently. And one thing that's surprising about these debates is how often the phrase "a language is a tool" comes up. When I said static methods are almost always bad, I heard this:
A language is a tool. To not use all of its features is to not use it to its full potential.
Later, when I kind of wanted to remove the "=" operator in my language Wake to prevent that classic assignment-inside-an-if-condition bug, my C++minded friend also told me that languages were tools. This time, the point being that I can't prevent their misuse, and should leave them alone.

In a way the metaphor is perfect. I think both of those objections to my ideas, valid or not, were truly more along the lines of, "Don't reorganize the tools in my workshop, and definitely don't break them."

Building an App in Hammer

The idea that x is a tool is a truism. One definition of "tool" you will find online is a means to an end. Another one that I saw said a tool is something used in the practice of a vocation. So sticky notes are tools. Chairs are tools. Ideas are tools.

For such a broad definition of "tool" as this, those two arguments from my friends often don't apply. You probably don't think its a good idea to enact every idea you've ever had, to deliver its full potential. You definitely wouldn't say that sticky notes couldn't use stronger adhesive, because the ultimate usage of sticky notes will always fundamentally require knowing the best surfaces they'll adhere to.

And if C++ was the hammer of choice for your latest app, you wouldn't say you built that app in hammer.

Viewing Programming Languages as a Medium

I read a blog post by Jamis Buck stating that Java is the LEGO of programming languages...Ruby is the Play-Doh. You can build a house in Legos and you can rebuild it later in Play-Doh. His metaphor also coincidentally communicates the difficulty of swapping and merging languages.

Applications are sculpted in our medium of choice. That makes our compilers, IDEs, and VCSs into our tools - like our glazes, our bench, and our catalogs. Some languages have to be fired to finalize the end result and others don't, like clay vs marble, C++ vs PHP. Some materials can be glued together beautifully and some not so much -- depending on if you view the JNI layer as "pretty".

Problems in a language (such as the classic assignment-in-an-if-statement problem) can be viewed as bubbles in your medium, waiting to appear without warning. Problems in a language's usability can be compared to malleability, fragility, the difficulty of working against the grain.

Its been said that Java is naturally untestable, and I would agree insofar that the easiest (most intuitive) way to build an app out of Java, PHP, or C++ often leads to rigid, untestable code. That is why I am in the process of creating Wake: to create a medium that can be intuitively built into testable structures, but without the Play-Doh of Ruby. It is also my goal to make it compatible with as many other mediums as possible, something that a few recent languages have attempted.

Languages are a Medium, so Insert Lesson Here

Since a medium is a tool, many expressions involving tools translate directly over to mediums. You'll see that this isn't a meaningless distinction of semantics, but rather that there really are more applicable insights that follow from a single changed word.
Pick the right medium for the job.
Know when your app has to be light and fast, or strong and durable. Choose a medium sculpted by techniques you already know. Unlike tools, be careful to only mix compatible materials.
A bad workman blames his materials.
Know your materials, their strengths and weaknesses. If the material is a poor choice, do whatever you can to change it. Unlike tools, sometimes projects are past the point of feasibly changing the medium. At this point, a good workman is of course allowed to blame somebody else's materials.
Don't work for the material, make the material work for you.
For tools like a hammer, this is an encouragement to sometimes just use the handle, or to occasionally use it to prop open a door. In other words, it's a way of saying you may be doing too little with your hammer. For a material, however, this advice warns you of doing too much. Don't go against the grain. Don't make deep gashes that may have to be filled in later. See the shapes already present in your block of wood and blend them into your design. Do as little with the material as you have to in order to get a final product.

Lastly, My Own Personal Advice

Languages are a medium. The future will always offer new and improved concoctions. Do not be afraid to learn how to work with them.

No comments:

Post a Comment