Live data from Hacker News

You Should Write Ugly Code

redotheweb.com

21–30 of 56 posts

Re: You Should Write Ugly Code

#21
post #17

Earlier quoted context omitted.

My issue is the phrase "sake of beauty." This ignores why this code was written. I'm fine with beautiful code. My issue is the use of the word beautiful in such a way as to imply that beauty was the intent. People don't try to write beautiful code, people try to write good code. That it happens to be "beautiful" is a bonus. Hopefully my point is clear. I guess it's subtle, but I think a crucial difference.

I actually thought the article would be about indention, style, etc.

Considering his examples, it's not. It's about architectural quality.

Indentation style is meaningless in this context.

Re: You Should Write Ugly Code

#22
post #10

Earlier quoted context omitted.

Actually, I find that it's usually when the ugly code starts to cost them more. Basically, it's a car without brakes. It will get you where you are going, but it would have cost less all together if you'd installed working breaks from the beginning.

To use your analogy, is it better to have a car with no brakes now, or to save up for another year to buy a car with brakes? The problem with the analogy is that it's _obvious_ that you should save up another year because of the danger. But in startup-world, it's not obvious at all. To really abuse your analogy, if you're being chased by wild hungry bears, you don't care whether the car has brakes.

The thing with good code is that it's cheaper than bad code.

For instance: it takes me 8 minutes to run the full test suite of an app and make reasonably certain nothing is wrong. It takes me 2 hours to get the same assurance manually. And I'll miss most of the problems.

Another example: I recently implemented a feature where the feature took ~5 days and fixing the whole codebase to make the feature implementable took 20 days. Had the codebase been using certain libraries correctly without ghetto-coding its own solution, the feature would take me ~5 days.

Re: You Should Write Ugly Code

#23

This all sounds great, but I've worked in places where this has been the philosophy. Unless you have somebody in charge who understands the importance of code quality (and why a bad codebase can be a ticking time bomb) you will find it very difficult to budget time/money for the removal of technical debt. You will often meet the attitude of "well it works now, why waste time rewriting it?" or "sure, do that. But let'…

Thanks, "Technical debt" is the word here. "Beautiful" might not come close to "valuable" in terms of importance, but "Clean" should come close, because accumulating too much crap makes maintenance & feature addition painful. Uncle Bob's "Clean Code" does a great job at detailing that.

Re: You Should Write Ugly Code

#24
Disagree.

You deliberately call it beautiful code, whereas in reality it is clean code. Clean code is not more expensive to deliver than ugly code. It just requires a better calibre of developer i.e. a developer who can express features in a style which others can understand.

Once you have clean code you can take on features more easily and quickly. You can also change personnel more easily. Most importantly of all you can get better confidence that changes won't introduce side affects.

The problem is there are not many people who can do this.

No-one in their right mind (Fowler, Uncle Bob, included) say code should be beautiful as some kind of vain exercise in style over substance.

Re: You Should Write Ugly Code

#26

> the code they wrote for the sake of beauty is crap. From my understanding, this is the crux of the article. The problem with this is the misunderstanding of why people employ patterns in programming. It's not for the sake of beauty, but because of sound architectural principles. Maybe that's how he interprets beauty, but then using the word beauty diminishes why the code was written the way it was written. That bea…

Well there definitely is a real problem he is speaking to, in which people apply patterns out of reverence rather than understanding. They want to be able to say at their next interview or meetup that they've used all these patterns. Anyone who has worked in Big Corp has seen this first hand: a great shining tower of beautiful code which is 80% bullshit and ceremony.

Re: You Should Write Ugly Code

#27
post #10

Earlier quoted context omitted.

Actually, I find that it's usually when the ugly code starts to cost them more. Basically, it's a car without brakes. It will get you where you are going, but it would have cost less all together if you'd installed working breaks from the beginning.

To use your analogy, is it better to have a car with no brakes now, or to save up for another year to buy a car with brakes? The problem with the analogy is that it's _obvious_ that you should save up another year because of the danger. But in startup-world, it's not obvious at all. To really abuse your analogy, if you're being chased by wild hungry bears, you don't care whether the car has brakes.

I don't really like the casual acceptance of the total dichotomy between dirty and clean code here. I'll freely admit you don't always get to clean every bit of code and make it pristine, but on the other hand, with only a small amount of effort and perhaps 5ish years experience it becomes pretty easy to pump out clean-ish code at the same rate you can make an utter, total mess, and recover the value of your slightly higher effort in as little as a week or two, a time frame all but the craziest start ups should still be caring about.

Being in a hurry may be license to be "a bit sloppy", but I think it's a mistake to give yourself license to make a total mess, and use your speed as an excuse. For instance, once you're skilled at programming, and assuming you're using a decent language (another thing your startup should be doing), it's at most only slightly slower to refactor something into a function that copy and paste, and that probably still wins on every level the fourth time you reuse a function like that. Well-done unit testing can also have a payback time frame of under a week, in my opinion. You get bigger wins from listening to it guide you through the initial design that you will get from adding it later.

Re: You Should Write Ugly Code

#29
I had a really great post for this topic about the utility of ugliness in language design. Ocaml provides imperative features but makes them ugly, subtly encouraging a functional approach in most cases. Clojure quite brilliantly makes OOP and heavy Java interop possible but very ugly (because the language's ultimate goal is platform-agnosticism) while making idiomatic Clojure beautiful. Making something ugly is often more powerful than saying "don't do that". So ugliness has a real value, and that's what I originally came here to talk about.

Then I read the OP, which had to go and ruin that by being wrong.

First of all, OOP is not "beautiful". Quite the opposite, I find Delegates and Factories and Visitors to be fucking atrocious from an aesthetic perspective. All that stuff is there to make business people think their metaphors apply to code and to give them a sense that they, the "big picture guys", have a chance at understanding what's going on. They don't.

I've taught. I've designed games. So I understand the importance of aesthetics in any replication process. Making something easy to learn, understand, replicate, use, et al actually comes down to aesthetics. Now, it's a specific kind of aesthetic sense you need. You spend more time on convergent creativity (trimming, simplifying) than on divergence (adornments, gargoyles, "neat" advanced features). You should, at least when you start, ship a simple product that people can use rather than a complex one that you (having grown up with the complexity as it emerged) find "beautiful". With that I agree. It's better to write straightforward "boring" code that works than to apply every programming trick in the book (self-modifying code! three-level syntax quoting!) If the dumb thing works, use it. Complexity will happen on its own, so don't go looking for more.

Not paying attention to code aesthetics and simplicity, however, is a recipe for disaster. If your code is going to be read by other people and you write ugly, unmaintainable code, then... well, good luck with that.

I don't really mind the substance of what the OP is saying (focus on solving problems rather than writing code) but the presentation is awful.

Re: You Should Write Ugly Code

#30
post #2

You should definitely write ugly code. People pay me and people like me good money to come in and clean up your mess when adding features becomes an endless exercise in breaking things in unexpected ways for the whole team and productivity plummets. Relevant blogpost: http://swizec.com/blog/my-very-own-daily-wtf/swizec/5829 Relevant website: http://thedailywtf.com/

What you're describing sounds more like the result of poor test coverage.

The OP was mostly referring to design patters and a semi-arbitrary measure of "beauty", not specifically advocating writing unmaintainable code.

Post reply on HN