When Strict isn't strict Enough

by chromatic

One of the weirdest portability problems I've ever encountered is dealing with platforms with case-insensitive filesystems. Files I expected to be there mysteriously weren't. Files I didn't expect to be there mysteriously were.

Case-sensitivity in programming languages confuses novices too, especially on insensitive platforms. The capitalization of certain words matters within the language where it doesn't on the filesystem.

Usually that only leads to mysterious error messages. Though a novice may not know enough about the language to decipher the message yet, there's no silent failure. Unfortunately, there's a case in Perl where there are silent failures: pragmata.


Vance Dubberly
2007-04-17 14:25:44
Plain and simple, the interpreter should be checking the package name when it imports the Module. In the meantime a variant of Abigail's solution should be put into the strict.pm and any other module. Only the message should be very abusive and make the idiot who typed "use Strict" cry. :) There are legitimate mistakes and there are retarded mistakes, programmers should always assume case sensitivity, so this mistake is retarded.
2007-04-17 14:38:45
@Vance, there are legitimate reasons to have the package name not match the file name... at least in any way that static analysis can detect.

I agree that assuming case insensitivity is a mistake, but I'm not sure how a novice programmer can intuit that case matters without guidance (and abusive error messages aren't the way to go).

Jeff Kirkland
2007-04-18 05:35:51
I have to agree with chromatic in that the abusive error messages would cause more grief than be of help. This is another case for having each and every Perl book start off with he same note: always "use strict" and "use warnings" (or the -w switch).

A number of us are Unix geeks, but there are unfortunately an increasing number of novice coders out there who are and have always been on a case-insensitive system, such as Windows. I remember when I first started in Unix (some 10 years ago) and it took me a little bit to get used to the case sensitivity, but having to deal with it on a daily basis made it come quicker to me.
All in all, using warnings is probably the best solution, but with an error message that makes sense, even for a novice. We want to encourage people to code in Perl, not discourage them. :-)

2007-04-18 11:28:03
If we are talking about *just* solving the "use Strict" vs "use strict" then I agree mostly with Vance. If you try to solve it beyond that case (no pun intended) then you have to think a little harder about the whole thing.
Vance Dubberly
2007-04-19 11:25:46
I was of course being a little silly to illustrate a point. Hand holding novices doesn't do anybody any good. It creates the expectation in them that they can screw up and the language will figure out what they meant. While the language can figure it out, it comes at a cost. Namely more bugs, and more clock ticks.
2007-06-19 16:17:59
Does anyone really have a problem with this? When I learned Perl, the book and all of its examples had "use strict;", so why would anyone even think of capitalizing it in the first place.

More importantly though, it is probably a bad idea to have any identifiers (data, subroutines, module names) that vary only in case. Even an experience programmer for whom case-sensitivity is natural can forget the right case and type an identifier wrong. And it is confusing and hard to "speak out."

This probably all belongs in some 'lint' like pre-processor.