I am the only programmer and new this year for my team. Previous years’ programmers have just gotten by, and I am trying to improved things for future years.
While going through a couple of other teams’ code I keep finding this consistency and I cannot figure out why it is done. At first I thought it stood for motors but it is not always attached to variable names for motors and speed control groups.
m_ is to say that the variable is from the class which you are working on. There are multiple variables throughout, and perhaps some similar names. By putting m_ in front, you can easily tell where it came from
As others have said, it typically denotes a member variable. Our main reason for using it is to maintain consistency with WPILib’s conventions, in particular so new members have an easier time navigating dependencies.
While this convention is used by wpilib, it is not required and is definitely not universal. It’s basically just a personal preference, but whatever styles teams decide to use it’s very helpful to remain consistent.
One real life example is the Google Java style guide that explicitly does not use identifier prefixes.
Putting character’s in front of variable names is very much a C++ style practice and not really the Java standard. But, as @forbes said in a previous post it doesn’t matter what style you use, as long as it’s consistent.
One year our auto-aiming code had a member variable called “mIsAligned”. This caused a lot of confusion when a programmer thought that this variable should be true when the robot was misaligned.
There can be good reasons for wanting to distinguish, at a glance, between variables that belong to – I.e. are a member of – a class object and local variables of a method. The exact reasons can vary from language to language and even programming styles. Prepending a variable name with an “m” is one way of accomplishing this. To accomplish the same goal, I typically use the features of the IDE to display different kinds of variables using different fonts; e.g., different colors, italicized, bold, etc.
The goal is always to maximize readability. This in turn increases development velocity, which is almost universally a good thing. To do this, concretely:
Whenever I’m editing existing code, my priority is always “maintain existing conventions”.
Whenever I’m writing code from scratch, I pick my convention according to a particular style guide.