Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Coming from a Java background, I'm very used to camelCase. When writing C, using the underscore wasn't a big adjustment, since it was only used sparingly when writing simple Unix apps. In the meantime, I stuck with camelCase as my style, as did most of the class.

However, now that I'm teaching myself C# in preparation for my upcoming Usability Design class in the fall, the PascalCase convention of the language is really tripping me up and I'm having to rely on intellisense a great deal in order to make sure the correct API method is being used. To be honest, switching to the PascalCase layout hasn't quite sunk in the muscle memory just yet, and that is frustrating from my point of view.

Since C# and Java are considered to be brother languages, as both are descended from C++, why the variation in the language conventions? Was it a personal decision by the creators based on their comfort level, or was it just to play mindgames with new introductees to the language?

share|improve this question
    
By the way: neither Java nor C# are descended from C++. Java is descended from Objective-C (which is descended from Smalltalk), so it makes sense for them to use naming conventions from Smalltalk. C# is descended from the Pascal/Modula family (the lead designer of C# was also one of the lead developers of TurboPascal/Borland Pascal/Delphi), so PascalCase is no surprise there. –  Jörg W Mittag May 6 '13 at 23:19
add comment

5 Answers

up vote 8 down vote accepted

The culture difference originated long before C# or Java.

All three conventions have coexisted since the late 60s or early 70s, and have been popular in different groups. (As well as other conventions, including the unlamented Hungarian notation that Microsoft inflicted on so many for so long.)

In particular the inventors of Java were at Sun, and many were involved with StrongTalk, which is a form of Smalltalk. The Smalltalk community has used camelCase for a very, very long time.

The inventors of C# came from Microsoft. StudlyCaps was one of the major conventions at Microsoft, and is heavily seen in places like Visual C++.

Those originator styles appear in all of the core documentation, which influences groups who pick up the language, and therefore has caused the split in capitalization conventions between two very similar languages.

share|improve this answer
add comment

YOU FORGET FORTRAN, THE FIRST HIGHER LEVEL COMPUTER LANGUAGE. BACK IN THOSE DAYS THERE WERE NO LOWER CASE LETTERS, AND SO EVERYTHING WAS IN UPPER CASE. LATER WE HAD EBCDIC BUT STILL THE KEYPUNCHES DID NOT SUPPORT LOWER CASE LETTERS SO ALL PROGRAMS WERE STILL KEYPUNCHED IN CAPITAL LETTERS. COBOL SAME AS FORTRAN; AFAIK SAME FOR ALGOL BACK THEN.

Then along came ASCII and terminals and suddenly lower case letters were all over the place.

When you want to name something "next serial number" it is natural to want to break it into three words. But with one disasterous exception, no language I've ever used allows blanks in names. So you can write next_serial_number or NextSerialNumber or nextSerialNumber or anything similar depending on your taste.

Personally I see no reason why the first word should be lower case and the rest of the words capitalized: "nextSerialNumber" makes no sense to me at all.

AND YOU CAN STILL TYPE IN CAPS IF YOU WISH.

share|improve this answer
    
PHP allows blanks in names... as long as these are from above ASCII range (i.e. different Unicode chars that render as blank space). Undocumented feature - do not (DO NOT) use. –  Mchl Jun 25 '11 at 16:51
add comment

Naming convention, as I learned in Software Engineering course, is to make code consistent and self documenting.

The naming conventions of languages could more have to do with the timeline a language was being used the most and the naming conventions that were prominent at the time. Hence those naming conventions that were being used at the time of a particular language was famous got stuck together.

There are no restrictions what naming conventions you use as long as your code is consistent and self documenting for the sake of maintainability.

share|improve this answer
    
But you should conform to the conventions of the language you use. In Java - ALL_CAPS mean a constant, thisIsAMethod() and ThisIsAClass. Do it differently and even if you are consistent your code will be harder to maintain. –  user1249 Feb 28 '12 at 15:40
add comment

To the best of my knowledge, none of the languages you mentioned enforces any naming convention.

As to the naming convention of the standard libraries - you have to remember that C came first, C++ wanted to be backward compatible to C while improving some, and Java and C# were developed to compete against each other (while learning lessons from C and C++, both). Sometimes migrating from one language to another is not in the best interest of the language developers.

In your own code - you can use whatever naming convention you want, there's no restriction.

share|improve this answer
    
I have to take issue with your first statment as the languages don't specifically enforce a convention, but in the basic APIs, there are classic conventions followed. For example, strtok in C could be written as stringTokenizer in Java and StringTokenizer in C# –  Jason Jun 24 '11 at 23:27
1  
@Jason - that's not enforcing convention on you, that's the convention they use (they=developers of the language standard library). The fact that in C they call it strtok doesn't prevent you from making a stringTokenizer function of your own. That what I was trying to say. –  littleadv Jun 24 '11 at 23:39
add comment

Anders Hejlsberg is the lead architect of C#. He comes from a Pascal background, and this has influenced C# in various ways.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.