Phango - questions

Christopher Wright dhasenan at gmail.com
Mon Nov 19 15:11:46 PST 2007


Robert Fraser wrote:
> Bill Baxter Wrote:
> 
>> Sean Kelly wrote:
>>> Christopher Wright wrote:
>>>  > This is
>>>> a stylistic topic that almost no one touches, probably because Tango 
>>>> conventions seem to be lifted wholesale from Java and that's how Java 
>>>> does it, but I find it a bit confusing and annoying when I'm reading 
>>>> someone else's code.
>>> For member variables, I personally prefix the non-public variables with 
>>> "m_" and non-public static member variables with "sm_".
>>>
>>>> I would at least prefix private variables with an underscore, if I 
>>>> were setting the style. But if I want to muck about with Tango's 
>>>> internals, I can suck it up.
>>> I avoid leading underscore prefixes because they are reserved for C/C++ 
>>> standard library use.  It's easiest to just avoid this format entirely 
>>> than risk the rare chance of a collision.
>> I used to be a big 'm_' guy, but I recently started using trailing 
>> underscores for private members.  Started doing that after porting 
>> OpenMesh from C++, which uses that convention.  I was amazed at how much 
>> more readable all the code looked with the garbage characters appended 
>> as a suffix rather than a prefix.  Apparently this style is used some by 
>> Boost as well as the ACE library.  Trying to find out where it came from 
>> I ran across a quote from someone saying (in 2004) that it's "the de 
>> facto cool kids' C++ style".  :-) 
>> http://discuss.joelonsoftware.com/default.asp?joel.3.49438.14
>>
>> I asked the original OpenMesh devs about it and one responded that he 
>> used to be in typography before computer science, and from what he 
>> learned doing that about how humans read he could say the suffix version 
>> is definitely going to be more readable.
>>
>> Just some food for thought.
>>
>> --bb
> 
> Why do private members need to be differentiated typographically?

More that they should be differentiated from locals. It's a reminder 
that you should be careful to modify the variable, and it means you 
don't have to read as much or search as much to find the scope of a 
variable.

The extremes are Java and Hungarian notation. Hungarian, from the few 
examples I've seen, tends to be complex and opaque. Java style only 
takes a couple extra seconds to parse, but that's multiplied by the 
number of times you have to read the code. Using a prefix and 
associating it with a simple property is relatively clear and marks out 
those variables.

The question is, does it actually improve readability to any appreciable 
degree?



More information about the Digitalmars-d mailing list