18

I'm working on a game engine in C++ and I have methods like setColour and things that use British grammar. While I was thinking how C++ compilers mostly use the English language (correct me if I'm wrong) and how most APIs use American grammar, should I go with the flow and continue the unofficial standard in the grammar programmer high council or be a rebel?

I'm not sure which.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Jookia
  • 6,544
  • 13
  • 50
  • 60
  • I had the same question, being a foreigner. unfortunately there is no consensus, as far as I could tell. boost for example uses both British and American spelling. – Anycorn Mar 15 '10 at 02:03
  • 8
    Compilers don't use the english language. Complilers use compiler language. Beep boop zap beep beep. – George Johnston Mar 15 '10 at 02:04
  • 1
    @George: I think he means that C++ keywords are (based on) English. Error messages and such can be localised. zed. – Steve Jessop Mar 15 '10 at 02:12
  • At least spell it correctly, I use a major library where a couple of methods were mispelled (by non-English speakerS) but became too widespread to correct! – Martin Beckett Mar 15 '10 at 02:16
  • 3
    George: "Beep boop zap beep beep." See, I tried that, but whenever I say that to *my* compiler it gives me some annoying error message. I think my compiler must be broken. – itowlson Mar 15 '10 at 02:21
  • @Martin: by non-English speakers, I can forgive. There is no excuse for "Referer" in HTTP. – Steve Jessop Mar 15 '10 at 02:25
  • @Martin - You mean Linux and `creat` ? – Chris Lutz Mar 15 '10 at 02:29
  • @Chris Lutz - `creat` predates Linux. – asveikau Mar 15 '10 at 02:36
  • I don't understand how people can miss out the 'e' in user. Is it some sort of l33t speak? – Tom Hawtin - tackline Mar 15 '10 at 02:51
  • If only we could use "colour" when defining style attributes in web design... Sad Panda :( – Ganesh Shankar Mar 15 '10 at 02:53
  • @asveikau - My point was that it also predates applying common sense to designing software systems, but you are correct. "Linux" should have been "Unix". – Chris Lutz Mar 15 '10 at 03:00
  • 1
    Creat isn't a typo, 5 letters was a limit on a predecessor. There is an entry in the samba manual that says on entry is spelled a certain way because they are Australians and speak the Queen's English. – Martin Beckett Mar 15 '10 at 04:50
  • [why don't we have both?](http://d37nnnqwv9amwr.cloudfront.net/entries/icons/original/000/006/759/both.png). this is just semi-serious: can't you just typedef it and make everyone happy? – João Portela Dec 31 '11 at 20:28
  • upon further thought that wasn't a very good suggestion. Besides [it had been suggested already](http://stackoverflow.com/a/2444657/86845). I think I just really wanted to use that meme XD – João Portela Jan 02 '12 at 15:49
  • @ChrisLutz Linux is not UNIX, and there is absolutely no reason it should be called UNIX when it is not UNIX. – Miles Rout Jan 04 '14 at 10:55

10 Answers10

36

You should use the American spelling of color. 99% of code out there uses this, even including much of the code written by British or Australian English speakers. If you use something different, you (or someone else that uses your code) are just going to end up forgetting which to use at some point and making a needless mistake.

Tobias Cohen
  • 19,893
  • 7
  • 54
  • 51
  • 7
    +1 As a New Zealander (we use the British spelling) I would always try and persevere with the 'correct' British way until one day I realised how ridiculous it was - just use color. The great majority of code already uses it, it's shorter, and I don't often submit my code in English classes. – gacrux Mar 15 '10 at 02:25
  • 4
    +1 This is especially true if you're working with something like the Java API which already uses `color`. Mixing your own `colour` with the API's `color` is asking for trouble. (I'm Australian btw.) – David Johnstone Mar 15 '10 at 02:39
  • 3
    I agree and this is how I work, but it still does make me sad though... Especially during all the times I'm debugging and end up finding a "typo" of colour :( – Ganesh Shankar Mar 15 '10 at 02:59
  • 1
    +1. "Color" is the de-facto standard and will be used in most APIs already. In general, American English is the standard for all code worldwide, for historical and other reasons. – Max E. Mar 15 '10 at 03:15
  • 2
    Now that we're well on the way to fixing everyone's spelling of 'color', maybe we can start on weening you away from the metric system and overly colorful currency (6 shades of green are enough for anybody). We'll work on 'bonnets', 'boots', and 'chips' later. I promise to let you continue using 'football' incorrectly. – Michael Burr Mar 15 '10 at 05:44
  • 4
    @Michael Whilst "Color" is the de-facto standard in programming, be aware that some people can be quite possessive of their grammar and spelling - It's not our fault the yanks couldn't get it right :p (excuse me while I put my flame suit on) – Basic Mar 15 '10 at 17:37
  • 6
    @Michael: I hope you're aware that we Americans are the ones using "football" incorrectly, and each region of the USA and the English-speaking world has its own slang, dialectical variations, etc. Also, the word you're looking for is "weaning." – Seth Johnson Mar 15 '10 at 17:38
  • 1
    Most coders that don't speak english natively learn the american english. –  Apr 04 '10 at 18:27
  • 2
    @user216441: Your statement is a perfect example of something that would fly just fine in 'Murica but nowhere else. – Mad Physicist Jul 25 '17 at 14:09
15

I'm British, and I think the right thing to do is to grit my teeth and use Color. I wouldn't normally expect a German-speaking programmer to use Farbe in a public API[*] and I wouldn't expect to have to provide alternative spellings like finalize vs finalise or localization vs. localisation.

The compiler will point out any mistakes, so I think providing alternative names for things is misguided. Come to think of it, it could even hinder some programmers since IDE auto-completion will have more to chew on. If you're going to use a single spelling hten "Color" is such a common word in APIs, commonly spelled without the "u", that it's wilful idiosyncrasy to spell it any other way. It doesn't help anyone much.

Obviously there's no clinching argument - you can call your functions method001, method002 if you like, and the code will still work, so Colour is a minor quirk by comparison. But there's a fine line between "quirky" and "misanthropic".

[*] Just because he finds it more readable than Color, I mean. If he doesn't speak English at all, he has no choice.

Steve Jessop
  • 273,490
  • 39
  • 460
  • 699
14

Be a rebel! Go with your native English.

If you feel like tossing a sop at the Americans, provide cover functions with the incorrect spelling (facetiously: but just make sure they run enough slower that they prefer to use the right spelling).

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 1
    +1 for "do it both ways." That's probably the best way in this case. – Chris Lutz Mar 15 '10 at 02:02
  • 1
    @Chris: really? How about `localize` vs `localise`? (A variant spelling within British English, as well as a British-American difference). Do you always remember to make those #defines too? What about Grey vs. Gray? Or let's not forget EU harmonization: Gris, Grau, Grigio, Šedá (I confess, the last one I looked up). I think this could rapidly get out of hand. – Steve Jessop Mar 15 '10 at 02:18
  • 9
    Hmm, for C++0x how about `std::list`, `std_en::list`, `std_es::lista`, `std_de::Liste`, and so on ;-) – Steve Jessop Mar 15 '10 at 02:35
  • 11
    @Steve Jessop: How interesting it would be to see `std_ja::リスト` – dreamlax Mar 15 '10 at 03:02
  • 2
    @dreamlax. This is actually not a terrible idea. Have a feature in major IDEs to "Select Viewing Language..." to translate from one to the other for you. – Mad Physicist Jul 25 '17 at 14:12
9

Which naming convention you choose is unimportant. Use whichever form you're more comfortable with, so long as you are consistent, both within your own code and with any associated APIs that you work with.

greyfade
  • 24,948
  • 7
  • 64
  • 80
  • 1
    This is one case where I'm going to disagree with the consensus: why not have _both_ `doStuffColor` _and_ `doStuffColour` work, and produce identical results? This can be done with some simple `#define`s or with inline functions (or both). – Chris Lutz Mar 15 '10 at 02:02
  • 6
    @Chris: that seems unnecessary. Just pick one dictionary to use and be consistent. – xian Mar 15 '10 at 02:13
  • @Chris: It's an unnecessary maintenance load. Why should you have two functions that do exactly the same thing, just with different names? It's not needed. Period. – greyfade Mar 15 '10 at 02:46
  • @Chris why not have SetColor in german, and all the other langauges. – mP. Mar 15 '10 at 02:55
  • 1
    Isn't it contradictory to say "naming conventions are unimportant" then say "so long as you are consistent"? Just saying... – Michael Burr Mar 15 '10 at 05:51
  • @Michael Burr: You're right, of course. My meaning was that *specific* naming conventions are unimportant. I my post (2 days ago ><). – greyfade Mar 18 '10 at 06:44
6

I've been using those crazy spellings they use on a small island called England for a number of reasons:

  • I work here
  • All my colleagues work here
  • Well.. it's the English language
  • We like to think we invented the internet
  • We all think we still have this huge empire and rule the world, etc
  • We don't like the yanks! >:(

However, primarily I write C#, HTML, CSS, JS, etc. I could remain stubborn and use our own spelling, but all of these languages use Americanised keywords and member names. I ended up with a bloody load of tosh!

In my C#:

public Color BrightenColour(Color colour); // eew, minging

or in my CSS:

.greyColoured { color: gray; } /* not semantic? crikey! */

or my jQuery:

function serialiseForm() {
    return $('input, textarea, select').serialize() // cor' blimey!
}

or my HTML:

<div align="center">Centre</div> <!-- goodness gracious me! -->

So, today, I finally gave in and did a solution-wide find-replace on all my old, traditional spellings. Although I don't like all my new cross-atlantic spellings, my code is now a lot cleaner :D

Tally-ho!

Connell
  • 13,925
  • 11
  • 59
  • 92
6

As an Australian, I have the same considerations.

At work, we do not use US spelling, largely as it is not second nature for us to spell this way, so it would (theoretically) take longer to code if we stick with US convention, as we will always have to second guess ourselves. In doing so, we don't appear to have any problems jumping between our APIs and external US convention style libraries, but if you think you might, that will need to be a consideration.

I believe you should go with what ever comes naturally, as that will be easier for you.

And if that means sticking with your UK spelling, do so with a touch of pride ;)

johnc
  • 39,385
  • 37
  • 101
  • 139
5

It really doesn't matter which you choose, but just make sure you remain consistent.

Kyle Lutz
  • 7,966
  • 2
  • 20
  • 23
4

Definitely the smartest thing to do is to pick one convention and stick with it (and also document it). C++ only "uses" a small numbers of reserved keywords. Everything else is up to you (but of course a crazy naming convention will just infuriate those who come after you).

To make a more general point, though, there is absolutely no reason to change the way you are used to spelling things. I've heard of many cases where people inherited code whose comments were in French or German: now that could be an issue in terms of maintenance!

EDIT: A point I believe is not touched upon by all the answers that say you should just stick to the American spelling: there are many cases where (to the best of my knowledge) American spelling itself has not converged, e.g. "parameterize" vs. "parametrize" (and note that I used "z", so both of these are American spellings).

Alexandros Gezerlis
  • 2,221
  • 16
  • 21
2

My rule, as a Canadian, is to use "color" in identifiers and "colour" in comments. For instance:

/// <summary>Return the colour in CIE Lab space.</summary>
public GetLabColor() : double * double * double;
Don Reba
  • 13,814
  • 3
  • 48
  • 61
1

Why not internationalise your method names. I propose two options for this. * Name your methods in the following manner 'method1", "method2" and provide different cheat sheets for different locals, so that the British one would have method1=setColour, while in America they would see method1=setColor.

Another option is to use something like ASM to rewrite the class files inside your jar files so that for americans the method is "setColor" while in Britain and the rest of the Commonwealth they see "setColour". This would remove the need for duplicate setColor/setColour as someone else has suggested.

mP.
  • 18,002
  • 10
  • 71
  • 105