tags:

views:

1087

answers:

18

Jeff finished his post talking about this, but I don't catch the idea.

So, why do you think this is a bad coding style?

EDIT:

I, as a lot of you, don't think that it is a bad coding style. But Jeff is far better programmer than me, and his point of view turned on lights on my head to get answering if I was wrong. I was a Delphi developer for some few years and am becoming a C# developer now, and in Delphi it was a common practice.

+1  A: 

ALL CAPS IS LIKE SHOUTING AT SOMEONE.

S.Lott
+1  A: 

IT ALSO MAKES THE CODE HARDER TO READ

Sergio
+1  A: 

FLIP THE QUESTION, WHY USE ALL CAPS?

ck
+3  A: 

Jeff has some additional things to say on this in the comments:

However on the other side and the reason I do still use the all caps and underscore

Less code? That's a worthwhile cause deserving of serious discussion.

But whether you call something "foo", "Foo", "_foo", or "FOO"? Meh.

Naming conventions are highly controversial and religious. Developers should pick something they like, something that's hopefully not too much at odds with the "local conventions", and just go with it. A lot of discussion and hand-wringing over naming isn't worthwhile.

That said, I think ALL CAPS IS REALLY HARD TO READ!

I also use this for constants, but I also can understand why some people don't like it. It's a bit like writing everything in lowercase in german or other languages.

schnaader
+2  A: 

Some people consider ALL CAPS to be "old school". Consider the difference between:

const string ErrorMessage = "Some error message.";

and

const string ERROR_MESSAGE = "Some error message.";

Both are completely usable, but the ALL CAPS version is less used by newer developers, such as the ones that started out with .NET.

I consider it a bad coding style if your team is using a different style. Other than that, I don't really care. At least when I see ALL CAPS in some shared code, I can guess that it's a constant.

Robert S.
-1: Not "old school", but language/platform dependent. In .NET it is discourages, but other cases it is encouraged.
Richard
I guess you didn't read Jeff's post, in which he specifically called it "old school."
Robert S.
A: 

@ck,

BECAUSE IT'S CONVENTION.

lfaraone
A: 

I use ALL_CAPS for macros and preprocessor symbols. So my pre-C99 C constants are ALL_CAPS, but not in any other language I know of.

jfclavette
+5  A: 

I don't think it's bad coding style. Maybe old-fashioned, but not bad. It does make constants stand out from other variables.

Jeff
+1  A: 

I don't think that it is wrong. Mostly, it's a personal choice. For your personal coding, do what you want. For you professional coding, follow company policy.

Muad'Dib
+2  A: 

Well, there's the old readability issue. Normally-cased test is just easier to read.

There are exceptions, though. Languages like SQL are usually all upper-case (although case-insensitive).

Also, there are other uses, like to distinguish between "constants" and regular variables, which you'll see in a lot of languages like PHP, Python, etc., even though Jeff for some reason doesn't like that, and it is apparently against the C# code style guidelines.

So generally, I don't think it's wrong anywhere, but I do think that one should always try and follow the general best practises. When in Rome, do as the Romans – when coding Python, follow PEP 8 :)

mikl
A: 

Just like writing everything in bold is not a good idea

RN
You wrote Java/.Net code in Word?
romaintaz
A colleague of mine set his code editor font to be bold... it was definitely interesting to be able to read his code from across the entire room.
J. Steen
+4  A: 

The only compelling reason to me is consistency in style. For non-.NET languages like Java / C++, all-caps constants are certainly acceptable.

For C#, the standard is to use PascalCase, as noted here: C# naming convention for constants?

Scott Wegner
Yep, assimilating the style of the platform / language is the way to go. +1
0xA3
+14  A: 

You'll find that a lot of Jeff's statements are controversial first, with accuracy being a secondary concern. His blog wouldn't be that popular if he weren't occasionally inflammatory. (Consider the last line of Death to the Space Infidels, "That said, only a moron would use tabs to format their code.") It's honestly subjective. Don't take everything he says as True and Good -- it's not meant to be. If you disagree, go kick his ass in the comments, and see if he writes back. :)

I think ALL_CAPS_CONSTANTS are perfect: they're instantly recognizable and familiar. Part of my workplace's style guidelines (and we don't have that many) is to write all static constants in caps. Don't sweat it; just use whatever the rest of your team uses. Deciding on StudlyCaps vs. camelCase vs SCREAMING_CAPS is worth maybe 90 seconds discussion.

ojrac
+19  A: 

All caps is the traditional C designation of a preprocessor macro constant. It's very useful to have these in a different namespace from anything else, since the preprocessor will substitute wherever it finds the name, regardless of things like scope.

A constant in the sense that Jeff was using is, semantically, a variable that can't be changed. It obeys all scoping principles and everything, and is semantically identical to a non-const variable with the same value.

To put this another way,

#define max_length 5

is a problem because somebody might use max_length as a variable in a different context, where it would normally be safe, while

const int max_length = 5;

is simply a variable declaration. Therefore, there's an advantage in using

#define MAX_LENGTH 5

because the convention is that only preprocessor constants are all-caps, so it will not interfere with any other use.

David Thornley
+1 In addition, if you use macros for calculations (say the canonical bad MAX() and MIN() bit), it helps to know that arguments to these objects have pre-processor semantics not compiler semantics.
dmckee
+1 Very good answer!!!
eKek0
+8  A: 

Frankly, I don't think it is bad coding style. Indeed, even the official Java code style makes constants all capitals (http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html), as do other language conventions.

In theory, it's harder to read - we humans like to use the variable height of letters to increase reading speed (we can infer a lot of information from just rough word shape and the first/last letters). However, I don't have a problem with short, all capital phrases. It's hardly "shouting" (you compiler doesn't exactly care how rude you are), and clearly shows the names are potentially mutable, and those that are not.

Adam Wright
+3  A: 

Screaming is fine. In the case of the constant it tells the reader

DONT THINK ABOUT CHANGING ME LATER IN CODE

But I understand if soft programmers get offended.

Rich
A: 

I remapped my capslock to a ctrl key (woo emacs!). So I think its bad style when I have to type 30-character names while holding down shift

Alex
A: 

"Old School" is now a ridiculous, over-used and meaningless term except perhaps when referring to ones old school. Otherwise, please stop using it, or use the full form of the idiom "old school of thinking" - which, for this discussion is inapplicable as there is more than one school of thought as regards caps usage. And, old is not bad, just different!

jas

jas