Greg Helton (11) [Avatar] Offline
#1
Will you please explain your use of variable names with trailing underscores. Examples in your book seems to me to use trailing underscores randomly. Sometimes the book has a method with a parameter without the trailing underscore, like "field", and sometimes with, like "field_" and the method may have code with this form

field = field_;

and code in other methods with this form

this.field = field;

I buy several Java books a year and I have not seen the underscore convention used in a decade. Please follow the convention provided by the language and consistently use the keyword this. A Well-Grounded Java Developer would be consistent.

Thanks,
Greg
martijn.verburg (86) [Avatar] Offline
#2
Re: underscores
Hi Greg,

Right you are! We'll be tidying this up before the final version comes out (it might make it into the next MEAP update as well).

Cheers,
Martijn
benjamin.evans (18) [Avatar] Offline
#3
Re: underscores
Hi Greg,

The differences come from whether Martijn or I originally wrote the code.

My convention is trailing underscores for parameters inbound to a method, and that's a convention I have seen at a number of firms over the last 10 years. I find the use of this to be unnecessary complexity, as it forces the developer to think about scoping rules when there's no need to. After all, it's not anything provided by the language - it's a convention defined by common practice - and one can have different ideas about how good a convention it is.

You're right, though - the book needs to be consistent, and I know that this is one battle that my viewpoint has unfortunately lost smilie. The final version will use the this convention - but that's something which gets tidied up late in the production process.

Thanks for taking the time to let us know,

Ben
martijn.verburg (86) [Avatar] Offline
#4
Re: underscores
It was a hard fought battle though smilie. Now as for which line the { goes on..... smilie
adrianmurray (4) [Avatar] Offline
#5
Re: underscores
I hope this is something you revisit. I am reading the book now and find the use of underscores very distracting.
martijn.verburg (86) [Avatar] Offline
#6
Re: underscores
Hmm, they _should_ have been removed - are they in the source code download as well? If so we can at least get that updated, many apologies!
adrianmurray (4) [Avatar] Offline
#7
Re: underscores
Hi Martijn, no need to apologise - it's a personal preference thing but I just wanted to add my vote to the "against's". To answer your question, underscores are present in the source code I downloaded last month.

Thanks for producing an otherwise very readable book.
martijn.verburg (86) [Avatar] Offline
#8
Re: underscores
Thanks for letting me know, I'll get the underscores removed for the next version of the source code errata.