How to do CamelCase with German words (or with any other language that supports compound nouns)?
Asked Answered
S

3

6

Disclaimer: Feel free to close this as "too localized", if you think it is inappropriate for StackOverflow. Since there's quite a large German-speaking community here, I thought I'd give it a try.

CamelCase is used frequently in programming language conventions (method names in C#, public method names in Java, etc.). It's quite easy to do in English: You just concatenate the words and capitalize the first letter of each one: DisplayName, InternalName.

German, however, supports compound nouns in many cases. E.g., "Anzeigename" (DisplayName) is a single noun, but "interner Name" (InternalName) is not. So, the latter case is easy to camelify: It's InternerName, just like the CamelCase rules in English. What about the first case? One could

  • use Anzeigename, to keep consistent with German grammar, or
  • use AnzeigeName, to keep consistent with the look and feel of CamelCase and with other *Name-s, which are not single nouns.

Is there some guideline or well-established best practice on this?

I realize that just using English names solves this problem quite easily, but that's sometimes not feasible when developing domain-specific software, or when configuration files must be human-readable by people without good English language skills. It just doesn't make sense to make up an English translation for Umsatzsteuervoranmeldung, when you are certain that the software will only be used in a German language context...

Stunt answered 31/8, 2011 at 9:33 Comment(4)
Argh. Please do not use denglish in code. if (Anzeige) then Aufruf() is extremely irritating.Recuperative
IME it is best to find english words, I'd only use a localized word if there is no direct equivalent.Worship
I agree that it's a nuisance. Still, there are situations where no English equivalent exists or where an English equivalent would appear very out-of-place or artificial. In these cases, the problem illustrated above arises. In fact, in these cases, it might make sense to use German for all words, to be at least consistent in this regard.Stunt
Tag german removed as part of the 2012 cleanup.Monkery
B
7

There is the same problem in English too.

For example Surname versus LastName

Use a captial if when written in the language there would be a preceding space

Breakneck answered 31/8, 2011 at 11:53 Comment(0)
R
1

I don't think there's any reason why you would camelcase names to be "conformant". Norwegian (my native language) works the same way and camelcase should not be for anything else except a replacement for blanks.

But then again, I would never write code in anything except English.

Rutty answered 31/8, 2011 at 11:40 Comment(0)
S
0

Regarding the example of Umsatzsteuervoranmeldung from the final paragraph:

The rules of the German language allow you to use a hyphen instead of a compound noun if it makes the word more readable (Duden, rule D22): You are allowed write the word as Umsatzsteuer-Voranmeldung.

We found that using an analogous rule for camel-casing words works for us: If adding a hyphen makes the word more readable in "regular language", adding an uppercase letter is likely to make it more readable in camel case. Thus, for the examples in your question, we'd use Anzeigename, InternerName and UmsatzsteuerVoranmeldung.

Stunt answered 2/8, 2024 at 17:41 Comment(1)
Note: This is a self-answer after more than 10 years, describing what "worked for us" after trying multiple different approaches.Stunt

© 2022 - 2025 — McMap. All rights reserved.