5 ms·
Almost as bad as m prefix.
by Hnus 8y ago
Almost as bad as m prefix.
- dman 8y agoWhat is wrong with the m prefix for members?
- pjmlp 8y agoUseless prefix better replaced by making use of this. or IDE tooltips.
- dman 8y agom is shorter than this and not everyone uses an IDE.
- pjmlp 8y agoStill not an argument to plague source code with it. I for one am more than happy not to write Hungarian notation any longer. Even Microsoft style manuals now advise against it for modern Windows code.
- simias 8y agoIf the point is to write legible, explicit code then the extra 4 characters of "this->" over "m_" shouldn't be a deal breaker. It also has the advantage to save space and reduce noise in locations where you really don't need to make it explicit (like declarations in particular where you obviously don't have the "this" but you'd need to add the m_ prefix). If the point is to write super dense code for some reason then don't use anything at all.
- simias 8y agoI don't write C# but I also dislike this notation in C++. If I want to make it obvious that I'm accessing a member then I write "this->member". IMO it was a mistake for C++ to allow the "this" to be implied for members, it makes it a lot harder to figure out what C++ code is doing and what's dealing with member variables and methods vs. globals. At the same time "m_" prefix only solves half of the problem because it doesn't help with method calls. That's why I prefer to drop the 'm_' and just put the "this->" everywhere, even when it's not mandatory.
- 72deluxe 8y agoBut what the method resolves to could be very different in the case of an inherited hierarchy, or where a base function is overridden in a child class. It has never been a difficulty even with colossal codebases that the function that it is resolved to might be elsewhere, in a child. If anything, it's one of the great strengths of the language. The m_ syntax is kind of ugly but adding a this-> every time seems foolish, given that either the member is protected or public if you're modifying it in a base class. In the case of complex inheritance, you might be running into problems with ambiguity of names anyway. m_variable (or a sensible member naming convention, e.g. a prefix) helps to distinguish between local variables, which is important in complicated classes/functions. This proposed # for JavaScript looks insane, coming from the well-established, tried, and tested (and perfectly functional and useful) systems found in C++, Java and C#. It's like it's adopting a terrible syntax in order to solve a problem that doesn't exist. Perhaps I am misunderstanding.
- pjmlp 8y agoYep, that is another one.