aspose file tools
The moose likes Beginning Java and the fly likes How far do conventions go? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "How far do conventions go?" Watch "How far do conventions go?" New topic
Author

How far do conventions go?

Ewan McTiernan
Greenhorn

Joined: Jan 31, 2012
Posts: 2
Hello, everyone. First post here and I'm sure its one of many to come.

I have (i hope) a relatively simple question that will (I suspect) have a simple answer.

I'm a relative Java newbie (I've come from a background of C# and LISP) who has found himself responsible for an application that someone else built with a lot of knowledge and over a long period of time.

The issue I have at the moment is I'm seeing a lot of code that breaks what I thought was pretty standard Java conventions and I don't know if it implies something more significant or if it was just lax coding...

In some cases the classes have camel case names starting with lower-case and variables/methods have camel case starting with upper case. In most other cases they are the correct way around so I'm not sure if this is being done to infer special significance to these objects/methods or if it was just an oversight.

I'm just worried as I know sometimes an underscore or m can be used to differentiate class member variables from local variables - is this likely to be something like this?

Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50693

Ewan McTiernan wrote:I'm not sure if this is being done to infer special significance to these objects/methods or if it was just an oversight.

Just sloppy coding on someone's part.

I'm just worried as I know sometimes an underscore or m can be used to differentiate class member variables from local variables

Gross! I only see raw newbies doing something grody like that.

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 3141
Bear Bibeault wrote:
Ewan McTiernan wrote:
I'm just worried as I know sometimes an underscore or m can be used to differentiate class member variables from local variables

Gross! I only see raw newbies doing something grody like that.


Indeed. If that's actually necessary to make the code understandable, then the class is probably too big and/or too messy. Fix the underlying design problem and the naming issue magically goes away.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 3141
Ewan McTiernan wrote:
The issue I have at the moment is I'm seeing a lot of code that breaks what I thought was pretty standard Java conventions and I don't know if it implies something more significant or if it was just lax coding...


The level of adherence to standards depends entirely on the shop and the individual coder. You can get used to anything though.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 3688

naming member variables with m_ is left over from hungarian notation. Its a really bad idea for modern languages.

The compiler won't care if you ignore conventions, and on some operating systems it won't even complain if you do really dumb things like have different capitalization of your java source files and the class name within the source. But just because the compiler doesn't complain doesn't mean its OK to do.

Any time you write code, you do so for two audiences. One is the compiler. The second is for the human who has to modify, understand, reuse, extend and improve your code. Some of us think that this second audience is actually much more important than the first one.
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 11642

Ewan, welcome to the Ranch!

I do projects at lots of different companies. Almost all Java code that I have come across is written using the de-facto style that Sun came up with a long time ago (with small deviations).

Sometimes for some reason people adopt some really different style. I can get used to that, but what I really hate is inconsistency. It's much better to have a strange, but consistent style than to have an inconsistent style.
Ewan McTiernan wrote:In some cases the classes have camel case names starting with lower-case and variables/methods have camel case starting with upper case. In most other cases they are the correct way around ...

That's exactly what I mean by an inconsistent style, and you already experienced how confusing it can be if the style is inconsistent.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ewan McTiernan
Greenhorn

Joined: Jan 31, 2012
Posts: 2
Jesper de Jong wrote:Ewan, welcome to the Ranch!

I do projects at lots of different companies. Almost all Java code that I have come across is written using the de-facto style that Sun came up with a long time ago (with small deviations).

Sometimes for some reason people adopt some really different style. I can get used to that, but what I really hate is inconsistency. It's much better to have a strange, but consistent style than to have an inconsistent style.
Ewan McTiernan wrote:In some cases the classes have camel case names starting with lower-case and variables/methods have camel case starting with upper case. In most other cases they are the correct way around ...

That's exactly what I mean by an inconsistent style, and you already experienced how confusing it can be if the style is inconsistent.


Hahah, thankyou and everyone else for the help. As you touched on its largely consistent except for say, 2% of the classes and variables. As I've learnt it makes it hard when you're looking at a static method of a class as opposed to a public method of an instantiated object - I kept scrolling up thinking "where did that little fella come from?" and when a String variable named "ServerName" gets passed as a parameter I become wildly confused.

Now that I know its not all just some metaconcept with implied meaning that I didn't get I feel alot more relieved... relieved and FRUSTRATED
EDIT: Hahah Alot - Hyperbole and a half reference
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 26720
Ewan McTiernan wrote:. . .
EDIT: Hahah Alot - Hyperbole and a half reference
I hope the joke about that spelling error still works
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

Pat Farrell wrote:... and on some operating systems it won't even complain if you do really dumb things like have different capitalization of your java source files and the class name within the source.


Yup. I just got bit by that one... we had a web application which had been running for about 6 years on a Windows server, and then we moved it to an AIX server and all of a sudden "Index.class" didn't match "index.class".
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 11642

Ewan McTiernan wrote:As I've learnt it makes it hard when you're looking at a static method of a class as opposed to a public method of an instantiated object - I kept scrolling up thinking "where did that little fella come from?" and when a String variable named "ServerName" gets passed as a parameter I become wildly confused.

Another tip: Using a good IDE such as Eclipse can make it a lot easier to navigate the code in a project. In Eclipse, you can put the cursor on a name and press F3 (or hold Ctrl and click the mouse) and it will take you to the place that the name (variable, method, class, ...) is defined. That makes it easier to find where things come from.
 
IntelliJ Java IDE
 
subject: How far do conventions go?
 
Threads others viewed
boolean rules for JavaBeans
Strange Error with JSLT and JSON Taglib Array in JSP using "." (dot operator)
Camel In Action Questions
a question for good nerves
instance variable declarations, when do they occur?
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture