A web design and development community for people with a thirst for knowledge. Follow the Community on Twitter right here.
Buildings that serve a purpose and enhance the beauty of the environment around them are created by artists disguised as architects. Buildings that are hideous and need to be torn down are created by architects. The difference is that the artist takes pride in what he is doing. He understands that his work will be viewed by many people and therefore stakes his pride in the building. The architect knows that he got paid to finish something within a timeframe and therefore could care less about how people see his building. In fact he does not even think the building is his anyways.
Hackers act the same way as architects. They gather bricks and cement and throw them together and call it a house. Although it works, it will more than likely not stand the test of time. As a programmer/front end developer you should not see your code as a means to an end. It should provide a source for others to look at and revel in its beauty. Beautiful code has more to do with the functionality of the code and how it works than the actual look of it. I want to get lost in the beauty of its design. I want to see how simple you make complicated sequences appear. A quick example is the Towers of Hanoi done using recursive functions. There are plenty of ways to go about this problem, but the recursive approach shows you how code can be an art. Although very rarely you see recursiveness used in large designs you must marvel at the simplicity of the design to such a complicated problem. To me simplicity of design is beauty.
In What is Design? I answered the question by saying:
Design is the process of finding the most elegant answer to the question of ‘how do I?
Does this not apply to code as well? We might not find the most elegant solution initially, but after a couple of iterations one would hope we would finally get there.
A lot of programmers are given code that is not theirs and they are told to refactor it or make it work better. This is the greatest time for showing that programming can be an art and probably an even better time to wish that every programmer treated their code as an art form. It is like someone giving you a marble statue of something that appears to be a man and when you are done with it looks like David.
If you tackle your code as an artist then you are putting an investment into it. You are putting yourself behind the code so that the code represents you. A lot of open source projects need to take heed and listen. Just because you start a great idea for a project and start an account on GitHub it does not mean you will draw in the legions of the open source army. No doubt you will draw interest, but if your code is a catastrophe and the design is horrific then that interest will die quickly. Beautiful code and design lasts like great pieces of art. There is a reason Ruby on Rails remains popular and it goes beyond the fact that 37signals hypes it.
Programming is an art because you are creating your own masterpiece. You are creating your own exhibit for the world to see. Artists don’t paint just so they can keep their works to themselves. They paint because they want the world to enjoy what they enjoy. Why should coding be any different? Of course if you are writing a small program for yourself, write it however you want. I write small little programs that serve my purposes, but I also design them as if I were letting the whole world see them. For some reason I can’t let bad design and ugly code get in my way. I take pride in what I do because I take it seriously and I wish others to take me seriously as well.
Granted, and this is where a majority of the coders start to nod their head, there just isn't enough time to design the most elegant solution. You are under a crunch and you know an answer that will work, but will probably be ugly. By all means apply it and hopefully you have the chance later to come back and reiterate it to a more beautiful solution.
As programmers you are under tight deadlines so your main priority is to create working code. However, if the design is not thought out then that working code might be incompatible with the other components that it has to interact with. If there is an art to the design of the code maybe it can be fixed easier than the spaghetti code. If something is hacked together quickly, that is understandable, but go back and fix it up. 99% of the time there is a more elegant solution to the problem.
If you view the custom.css for this site you will see that I don't really create complicated CSS. I happen to know where everything is so in my mind it is a good solution. Unfortunately, for someone else that might be looking to jump into it, it can take them a bit of time. That is not a good thing. Also because of the style of the CSS I can't tell when I am redoing code that I could simply be reusing. How many lines of CSS do we waste by repeating attributes and properties for different elements?
In contrast if you look at the CSS for Flyosity, Mike Rundle takes his time to make sure that the CSS is logically indented to he can quickly jump back into it to make changes. You can tell he takes pride in his CSS.
#right_column {
position: relative;
z-index: 1000;
padding: 0;
top: -101px;
float: left;
width: 250px; }
.portfolio {
margin-bottom: 10px; }
.portfolio a {
display: block;
padding: 36px 15px 0 72px;
height: 30px;
text-decoration: none;
font: normal 12px "Lucida Grande", "Verdana", sans-serif;
color: #19a0d1;
margin-left: -11px;
text-shadow: rgba(255,255,255,.8) 0 1px 0;
-webkit-text-shadow: rgba(255,255,255,.8) 0 1px 0;
background: transparent url(images/portfolio_icon.png) 2px 8px no-repeat; }
.portfolio a:hover {
text-decoration: underline; }
See yourself as a master craftsman who has apprentices and journeymen coming from all over to view your code so that they may learn the art of programming. Take pride in your work not for others’ enjoyment, but for your own sense of self. We are artists and we must learn to love our art.
This article was a bit different than what you usually see right? That is what Drawar is all about. It's not about being different, it's about helping all of us dig deeper into what web design really represents. It thrives off its members contributions so if you like what you see consider becoming a Plus Member or Drawar Friend.
Are you intending to be a teacher or a crafter of the most efficient code?
Surely it's best practice to remove every last un-needed byte/bit from your code and serve it fractionally faster and fractionally cheaper than have it so Dave McStudent can look at your code and learn from it?
Are you suggesting there is a difference between producing fast code and code that others can look at and learn?
@drawar maybe i'm magnetically drawn to your broken links, but your link to custom.css is broken. :) (should be /css/custom.css)
It depends what you mean by fast.
If you mean production of said code, then no, they're not separate things. Quickly produced code can be easily learnt code.
However, I was focusing on the display of said code. For example, I just removed all of the comments and un-needed indents and spaces from your custom.css file and reduced the file size by 7.2kb. That's without even bothering to attempt to consolidate duplicate parameters or shorten some class/id names.
What I was getting at, is it best to be as efficient as possible in how your code functions or should you sacrifice efficiency for the sake of someone being able to read and learn from it?
In some cases it does make sense to minify code (JS, CSS, etc), but at times doesn't the fact that you remove indents or comments make the code just as hard to read for the person that created it? Again, I'm not saying it shouldn't be done, but I think that starts to depend on a case-by-case basis.
It's easy enough to have a working CSS file and a production CSS file.
I guess it's just different ways of looking at things. I'm not disagreeing with what you wrote, I just don't see easy to read code as an example of good craftmenship in the same way you do.
Granted I think we need to take into consideration that using CSS as the example probably wasn't a good idea on my part. I'm thinking more along the lines of backend stuff that programmers deal with such as C or PHP.
Rarely do you come across a CSS file that is complicated.
Fair enough, but then again it raises a question as to whether the process/backend is a show of the craftmenship or is it the end result? Isn't how only relevant to the eventual outcome?
If a PHP file parses miliseconds before another, but the faster parsing file is a bit of a mess to outside parties and the slower parsing file is well commented and easy to grasp, which shows better craftmenship?
I'm not trying to suggest that well presented code and quick parsing are mutually exclusive, the best of both worlds is ideal, but I know if I had to chose between the two I'd certainly chose the messy but efficient/quicker parsing code and I'd see the person who wrote the messy/quick code as a better crafter of code than the person who knew how to dress it up, although the person who knew how to dress it up is arguably a better crafter when it comes to presenting information.
I hope that made sense. I'm spamming buttons while shoving pasta into my mouth.
I guess then it depends on a lot of factors. I mean in a large organization where code is passed around a lot I'm sure they will take the better formatted code of the one that does things just a millisecond faster. In contrast, you might be in a two man shop where you just plow through everything.
I would love to hear how it goes in places where people code in teams.
I may be way off here but and this is in a per case basis; isn't creating the smallest possible CSS document almost obsolete now a days?
Lets take Drawar, I'll take a bet that more then 95% of its visitors are on broadband, will they really notice the difference if the CSS is quick or not?
When Google introduced their own DNS service recently they mentioned that users do notice milliseconds of delays. I have my router set on Google DNS for a while now and don't really see a difference, only lags I experience on sites are heavy graphic and if the site has lots of Javascript or Flash animations. That's why I do agree that Javascripts library mostly always need to be compressed. And use of Flash needs to really add something to the website and not just be a wow factor.
And I for once, maybe because I'm a web developer, when looking at a website for the first time I always look at the html and css code. I don't judge by the "cover" aka design only. I like looking beneath the hood if the code is tidy, logical, how do they sort their CSS, etc.
Lots of time I can make out from the code if the person who made the website really gets it or if it was a pure copy/paste job.
Making comments in your code is good practice, saves you time if you have to modify it, if you need to work on the same code in a team it will make everyone's job easier. A lot of time I come back to my own code after months and I'm glad I have comments on them saving me time of remembering or figuring out what is what. This counts for client side and back end code.
"I would love to hear how it goes in places where people code in teams."
Coming from a contract position in a $5B company, I can say where I was, with a team of 4 designers and 30+ developers the code was a disorganized nightmare.
So much legacy and different mindsets sprinkled throughout with varying results. Jobs were billed to the hour so speed was given precedence over readability/updatability.
I tried in vain to clean up code I worked on, only to have updates made a week later by another designer and/or developer and totally negate my clean-up efforts. While the end result was still functional, trying to make updates was laborious.
My current job I am the sole designer/developer so I comment the hell out of my code because I know if I leave whoever replaces me will only have my documentation to go by.
I've always felt that for code to be functional and nice to look at are one in the same, I'm always annoyed when a site uses compressed code, it's just so anti-social. But then I've never had to worry much about bandwidth or the like.
To all those that are saying about loadtime, compression to me is not about load time, but rather server load and how well it scales.
For some reason this post reminds me of the Fujitsu font tag mountains
Really nice article. I fully agree and I think developers should be more serious about creating beautiful and elegant code.
I believe that when writing code, 2 things should be prevalent.
1 - Readability : The programmer(s) should be able to make sense of what they are going through, whether that be alphabetized, tabbed, or some other structure to make scanning easy. Granted, this might slow down access times, but I think getting down to that fine minutiae is a battle that can't be won - there's just too many factors that go into page load speed.
2 - Functionality: Take CSS for example. How many elements in your css file use something like margin:0; ? Instead of defining that for all of your elements, would it not be more logical to add it on one line?
Good article again Scrivs. I think that there are so many facets to web design that people don't look at - and code is a huge part of that. I've talked to so many people that think "as long as the site works, who cares how the code works"... it's such a fine line between clean code and jargon, imo.
The 7.2 kb of savings mentioned by WiBu would be saved by Gzipping the CSS file. So, I think Scrivs' point is spot on, and perfectly relevant.
A CSS file should be indented, organized, and commented, otherwise it's unmaintainable. Even if you keep a backup of the uncompressed file, you're still creating more work than is necessary.
If you use Gzipping, you'll get the savings in speed (the same as if you compressed it manually, from what I understand) as well as be able to keep your code beautiful.
As far as I'm aware gzip wouldn't be compressing a lot of what I took out (often 1 space gaps or 1 character bits). It will however make the file I came up with smaller almost to the same extent it makes the original smaller. As I said, I didn't run through the code optimising duplicate parameters. Gzip loves them.
Actually, I'm probably wrong, it would.
It would be interesting to see the results if anyone is inclined to do so.
Excellent article - I really think this applies to code in a global sense, even though you just focused on CSS (at the end).
As a web writer, I'd like to mention another point. It's not just craftsmanship and thought leadership -- though I'm in total agreement with this post on that. If you build a site for a client and your site is successful, then it's likely that someone else will be called upon to work on it at some point. I have designers whose sites, email templates, etc. I love to work with because their code is displayed in a logical way, and designers with whom I'd rather never work again, no matter how nice their page looks on the surface. We should be able to go in and refresh text or update images without having to disentangle a bunch of untidy code. Shared clients shouldn't have to pay for the time involved in doing that. Elegant code is worth writing just because a thing of beauty is a joy forever, but on a commercial level, it also makes good business sense.
To comment you need to take a couple of seconds to login or register. Seriously it takes seconds and if your comment is worth it, which I have no doubt that it is, then you should do it.
Seriously though, Rundle writes his CSS like a NASA engineer does code for the space shuttle.