4 ms·
An assumption: code is designed [to get things done]. Another assumption: the [thing to get done] will likely eventually be transformed via evolution or destro
by tossacct 14y ago
An assumption: code is designed [to get things done].
Another assumption: the [thing to get done] will likely eventually be transformed via evolution or destroyed, as all natural things like rocks and species and hydrogen atoms and gluons and the entire known universe starting[?] with the big bang transforms via evolution or gets destroyed.
A conclusion: code that can not be easily changed and evolved will be conveniently destroyed via a complete re-write. This is why "facades" and opaque APIs are so popular - it is theoretically possible to rewrite different components of the code without rewriting the whole entire dang thing.
Case in point: http://stackoverflow.com/questions/810129/how-does-whiles-t-work http://stackoverflow.com/questions/810129/how-does-whiles-t-...
>>>while (s++ = t++);
This is code that is hard to understand(hence the stackoverflow question), making it not easily changed. Not a good sign for the survivability of the code.
JoelonSoftware.com makes a sparse point with this example, in that a "good" coder must understand what this does. He leaves the reasoning up to the reader, likely because he is clever enough not to make any claims that can be disagreed with. Luckily I am not this clever and I will make a claim that follows from my assumptions and conclusion above:
Claim: a "good" coder needs to understand the above type of obfuscated code so that they can evolve it or destroy it safely when they see it.
Note that my claim does not say whether a "good" coder would write code like that. A "good" coder gets the job done, whether it's a write-once-use-once-read-never perl one-liner or a big part of a big program. I only claim that a "good" coder must be able to read it, so that they can change it or destroy it safely.
- stephencanon 14y ago> while(s++ = t++); is absolutely trivial to understand if the reader has taken the time to actually learn the language in which the code is written. Saying this is "hard to understand" is like saying that "Ich liebe dich" is hard to understand. I'm sure it might be if the reader has never encountered German, but that's not real complexity, and it's not unreasonable for someone writing in German to assume that her reader has some competency with the language.
- jblow 14y agoI disagree. I have 16 years' experience programming in C++ (and substantial experience in other languages before that), and I find that an important factor in code clarity is not writing stuff like this. Yes, you can understand it, but it takes more brainpower to do so than it should, especially once you get beyond trivial cases. It is much better just to write it the long way.
- stephencanon 14y ago> I have 16 years' experience programming in C++ < Well, there you go; this is absolutely not idiomatic C++; in C++ (or even in application-level C code) one would (correctly) use language features or a library call to perform this copy. I should have been more specific; this code is completely idiomatic for standard-library-level C (though standard libraries will generally use more sophisticated copy implementations). If one is fluent in that particular dialect of the C language, then this construct is natural and correct.