Bad variable names vs. too complex functions

The dilemma about which is the worst common programming problem

If I had to single out one problem that most commonly leads to bad code, I’d be in a dilemma: I wouldn’t know whether to pick up bad variable names or complex functions.

Bad names aren’t a problem exclusive to programming. Scientists are often careless about terminology. When we use “artificial intelligence” instead of the more accurate “probability modelling”, we pave a road with misconceptions. Bad variable names are bad for a different reason—they make the code hard to understand. But since many scientists understand the importance of good terminology, and they automatically use a good naming habit when programming, I’ll resolve the dilemma by picking up complex functions.

The problem goes like this:

def some_function():
    [500 lines of code including deeply nested while/for/if/etc.]

There are three things we can do about it:

  • Write shorter functions

  • Write less complex functions

  • Avoid mixing abstraction levels in a function

I’ll go through them in more posts.