40

I'm just starting to learn C#. Coming from a background in Java, C++ and Objective-C, I find C#'s Pascal-casing its method-names rather unique, and a tad difficult to get used to at first. What is the reasoning and philosophy behind this?

I'm guessing it is because of C# properties. Unlike in Objective-C, where method names can be exactly the same as an instance variables, this is not the case with C#. I would guess one of the goals with properties (as it is with most of the languages that support it) is to make properties truly indistinguishable from variables and methods. So, one can have an "int x" in C#, and the corresponding property becomes X. To ensure that properties and methods are indistinguishable, all method names I'm guessing are also therefore expected to start with an uppercase letter. (This is just my hypothesis based on what I know of C# so far—I'm still learning). I'm very curious to know how this curious guideline came into being (given that it's not something one sees in most other languages where method names are expected to start with a lowercase letter)

(EDIT: By Pascal-casing, I mean PascalCase (which is basically camelCase but starting with a capital letter). Method names typically start with a lowercase letter in most languages)

gnat
  • 20,543
  • 29
  • 115
  • 306
Debajit
  • 503

6 Answers6

33

It is matter of taste. Someone once decided to use Pascal style for names and it became a standard.

I have a wild guess that it was Anders Hejlsberg, who was architect of Delphi, successor of Pascal. Case style is same there as in C#.

Andrey
  • 1,209
26

If you are asking about reasons, here is one straight from the horse's mouth:

History around Pascal Casing and Camel Casing article by Brad Abrams at MSDN blogs

In the initial design of the Framework we had hundreds of hours of debate about naming style. To facilitate these debates we coined a number of terms. With Anders Heilsberg (the original designer of Turbo Pascal) a key member of the design team, it is no wonder that we chose the term Pascal Casing for the casing style popularized by the Pascal programming language...

Pascal Casing convention capitalizes the first character of each word (including acronyms over two letters in length)...

And here are the design guidelines: Design Guidelines for Class Library Developers

These guidelines are intended to help class library designers understand the trade-offs between different solutions. There might be situations where good library design requires that you violate these design guidelines. Such cases should be rare, and it is important that you provide a solid justification for your decision. The section provides naming and usage guidelines for types in the .NET Framework as well as guidelines for implementing common design patterns...

Glorfindel
  • 3,167
Yogesh
  • 506
9

Don't know about philosphy, but Pascal casing seems to be common on Microsoft platforms since at least Win32 API days.

6

I don't think there was a specific philosophy behind it. There needed to be guidelines, and there were many points that may have affected it:

  • They wanted to get rid of any prefix notations (read hungarian here)
  • They wanted that local/private members and public members be distinguished by just reading their names.
  • They did not want C# code look like Java code (which heavily uses camel case)
decyclone
  • 284
1

Taking a wild (but not unreasonable, IMHO) guess - C# design was supervised by Niklaus Wirth, the original inventor of Pascal. See the connection?... :)

Curious #1: I positively remember the announcement of .NET and C# (yes, I am prehistoric...) and how Microsoft bragged by having Wirth's name on C#. Yet, the Wikipedia pages on neither (C# and Wirth) mention this.

Curious #2: Although it is called PascalCase, it was popularized by the TurboPascal compiler (which eventually became Borland), not the language itself.

davka
  • 127
0

I don't know that there is a "philosophy" behind the casing other than it's nice and compact and can easily appear as multiple words without using underscores.

There's been many variations of casing over the past few decades. They've ranged from very terse (see C and the standard C library) to verbose with underscores separating each word. While the .NET library convention of naming is still pretty verbose, I think it strikes some middle ground as far as casing.