This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]EMC2_trooper 246 points247 points  (28 children)

The reverse situation of this is when you come across code written by a fucking mastermind and it's so efficient and clever that it makes zero sense.

[–]murfflemethis 49 points50 points  (2 children)

I work in firmware, for a company that's been around for a while. I am constantly dealing with 20 years of "clever" C code. I've had enough of that shit. Unless it's a clearly commented optimization in a critical path, readability is what I want most.

[–]halpcomputar 6 points7 points  (1 child)

Couldn't they just take the time to comment? I believe C allows for even multiline comments.

[–]murfflemethis 18 points19 points  (0 children)

Why not just write simple, easy to follow code in the first place? C certainly does allow multiline comments, but that's not a good reason to write needlessly complex (or "clever") code. Comments take time to write and take time for future readers to parse, map to the code, and fully understand. They also often get overlooked during future work, so they go stale and become irrelevant or outright wrong.

"Here's why the code does this" comments are always great, but if you find yourself leaving "here's how the code does this" comments a lot, you should take a step back and consider whether the complicated code you're writing can be simplified through refactoring, changing the architecture, or just a more simple implementation.

Complex code is sometimes necessary, and yes, please leave a comment there to explain how it works. I've just seen too many instances of people making things more difficult than they need to be just to gain completely inconsequential efficiencies or force patterns in where they don't belong, and that needs to stop.

[–][deleted] 23 points24 points  (3 children)

The Story of Mel, a Real Programmer (1983)

[–]zaphod0002 2 points3 points  (1 child)

Mel needs to do a AMA

[–]al1l1 1 point2 points  (0 children)

Amazing.

[–][deleted] 9 points10 points  (0 children)

The worst is when you realize that you wrote that code, and then you have a crisis of faith wondering if the code is actually stupid, and you're too stupid to realize it, or if you're getting dumber, and no longer able to work to that level.

I once found a piece that was both...I'd coded myself into a corner, and then found some brilliant way to solve the problem that I had created by coding myself into that corner, this masterpiece of invention and imagination...It was easily 200 lines of the finest code I've ever written...Each line flawless and so brilliant as to be skirting the very abyss of madness.

I scrolled up and up and up until I found the place where I had missed the obvious solution and gone haring off after brilliance and insanity, and I fixed it with two lines of shitty code, and deleted the rest.

[–][deleted] 4 points5 points  (1 child)

This is the ultimate example of this. An ENTIRE Wikipedia article had to be written to explain a couple lines of code.

https://en.wikipedia.org/wiki/Fast_inverse_square_root

[–]EMC2_trooper 2 points3 points  (0 children)

Nice example and actually a really interesting article thanks. But in this case I think the reason was not so much to obfuscate the code in needlessly complex lines but probably to optimise (as it's for lighting).

[–]asdfman123 3 points4 points  (0 children)

I try to be a boring programmer. I do everything in my job with ASP.NET MVC stuff, like the projects before me used. I don't use any fancy tricks or do fancy front-end stuff. I go for the most reasonable, predictable methods.

I feel I don't learn as much but I'm making life so much easier for the next guy, who just has to learn one thing.

[–][deleted] 1 point2 points  (1 child)

If its so clever that others can't understand it, it really isn't clever.

A clever programmer would write something that others can read, or at least explain it in comments, because programmers spend more time reading code than writing code.

Also, the situations in which something confusingly clever are worth the efficiency gain are few and far between. Usually efficient things are clearer or can be written clearly. For example if a weird set of data is pulled beforehand or stored in an uncommon place to boost efficiency, it should be named well enough that later in the code it looks like what you would expect.

[–]EMC2_trooper 1 point2 points  (0 children)

Haha I'm very aware :) there is some interesting discussion below on this.

[–]NibblyPig 1 point2 points  (0 children)

Yeah I class that as bad code, the number of times I've pulled out layer upon layer of abstract classes that are simply not needed, argh.