Devil's Sunrise Wrote:Is it bad to assume that the ones continuing/reusing the code are smart programmers? Or, even more, that they have to be?
You are taking things out of context. I was purely speaking about Fiel's case. There's a big gap in reusing code vs reusing variables. Generally, the problem is not the principle of reusing a variable, but rather the human errors associated with it that prevents them from being mainstream.
Because of that, OOP were taken upon, and one of the main emphasis of OOP is variable scoping. You dont need to be a smart programmer to reuse variable. We human do make mistakes and thus it's not advised. If you are careful enough to, then by all means. That's what I referred to as common sense.
Dont tell me in your programming career, there's never an instance where a variable does not have the expected value. Even after 7/8 years programming, I still make that mistake sometimes.
Devil's Sunrise Wrote:I mean, is it bad to program in a way which means its reader has to be smart to understand what's going on?
Short answer, yes.
Long answer, usually, if you're doing something beyond the norm, it's best that you explain it in a comment. Not only that it helps the next programmer, it helps you when 6 months later, you have to modify/enhance it.
Back in uni, I used to think I can understand anything and thus do not need comments. Then there were days when I bit my pride. Now, my principle is if a random programmer cannot understand what I am doing, it needs to be explained further. If you're stingy on time writing a comment, you'll waste 10x as much trying to re-understand your own code later.
This is an example:
$current_time = (time() >> 10) << 10;
Firstly, its in PHP. A language that can spoil many laziness. Secondly, it uses bit-shifting. A technique we don't often see in higher level languages and/or isn't streamline.
Without adding the comment:
// rounding down to the nearest 1024 seconds block (every 17.1 minutes)
It's pretty cryptic for the next programmer to read. They'll be like wtp did the old dude doing here?

