views:

236

answers:

5

I am wondering why Java, with its many safety features and constraints, allows developers to start a class name with a lowercase letter even though it would be an extremely stupid idea to do so.

Or have I overlooked a case where this could be useful? Or is it simply a case of not bossing the programmer around?

+3  A: 

Many things are stupid ideas - and most of them are not enforced by the compiler.

In the end - class, method and variable name capitalization is a matter of convention, and this is true in most languages.

Yuval A
Yes, it's a matter of convention (i.e. coding standards), but that's no reason why it should have been necessary to implement the rule in that (sloppy) way.
Tom Hawtin - tackline
+2  A: 

It is because it was thought that a programming language should not force conventions in the previous years. But now the scene is a little changing and there are favourable atmosphere for "Conventions over configuration" approach like in Ruby on rails.

So in the future, we may see more of the convention based programming languages/frameworks which will arise out of the programming patterns and best practices over the times.

Xinxua
A: 

Probably a big factor in this is that if you ever allow something like this at any point in the language history, you don't want to change it to break existing code.

quillbreaker
It would have been fine to start like this, and then later remove the restriction is there was some problem with it (say, interfacing to a different language).
Tom Hawtin - tackline
A: 

There are a number of ways in which the JLS allows sloppiness. Order of modifiers, for instance. Probably the worst offence is indentation, although that is not reasonably handlable by the grammar.

A particular problem with class names is that, IIRC, it is not clear in the grammar which identifiers are class/interface names and which are not. Strictness at declaration points is possible, but then it makes the rest of the grammar more complicated.

Probably it comes down to time pressures. And even back then, Java was considered bossy. People where busy writing C and C++ with all sorts of conventions (typically different from libraries) causing all sorts of confusion, but they didn't seem to care.

Tom Hawtin - tackline
A: 

Perl has a "use strict" directive that enforces some (but not this particular) best practices. Why not add a -strict option on javac that enforces such best practice conventions on the code being compiled? This could still allow the use of .jar or .class libraries that don't follow the standard but enforce it on anything new being compiled (.java)... Or better yet, turn it on by default and provide a -relaxed directive to turn off the enforcement, thus encouraging everyone to follow the standard more closely without penalizing those that, for whatever reason, can not.

Chris Nava