Building Beautiful Apps from Ugly Code

Programming in the 21st Century - James Hague - September 08, 2011

I wish I could entirely blame my computer science degree for undermining my sense of aesthetics, but I can’t. Much of it was self-inflicted from being too immersed in programming and technology for its own sake, and it took me a long time to recover.




There’s a tremendous emphasis on elegance and beauty in highbrow coding circles. A sort implemented in three lines of Haskell. A startlingly readable controller for a washing machine in half a dozen lines of Forth. Any example from Structure and Interpretation of Computer Programs. It’s difficult to read books, follow blogs, take classes, and not start developing an eye for elegant code.




All those examples of beauty and elegance tend to be small. The smallness—the conciseness—is much of the elegance. If you’ve ever implemented a sorting algorithm in C, then you likely had three lines of code just to swap values. Three lines for the entire sort is beautifully concise.




Except that beauty rarely scales.




Pick any program outside of the homework range, any program of 200+ lines, and it’s not going to meet a standard of elegance. There are special cases and hacks and convoluted spots where the code might be okay except that the spec calls for things which are at odds with writing code that crackles with craftsmanship. There are global variable updates and too many parameters are passed around. Bulky functions because things can’t be reduced to one or two clean possibilities. Lines of code wasted translating between types. Odd-looking flag tests needed to fix reported bugs.




Small, elegant building blocks are used to construct imperfect, even ugly, programs. And yet those imperfect, ugly programs may actually be beautiful applications.




The implications of that are worth thinking about. Functional programming zealots insist upon the complete avoidance of destructive updates, yet there’s a curious lack of concrete examples of programs which meet that standard of purity. Even if there were, the purely functional style does not any in way translate to the result being a stunningly powerful and easy to use application. There’s no cause and effect. And if there is a stunningly powerful and easy to use application, does that mean the code that runs the whole thing is a paragon of beauty? Of course not.




The only sane solution is to focus on the end application first. Get the user to experience the beauty of it and be happy. Don’t compromise that because, behind the scenes, the code to draw ovals is more elegant than the code to draw rounded rectangles.




(If you liked this, you might enjoy Write Code Like You Just Learned How to Program.)



Categories: Blogs  Programming in the 21st Century  

Comments

anonymous avatar

I would say that beauty *does* scale, just not at the lines-of-code level. Look at architechtures, frameworks, workflows, or protocols, and you’ll see some that are elegant and beautifull.

Appreciating the beauty of something is not O(1). The more complicated an objects, the more time needed to realize the full beauty/uglyness of it.

Posted by moltonel on 09 Sep 2011 at 09:00



 
anonymous avatar

Hey! I simply want to give a huge thumbs up for the good information you’ve gotten here on this post. I will probably be coming again to your blog for extra soon.
ラルフローレン ベビー服

Posted by vindiesel on 16 Dec 2011 at 17:16



 
anonymous avatar

I have been reading blogs on this subject for a few hours now and your content is the most informed I have read thus far. Thanks for putting this information in one place.
<a >essay services reviews</a>

Posted by vindiesel on 04 Jan 2012 at 16:43



 
anonymous avatar

I have been reading blogs on this subject for a few hours now and your content is the most informed I have read thus far. Thanks for putting this information in essay services reviews
one place.

Posted by top essay writing services on 04 Jan 2012 at 16:44



 
anonymous avatar

I completely agree with you. I really like this article. It contains a lot of useful information. I can set up my new idea from this post.cna exams

Posted by vindiesel on 15 Jan 2012 at 19:48



 
anonymous avatar

Thanks for sharing this. I really like this allocation due to some good information about building beautiful apps from ugly code. Thanks mate and keep it up.

hospital emergency room

Posted by Adam Ghilchritst on 05 Apr 2012 at 05:01



 
anonymous avatar

I just wanted to comment your blog and say that I really enjoyed reading your blog post here. It was very informative. Keep it up and I’ll be back to read more soon.

games download online

Posted by Alex martin on 06 Apr 2012 at 06:03



 
anonymous avatar

Excellent post. I want to thank you for this informative read. I really appreciate you sharing this great post. Keep it up!


dancing with stars contestants

Posted by Ana Farguson on 30 Apr 2012 at 15:25



 
anonymous avatar

I have started to clean up my coding skills after I’ve started working on a cloud protection application that involved other programmers too. I thought that my code will also be reviewed by my fellow programmers and I wanted to make it as clean and easy to follow as possible. This kind of thinking will surely help me get more organized and more productive in the future.

Posted by DenFletcher on 04 May 2012 at 10:59



 


Add comment

Name:

Email:

URL:

Smileys

Remember my personal information

Notify me of follow-up comments?