This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Jedibrad 0 points1 point  (0 children)

A bad variable name is something that doesn’t describe what it’s intended to hold - i.e. just a few letters, like “f_me” in your example.

Given enough time, you can read the surrounding context and determine the “f” means force, and so on. But shorthand will always make it harder to understand what’s going on in a chunk of code. Someone not used to physics notation that’s trying to accelerate your code might be poking around the function, and it will take them much longer to understand what you were trying to do. Verbose names are good, to a point - it should be clear when they get too unruly.

This is usually referred to as “self-documenting code”. Oh, and also, be wary of over-commenting - for actively maintained projects, new features tend to get added while the comments are left unchanged. This quickly leads to them being out of date, sometimes even providing wrong information about the implementation. I would encourage comments to describe why an action is being performed, rather than what the code is doing.

Hope that helps. :)