r/programmerchat • u/fainting-goat • May 27 '15
What good code habits have you learned from having to deal with the bad code of others?
I feel like a lot of my code style is a reaction to having to deal with heaps of bad code I've had to maintain.
For example, one of my coworkers always seemed to instantiate about 5 different variables, each of which could be returned depending on various if/then/else/try/catch logic. This made it virtually impossible to follow the program flow and debug the method when issues came up.
So I finally got so sick of this that I decided I'd never foist that kind of problem on others. Every method I write now, the first line is <returnType> returnValue = ...
and the only thing that ever gets returned is returnValue.
View all comments
Show parent comment
3
u/Ghopper21 May 29 '15
You bring up the word invariant -- one of the best programming concepts -- now that I think about it I'm surprised there aren't more language features letting you express desired invariants directly. I mean there are types and type-like behavior, but not really about data. Maybe the functional side of things deals with this. If so, this may be what gets me to finally learn about real functional programming.