Blog

Code as art versus Code as a tool

Posted by On Jan 03, 2013 In Web Development

I don’t have a deep history writing professional code, which sometimes makes me reluctant to write blog posts that don’t add some sort of new trick or fascinating javascript library I created. When I watch a seasoned expert craft a script, I’m still mystified as they pull functions and tools out of thin air that solve a problem in a clever 10 lines. As I improve as a programmer, I have noticed a dichotomy in programming that I find really fascinating: code as art vs code as a tool.

Before I began programming, when someone pulled up a source code on a web page or started running unix commands in a terminal window it was all gobbledegook. It was just random strings of punctuation marks I rarely use and abbreviations that I didn’t understand. Now, code appears in chunks, recognizable chunks with purpose I can discern. I don’t pinpoint the exact functioning, but instead get a feel for and make predictions about how data might be passed through a function. Everything is structured with a purpose and moving one comma out of place or forgetting to close a parentheses could break the machine, and everything would fail. To me, it appeared a profession with no tolerance for error.

I quickly found out that programming, and specifically programming for the web, is a mess. It’s filled with dead ends, variables with non-descript names, and weird work arounds. I regularly find myself knocking wonky elements off the screen or hiding them under another element, sometimes even hiding things in plain sight to create different illusions. Regularly, programmers refer to ways to “trick” the server or browser, like we are some sort of magician hiding our true intentions from the machine.

These goofy hacks create beautiful corners of the web, some with no purpose (this one has raptors, I highly recommend checking it out), or others provide comical and useful tools used every day to generate cross-browser CSS. I think code with syntax highlighting looks pretty cool on it’s own, even without any context. codescreenshot

On the other end, we have machine-like code optimized to the last character, silently performing their duty millions of times a day. These honed programs and snippets are not designed to be pretty, but to serve a narrow function and nothing more. They are trimmed of the fat of the human brain, minified into unreadable mashes of code.

Take for instance the Google Analytics tracking code. Don’t mind if you don’t understand the script, I don’t even know what most of it does. Wtf is gaq.

<script type=”text/javascript”>

var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-XXXXX-X’]);
_gaq.push([‘_trackPageview’]);

(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();

</script>

In under 15 lines of javascript, Google opens up a window onto all of your visitors. You can see how long they stay, which country they are from, what out-dated browser they use. Obviously, there is a work-horse web-app powering Google Analytics, but I appreciate these super-optimized snippets.

Websites like CSS Zen Garden and WordPress like to analogize code to poetry, and I would have to agree. You must choose every character deliberately and remain focused on what you want to express. But at the end of the day, your code is converted into 01010101 and back in time frames that are nearly inconceivable and across oceans that used to take years to travel. Or hell, you could have written some of the millions of lines of C++ that landed with the Mars rover. What test cases do you even begin to prepare for on an alien planet?

No comments

There are no comments on this post yet.

No comments