<p><pre><code> And, regarding "ugly"... ALL code is ugly. Yours, mine, everyone's. Code Is Ugly.
Just face it. When someone says "beautiful code", hear "beautiful rotten entrails".
The only beautiful code, the most clean code, is no code at all. If it's there, it's
ugly. The unfortunate fact of software development is that, in order to create
beautiful software, we must use ugly code.
</code></pre>
The premise that 'all code is ugly' is never really substantiated.<p>I believe code that accurately and clearly portrays the algorithm is beautiful code. For example, quicksort in Scala is concise, and reads like the mathematical description of the algorthm:<p><pre><code> def sort(xs: Array[Int]): Array[Int] = {
if (xs.length <= 1) xs
else {
val pivot = xs(xs.length / 2)
Array.concat(
sort(xs filter (pivot >)),
xs filter (pivot ==),
sort(xs filter (pivot <)))
}
}</code></pre>
I always thought that code is like babies' diapers.<p>I'll change my own. I'm so used to the smell, it don't even notice it anymore.<p>You change your own. It smells so bad my eyes are watering.
As contrived as those examples are, Python does have one feature that I currently miss, which is that trailing commas are ignored.<p><pre><code> mylist = [
"ape",
"bat",
"cat",
]</code></pre>
"If you disagree, then apparently, "clean" just means "looks like what I saw yesterday and the day before"."<p><pre><code> Well
, sometimes the way it was done yesterday simply _is_ the right way to do it
. Of course
, one can occasionally try to challenge fundamental grammatical conventions like putting punctuation on the end of a sentence instead of the front of a line
. To me
, "clean" or "beautiful" code is both easy to read and understand and follows the conventions and best practices that have proven themselves over and over
.</code></pre>
Comma-first is beautiful! Comma-first is <i>functional</i>.<p>When we make lists, do we put the * at the end, or up front? Comma-first serves the same purpose. It delimits a new entry. <i>"here is a new entry! here is another!"</i><p>Comma-first is column aligned with the least about of white space. It visually identifies the list as such, set apart from other code. Easy to parse, easy to skim, easy to elide, depending on your need.
If separators are meant to be put before each item, as in comma-first style, they shouldn't have been commas in the first place. Commas should be used just like they're used in natural written language. If I were to design a language that uses comma-first style, I'd replace commas with bullets:<p><pre><code> var a = "ape"
• b = "bat"
• c = "cat"
• d = "dog"</code></pre>
What a misleading title. This is about putting commas in array initializations before the next line or after the last line and argues that ALL code is ugly, so it does not matter if it looks akward.
In determining the best coding style, ease of spotting errors is one thing to consider. Another is ease of interpreting correct behavior. At a glance, comma-first is harder, but that may just be because I'm used to comma-last.
Sure code is ugly. So is paint when it's sitting in it's container. But when used by someone with skill, great works of art are created. Same goes for code. Out of context it's ugly, but what it creates is beautiful.
I've sometimes had my moments where I thought "no code could ever look good". If you read enough DailyWTF-like resources you'll gain a sense of pessimism about code.<p>My humble attempt to find some code that's pleasant to look at: <a href="http://lovelyco.de" rel="nofollow">http://lovelyco.de</a>.
<i>ALL code is ugly. Yours, mine, everyone's. Code Is Ugly.</i><p>I couldn't agree more. It's 2010 and we're using text files to describe rules. We're using text files to describe data.<p>My God. Everyone just stop what we're doing and look at your code. Look at it! It's worse than ugly; it's monstrously stupid. It's idiotic to a degree that beggars the mind. And here we are, in 2010, ignoring the elephant in the room: that code, the way we do it, is petulantly retarded.