Fog Creek Software
Discussion Board




Case sensitive environments

Now I know a lot of people love Unix, Jave and Javascript.. often for reasons I can't understand. But after today's fun writing some Javascript I just cannot understand any possible benefit from case sensitivity... why oh why oh why. It is such a pain in the arse..

Are there are proponents out there? Would they care to put a compelling case forward and educate me?

gwyn
Monday, July 28, 2003

String comparsions are easier?

Flamebait Sr.
Monday, July 28, 2003

When read code, I prefer the case to be the same everywhere, rather than according to each programmer's individual style.

I also prefer the indentation to be standardised, and Python (sort of) offers that.

John K.
Monday, July 28, 2003

Not sure I understand either of those points.

Today I spent a while trying to understand what I'd done to upset my script..

Turns out I had mis-cased one of my many function calls:

document.getElementById(etc)
as
document.getElementByID(etc)

Took me a little while to track it down. And it just seems sooooo pointless!

gwyn
Monday, July 28, 2003

I don't think the problem you have is with case-sensitivity as a general concept but rather with case-sensitivity in interpreted languages. 

If you did the same thing in C++, Java or C# it would be immediately obvious when the compiler complained about it.

Mister Fancypants
Monday, July 28, 2003

Well, if JavaScript was case-insensitive, then, when looking at JavaScript code, I would sometimes see:

DOCUMENT.GETELEMENTBYID(etc)

or

DoCUMENT.Getelementbyid(ETC)

and so on, and so forth.

This slows down reading the code.

I know - for 40 lines of code, it doesn't matter, but for reading thousands of lines of code and debugging for 10 hours straight every day for 5 days, trying to find a bug, belive me that it makes a hell of a difference.

Many software development practices (like strongly-typed languages, for example) are optimized for large projects development, and don't make a lot of sense for very small projects.


You say it's a pain in the *** to get the capitalization right.

Well, it isn't for languages that have a decent IDE (Visual Studio .NET, Borland Delphi, etc) which will show you a list of compilation errors, and double-clicking on any error will position exactly on that line of code.

Unfortunately, JavaScript doesn't have a decent IDE - that's why you find this a pain in the ***.

If JavaScript had a decent IDE, finding and fixing all the case problems would be trivial.

John K.
Monday, July 28, 2003

Iv eactually found mozilla to be verra good in terms of a javascript debugger.
<g> falls down a little if you are using ms specific code, but its prolly a good practice to avoid that as much as possible anyway..

FullNameRequired
Monday, July 28, 2003

I agree with Gwyn, and I think that some of the responses somewhat miss the point.

Sure, the compiler can find mismatches. That's not a reason to make a language case-sensitive; it's a way that a compiler can make case-sensitive languages a little bit less of a pain in the ass.

Sure, it would be annoying if your developers willfully misused case-insensitivity to violate your coding standards. That's not a reason to make a language case-sensitive, any more than the problem of illegal left turns can be solved by making cars that only turn right.

Why is it better to have a 63-character set than a 37-character set? Are you really in the habit of naming concurrently available variables Foo, foo, and FOo?

Zahid
Monday, July 28, 2003

Oracle Pl/SQL is case insensitive and compiled -- including keywords (wrt variables, compilation catches spelling differences only). In my experience, when keywords can be written in any case, it actually increases the effort required to read code. Literature has adopted certain conventions regarding capitalisation and these are enforced by publishers through editors and proofreaders; programming languages should enforce similar conventions regarding their syntactic constructs and they should be enforced by the compiler or interpreter. The rules may be jarring at first but they quickly become second nature. It becomes much harder for this to happen when you everything you look at presents a slightly different set of conventions.

And variables? I can see the points made regarding case in variables in interpreted environments. Fortunately, good programming practice helps out here: use less of 'em, keep the ones you do use closer together and structure the program to increase the local-ness of your variables.

Paul Sharples
Tuesday, July 29, 2003

cHair or Chair, Information or InFormation. Case can transmit meaning.

Mr Jack
Tuesday, July 29, 2003

> cHair or Chair, Information or InFormation. Case can transmit meaning.

Excellent point... Mr. Jack !!!

I can only whole heartedly support this. There's no denying this fact.

The One You Loved (TOYL)
Tuesday, July 29, 2003

Can't deny that case can hold meaning... but anyone who declares two variables inFormation and information in the same code would be a halfwit who's just going to cause grief for someone later on... So the chances are we're going to have one variable.. it may be 'inFormation'. But if I type in 'information' then (assuming our halfwit hasn't been around) there is no ambiguity as to what I mean.. so it should be just as acceptable.

I still don't buy it I'm afraid... I reckon if you want to use case to make it easier to read then go ahead but don't force it on everyone else! allow someone with a different view to type it in any case they like!

gwyn
Tuesday, July 29, 2003

Basically, if everybody in this world does believe & accept that case sensitivity is required in normal life for a language, what's wrong with having it in the programming language. Remember, code is read more than it's written. Though Information & inFormation is a convoluted example, it brings out a very good point.

How many times has it not being said that TYPING IN ALL CAPS is shouting. Same, I think holds true for a programming language.

Would I still be the loved one after all this rant :)

The One You Loved (TOYL)
Tuesday, July 29, 2003

Perhaps what is required is a language whereby variables are case-insensitive but used case-sensitively. This would prevent the use of differently-capitalized variables, but disallow differently-capitalized forms of the same variable. For example:

test=5 -- sets test to 5
TeST=5 -- 'test' exists
print tesT -- no such variable
print test -- displays 5

I definitely think consistent capitalization is important, and this scheme enforces that. However, I'm not so convinced about overloading by capitalization, which this scheme helpfully disallows.

Tom
Tuesday, July 29, 2003

"'test' exists" above is an error rather than a warning. It stops the program rather than assigning a value to the existing 'test'.

That's possibly obvious... thought I'd make sure it's clear though!

Tom
Tuesday, July 29, 2003

--"if everybody in this world does believe & accept that case sensitivity is required in normal life for a language"---

Err - they don't. Arabic has no capitals, and I don't think the Indian scripts do either. Chinese, of course, doesn't have an alphabet.

Stephen Jones
Tuesday, July 29, 2003

--"if everybody in this world does believe & accept that case sensitivity is required in normal life for a language"---

Yeah, but if you read a sentence that's incorrectly capitalized, you don't stop reading, hand the piece to the author, and say "You need to fix this before I can read any futher." Capitalization makes things easier to read, it doesn't make it possible to read when they once were impossible to read.

Jeremy

Jeremy
Tuesday, July 29, 2003

gwyn, the point isn't necessarily that you have inFormation and Information in the same code.  But if you have one of them, and captilatize for a specific meaning, if others come along and use a different capitalization it will just confuse the code.  To me capitalization provides a clear break between words, and I like having that enforced in my code.  Once in a while I have to fix a compile bug.  That's a very minor tradeoff for having consistantly capitalized variables when I am reading the code.  I very very rarely make capitalization mistakes that get through to the compiler stage, because I use a consistant convention.  The only time I slip up really is when using something like your example: "ID" which could go either way

Let me put it another way.  To counter the idea of case sensitivity you say "if you use it consistantly it is fine, so why should the compiler enforce it?"  To that I say: if you *intend* to use capitalization consistantly, you *should* have the compiler enforce it.  If you intend to use it consistantly, why would you want it to be legal to use it inconsistantly?

The only purpose of case insensitivity is inconsistant capitalization.  I don't think inconsistant capitalization is a good thing, so I prefer to have case sensitivity enforced by the compiler.

Mike McNertney
Tuesday, July 29, 2003

Also note that they've generally found that the lower case characters are easier to read.  So any upper-case usage should be minimized.

Modula-2 had the convention that all keywords were upper case.  Before syntax highlighting, I thought it made code more readable.  At this point, it probably doesn't matter.

Flamebait Sr.
Tuesday, July 29, 2003

To appreciate the true evils of case sensitivity you have to look at languages that combine case sensitivity with automatic instantiation.
A mistake, or did they do it on purpose? <g>

Just me (Sir to you)
Wednesday, July 30, 2003

Just me, on that I definitely agree, though I would argue the evil in that case lies with automatic instantiation, not case sensitivity.  After all, you have the same problem with misspellings (which in my experience are far more common)

Mike McNertney
Wednesday, July 30, 2003

Agreed.  I think the root of the OP's problem is that JavaScript is so loose.  A typo in a property name?  No problem, you meant to create a new property, right?  Because of the late binding, you can't tell a priori whether there will be a function called "getElementByID" when the code is run.

I'm in favor of case-sensitivity just on aesthetic grounds.  Why should the compiler treat 'A' and 'a' as the same character?  If you want to divide characters into equivalence sets, you really have to pick a locale in which to do it, and any choice is going to be essentially arbitrary.

Brian
Wednesday, July 30, 2003

*  Recent Topics

*  Fog Creek Home