• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Are capitalLetters unCool in moduleAndPackageNames?

 
Saloon Keeper
Posts: 1313
40
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Over on OCJP we normally focus primarily on what is legal, and secondarily on what is actually good practice.

Here in "Java in General" we understand when a user is required to follow local custom, and don't tell everyone to tell their boss that they are an idiot, but often advise on Best Practices.

I see a lot of people taking the Eclipse suggestion that packages and module names should not start with a capital letter too literally.

They still create package names and module names CONTAINING uppercase letters.  A Lot.

I know it is legal, because I keep seeing people doing this.

Is there some greatReason to Do this sometimes?  I know Germans like capitalizing all Nouns, for instance.

Is it not better to avoid capital letters thru-out our package and module names?

Thanks,
Jesse
 
Marshal
Posts: 74048
332
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
YeS, tHeY aRe UnCoOl. The Java™ Tutorials suggest:-

Package names are written in all lower case to avoid conflict with the names of classes or interfaces.

That is only a recommendation and there is precious little you can do about people who flout it.
 
Jesse Silverman
Saloon Keeper
Posts: 1313
40
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We can nOt do thIs in our eXamples that we write here, and can (politely) remind people that it is considered better to use all lowercase names.

I just saw someone (who teaches Java for a living or at least side-income) that does this all the time to mention DO NOT PUT a digit at the end of your module name.

When Eclipse yells at him, he listens.  So maybe we should just push the Eclipse team to generate warnings.  
 
Marshal
Posts: 22453
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Install the SonarLint plugin. That yells as well; a bit softer (blue underlined instead of yellow) but it still marks issues.
 
Saloon Keeper
Posts: 24321
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java does not enforce capitalization (or the lack thereof) on any nameable object or path component.

Nevertheless, there is the Generally Accepted Standard that class names begin with an upper-case letter and that pretty much everything else should not.

As I frequently point out, failure to adhere to this principle isn't likely to offend the Java compiler or runtime, but it is possible for some Java tools to get confused if you flaunt it. For example, the BeanUtils used in many services, such as property references in web page Expression Language locate the backing bean's access methods by taking the property name, capitalizing its first character, then prefixing it with "get", "set" or "is". So for example, the property named "todaysDate" is read via "getTodaysDate".

The Java conventions were inherited and adapted from earlier languages. And certainly starting only class names with upper-case makes it very visible when you're talking about a class definition rather than an instance reference or property.

However, speaking of inheriting practices, one practice that is irregularly inherited from C is an exception to the upper-case rule. Before C had a "const" attribute, the only way to indicate a manifest constant value visually was to declare its name in all upper-case, thus:

#define MAGNIFICATION_FACTOR 25

Java doesn't have a formal policy on this as far as I'm aware, so I've seen final values declared both all-uppercase and lower-initial.

 
Jesse Silverman
Saloon Keeper
Posts: 1313
40
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I strongly tend towards shouting my CONSTANTS.

On the other hand, making an ENUM_VALUE anything but all caps is as close to wrong as you can be and still compile:
https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html

 
Jesse Silverman
Saloon Keeper
Posts: 1313
40
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am seeing more and more poly-lingual programmers carrying their case-conventions with them as they hop from language to language, including in tutorial material one would hope would adhere to common conventions for the language being used.

I could easily be "One of Those Guys".  I try hard not to be, thus the question.

I definitely see people who have pretty intimate knowledge of a lot of Java that not everyone has, yet still Capitalizing things Randomly (or only apparently randomly, sometimes you can guess which language they have been working in lots recently by the patterns).

Several languages that didn't really have recommended "Style Guides" in any official capacity are starting to have them gain some traction.

I think part of that is due to so many changes in the languages, so that a high percentage of everyone using the language is "new" to lots of the features, and not yet set in their ways, so their is hope to get them into good habits.
Another is to resist the language-hoppers using Pidgin Capitalization tendencies and other naming conventions across the languages, which makes it decidedly harder to read new unfamiliar code quickly.
It has an odd side-effect of making it harder to tell which language one is looking at in an out-of-the-blue code snippet.

 
Tim Holloway
Saloon Keeper
Posts: 24321
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesse Silverman wrote:I strongly tend towards shouting my CONSTANTS.

On the other hand, making an ENUM_VALUE anything but all caps is as close to wrong as you can be and still compile:
https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html


Enum names are essential a bundle of manifest constants, so that simply falls in line with traditional C usage.

Though ironically, I often do NOT capitalize enum names in C/C++*, preferring to prefix them with an identifying prefix as to which enum they belong. About as close as I get to Hungarian Notation these days.


===
* mostly because I'm too lazy to hold down the SHIFT key while keying in that much text.  
 
Jesse Silverman
Saloon Keeper
Posts: 1313
40
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:

===
* mostly because I'm too lazy to hold down the SHIFT key while keying in that much text.  



Is your CAPS_LOCK key broken, man?

Anyway, interesting discussion thru-out, I will endeavor to capitalize things according to convention in whichever language I am working on at the moment.
 
Tim Holloway
Saloon Keeper
Posts: 24321
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesse Silverman wrote:Is your CAPS_LOCK key broken, man?



As far as I'm concerned all PC CAPS_LOCK keys are broken.  

The original CAPS LOCK was a lever key that latched down the left-shift key (which was in turn locked to the right-shift key) on a mechanical typewriter. The SHIFT function literally shifted the whole key-carrier assembly so as to cause the alternate type elements on each key to strike the ribbon/platen.

Computer CAPS_LOCK is an abomination - it twiddles the bits that define the character codes for upper/lower case. Meaning that if I press SHIFT while CAPS LOCK is on, I get lower-case and rarely is that what I want.  

There are desktop settings to select more civilized behavior, but as I bounce from machine to machine I get repeatedly burned, since it has to be switched on per-machine.

Anyway, my most common use for enumeration keys is in switch statements and since in many languages, switch selectors must be constants, SHOUTING is redundant. It's obvious from context. That makes it different from regular constants where you'd code things like "x * PI / 4".
 
Rob Spoor
Marshal
Posts: 22453
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

http://bash.org/?835030 wrote:
<Khassaki> HI EVERYBODY!!!
<Judge-Mental> try pressing the the Caps Lock key
<Khassaki> O THANKS!!! ITS SO MUCH EASIER TO WRITE NOW!!!
<Judge-Mental> <swearing removed here>

 
Saloon Keeper
Posts: 13280
292
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm really not a fan of ALL_CAPS, regardless of what kind of constant it is. It really does not convey any important information. However, I'm even less of a fan of flouting convention.

At least common convention for Java makes the difference between type names and member names clear. I absolutely despise the C# convention that constants and property names must be written PascalCase, which in many cases has led to situations where I will have a property that has the same name as the type of that property:

Granted, I could name the type PostAddress or BuildingAddress, but there are many cases where a type does not have an obvious alternative name.

This becomes especially frustrating when the type in question is a good candidate for a nested class. For sake of argument, let's say that Address would be a good candidate for a nested class inside Building. I can't do that and also have a property named Address, because Building.Address would be ambiguous.
 
Jesse Silverman
Saloon Keeper
Posts: 1313
40
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Stephan.
Tho I avoided Naming it, I believe that Programmers capitalizing Identifiers that one wouldn't expect to be capitalized in Java and C++ when in those languages are also Working in C#.

I don't have time to prove it, but that's my suspicion.

It is rather tricky to balance adhering to non-required Conventions in each language whilst also memorizing what is legal and illegal, primarily for Cert Exams and Interviews, but I am attempting to do so.

Lastly, I do see how an overly strict adherence to Best Practices treated as Absolute Rules can obscure tutorial lessons, because a module named moduleA containing a package named pack1 leads to very short and clear syntax examples of command line options and module-info.java contents while teaching that.  Calling both the module and the package com.coderanch.modulelesson is much more advisable in terms of coding standards, but obscures the teaching of new syntax (is this a module name or a package name here? also, longer command lines and everything else in a quick lesson).

 
Stephan van Hulst
Saloon Keeper
Posts: 13280
292
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesse Silverman wrote:Calling both the module and the package com.coderanch.modulelesson is much more advisable


But not by much. This is another of my pet peeves about programming tutorials. They're usually full with terrible names such as "lesson2", "week5", "BaseClass", "DerivedClass" (or worse, "Parent" and "Child") that describe where or how to use the code, but do nothing to describe the problem domain.

I think it's especially important for beginners to learn good naming practices, so instead the author should take the time to come up with a good case study that they can use throughout the different lessons and then use names that reflect the problem domain. This will also help beginners relate how abstract code can solve real problems.

A good name for a class could be com.coderanch.zoo.animals.Lion. When you want to demonstrate how an access modifier such as public works, instead of having a.A access b.B, have com.coderanch.zoo.staff.BigCatHandler act on the aforementioned Lion.
 
Jesse Silverman
Saloon Keeper
Posts: 1313
40
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stephan:
You probably already know this, but Scott and Jeanne's Sybex book do just that.

I mentioned before because I had just realized, there were some places where module names and package names (both of which would be relatively good in Real Life) appeared somewhere in a syntax that one was seeing for the first or second time and in those cases the places that had toy (bad) names made it a little easier to learn/remember the syntax of say,

exports myPack to moduleA, moduleB;

Also, rules vs. best practices such as "What relationship should there be between a module name and the names of the packages that comprise it?" I was pleasantly surprised to see at least on the mock exams from the same source.

I was watching a few Oracle-sanctioned videos on JPMS the past day or two.

They generally eschew garbage package and module names in favor of those that at least look legitimate, i.e. both unique and following standard naming best practices.

Thanks.


 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic