Indeed.. And I’ve also seen plenty of other really dumb things.. Recently at my place I found the following around line 300 in a perl script of 1200 lines..
database_port = 3306;
database_login = root;
database_password = ;
All I could say is FACEPALM. First, these should be in a config file. Second, this file was committed to SVN for over 7 years. Third, the RPM package contained these creds.
Tl;Dr. DevOps engineer looking for work with a more modern codebase, with even a minimal amount of code review…
I wonder who that author mentioned is?
Probably Yashavant Kanetkar.
Some of the easiest fixes are simply not having operators like ++. Or banning them from your style guide. The “cleanest” usage of that can be replaced by += 1, and the statement can’t be composed, limiting the silliness.
Another decent win is probably not having the assignment operator return its value. x = y = z = 0 might suffer a bit, but it’s a price to pay to destroy messy code.
x = y = z = 0
I’m a fan of “everything is an expression”, but it doesn’t mesh well with stateful languages. Better to cut the root.
FWIW, Clang emits a warning for multiple modifications with no sequence point in-between, and unsequenced modification + access, like the examples in the post.
Considering people write things where correct usage requires 10 or 20 lines of method calls in the exact order, and think this is good programming, I’m going to go with “yes” here.
I think the reason why this kind of code manifests, and all of the complicated, rube-goldbergian gegaws that get hacked together is because programmers like to think that they’re clever. Slap together an unexpected combination of operators in a multifold side-effect having statement? You’ve gotta be pretty clever to do that, pretty clever to understand it, and even more clever to change it later.
May the programming gods save us from the clever programmers.