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)

7
  • 2
    Why do you think it is called Pascal case? Commented Mar 1, 2011 at 19:14
  • 2
    @Martinho Fernandes it is standard name for this style, check Google
    – Andrey
    Commented Mar 1, 2011 at 19:16
  • 1
    @Nocturne - Yes. I would be curious :) Commented Mar 1, 2011 at 19:17
  • 1
    Wouldn't it make more sense to name a casing convention after a case-sensitive language?
    – dan04
    Commented Mar 2, 2011 at 3:17
  • 2
    The "method names start with a lowercase letter in most languages" is false in my experience. Conventions starting with an uppercase letter - with or without underscore word-separating - are quite common, though not necessarily in official language guidelines. Most language standards don't have any single official style guides. Quite a few languages (mainly older) ignore case anyway, and often have an everything-lowercase convention because don't-press-shift is the laziest rule that means you don't get differently-mixed-case spellings treated as the same confusion.
    – user8709
    Commented May 13, 2011 at 21:46

6 Answers 6

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...

5
  • 2
    TurboPascal is the baby of Philip Kahn (aka Borland) which is very convenient for Microsoft to forget. Politics....
    – davka
    Commented Mar 1, 2011 at 22:19
  • 1
    The comments on the first link are great, lol.
    – jmq
    Commented Mar 1, 2011 at 22:20
  • 1
    @davka Borland was the name of the company, Philip Kahn was their CEO for many years. And there was no competition between them and Microsoft, in fact Microsoft saved them from going bankrupt more than once by investing. Borland made popular development tools for DOS and later Windows. Microsoft recognized this and figured Borland was good for the platform at a time in which there was no real alternative for their tools yet. (Visual) Basic was... well, basic and Microsoft C was too spartan. Borland filled that gap nicely. This situation changed with .NET . Commented Jun 5, 2022 at 17:21
  • 1
    @MartinMaat: And Anders of course worked for Borland for many years. However it is incorrect to say that Microsoft and Borland were never competitors. The tools team considered Borland to be a partner, and a competitive threat, and for a time, a quality bar to aim for, as it suited them any particular day. A recurring internal joke that more than one person got in trouble for in early days at MSFT was to add "Buck Forland" to the credits easter egg of various products. Commented Feb 27 at 22:35
  • 1
    But generally speaking you are absolutely right that MSFT badly needed Borland in early days. The Microsoft C compiler was not good enough to compile Windows in early days so Windows used either Borland or, for early 32 bit builds, WATCOM compilers. And indeed much later on, as much of the design of .NET was, let us say heavily inspired by Delphi, that relationship changed a lot. Commented Feb 27 at 22:37
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#.

3
  • this was going to be my answer. :P
    – DevSolo
    Commented Mar 1, 2011 at 19:23
  • @DevSolo sorry, I started typing answer when question was at Stackoverflow :)
    – Andrey
    Commented Mar 1, 2011 at 19:26
  • I think that the roots go even deeper into ancient history - see my answer below :)
    – davka
    Commented Mar 1, 2011 at 22:14
9

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

1
  • 13
    and I still hate it, lol.
    – jmq
    Commented Mar 1, 2011 at 22:19
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)
8
  • Note that this naming guideline is for the .NET framework and not C# in particular. In VB.NET, a case-insensitive language, the convention remains the same, but you cannot use it distinguish private and public members by case. Commented Mar 1, 2011 at 19:21
  • @Martinho: agreed. but I still feel is was one of the reasons.
    – decyclone
    Commented Mar 1, 2011 at 19:22
  • 13
    +1: "They did not want C# code look like Java code (which heavily uses camel case)": I strongly suspect you are right here!
    – Giorgio
    Commented Apr 21, 2012 at 16:41
  • What's ironic is that despite some people's hatred of Hungarian notation, Java and C# would probably have both been much better languages in practice if they had adopted Apps Hungarian (or other naming convention) to distinguish reference-type fields that "own" a mutable object identified thereby, those which identify a mutable-type instance that must never be mutated, etc. Even if the Runtime doesn't care about such distinctions, it's impossible to write code which is efficient and correct without knowing which variables are of what kind.
    – supercat
    Commented Nov 4, 2014 at 22:22
  • 1
    They did not want C# code look like Java - The original name of C# was "Not Java", with an inferred "ha-ha" at the end,
    – radarbob
    Commented Jun 5, 2022 at 20:21
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.

4
  • 4
    and TurboPascal was conveniently designed and built by Anders Hejlsberg...
    – SWeko
    Commented Mar 2, 2011 at 8:08
  • 7
    Anders Hejlsberg was IIRC the lead designer of Delphi, and worked a lot on Turbo Pascal, but Turbo Pascal wasn't originally his baby (it was Philip Kahns). Niklaus Wirth invented the original Pascal and took it through standardisation, then saw the standard largely ignored. Also, Wirth has been retired for just about the whole of the life of C#, and before then designed several successor-to-Pascal languages (most recently Oberon 2) so I doubt he had any direct involvement at all. Microsoft bragged loudly about having Hejlsberg on board. Turbo Pascal was a Borland product from the start.
    – user8709
    Commented May 13, 2011 at 21:35
  • I don't mind downgrading - I have enough points on StackOverflow, but I am curious about the reason
    – davka
    Commented Apr 13, 2014 at 13:36
  • Wirth just turned 65 when the first iteration of C# was designed and I never encountered his name in the context of any Microsoft development. So I think the reason for the lack of sources to support this story is simple: it is not true. Commented Jun 5, 2022 at 16:50
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.

7
  • 5
    do-not-forget-lisp-style-naming! Commented Mar 1, 2011 at 19:16
  • @Martinho Fernandes actually in context of c-like languages it is not valid.
    – Andrey
    Commented Mar 1, 2011 at 19:20
  • Yeah, Lisp takes whitespace into account. (- var1 var2)
    – Michael K
    Commented Mar 1, 2011 at 19:31
  • @Martinho Fernandes: Of course, that requires the use of whitespace to separate tokens. It's also COBOL-STYLE-NAMING, which makes it common to the languages I most admire and least admire. Commented Mar 1, 2011 at 19:55
  • I'm sad to this day that cobol-naming-style has mostly disappeared. I'd say my typing speed went down 12% when I was forced to use under-scores. Thank goodness Pascal-style does away with under-scores. Now let's get the shift-period back on the keyboard!!
    – radarbob
    Commented Jun 5, 2022 at 20:17

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