I suspect your idea of the logical idea to introduce concepts is
being influenced by the history of Perl
It isn't.
You are letting your knowledge the evolutionary history of Perl bias
you towards seeing "use strict" as adding features.
I am not.
I see that you have promoted your suspicion from the first paragraph
to the status of a fact. In the future, you might want to be careful
that you don't forget which things are factually true and which are
the ones that you invented a few minutes before. I think it makes you
look foolish.
It is not. For someone looking at Perl5 afresh it is more
appropriate to see it as switching off rarely useful features
(implicit quoting, implicit declaration of unqualified package
variables, symbolic references) that are enabled by default for
largely historical resons.
I think this is a revisionist point of view. Yes, a lot of the
programs that people wrote in Perl historically are short scripts that
don't need 'strict'. But so are a lot of the programs that people
wrote yesterday afternoon.
Those features were originally enabled by default because they were
useful and convenient. Today, that cannot be changed, for
compatibility reasons. But even if they could be disabled by default,
it is not clear that would be the best thing to do, because they are
still useful and convenient.
In a 3-day class probably would never mention in detail the
consequences of omitting "use strict".
I have a number of objections to that. Some are practical, and some
are ethical.
Here is a practical objection. On day 4 you have gone home. Your
student is writing a program, and it dies in the middle. So they
spend a couple of hours puzzling over what might be wrong, and perhaps
changing stuff around at random because that's what a lot of
programmers do when they encounter an error message they don't
understand. Then they send mail to the guy in the next cubicle, who
was also in your class, saying
Hey, my program doesn't work; it says:
Can't use string ("ARRAY(0x8113f74)") as an ARRAY ref
while "strict refs" in use
What's wrong?
So you taught them to "always use strict", but it didn't do your
student very much good. They have a real error, and the program died,
and now they don't know what to do because you never showed them the
error message or explained what it was about.
Now what happens next? One thing that often happens in your scenario
is that the guy in the next cubicle writes back:
I got that message too, but getting rid of the "use strict"
made it go away.
which of course is a disaster. And the students are not equipped to
understand why that would be a disaster, or to understand the kinds of
problems that arise as a result, because you never mentioned in detail
the consequences of omitting "use strict".
It would be better if the guy in the next cubicle could say
I think that message means that you used a string as if it was
a reference. That ARRAY(0x8113f74) thing looks the way a
reference does when you print it out. Maybe your reference
turned into a string somehow?
and then maybe the first guy says
That sounded awfully familiar, so I looked in the notes we got
in the class and found it on page 142. Thanks!
This might happen in my class, but it can't happen in yours, because
you never mentioned in detail the consequences of omitting "use
strict".
You started out the post by suggesting that I was motivated by an
obsolete historical view of the development of Perl. But that's not
it. I'm motivated by a philosophy that says, in part:
* Programming can't be done by rote.
* More understanding is always better; less is always worse.
* Don't leave out anything important. But if something is
important, you should be able to explain why it is important.
'strict' is important, which is why I put it in, and why I want to
explain *why* it is important. ("Here's what could happen if you
don't put it in.") I don't think that it works to try to put it in
without including the reason why, and I think it's disrespectful to
the students to try to do that anyway. They're adults, they're
professionals, and we should suppose they can be trusted to make the
right professional decisions when provided with the facts.
That's not my theory. Teaching them to follow good practice is
separate. Given that we're doing that anyhow "use strict; use
warnings;" just makes life easier for them.
I think this may be the basis of our disagreement. I think you are
completely wrong here. Good programming practice does not exist in a
vacuum. It was not handed down by God from Mount Sinai. Good
programming practice is precisely the set of practices that make life
easier for programmers. How can making life easier be separate from
following good practice?
There is no such thing as a good programming practice that does not
make life easier, or a bad programming practice that does not make
life harder. If something makes life easier, it is good programming
practice; if it makes life more difficult, it is bad programming
practice. How could it be otherwise?
It is good programming practice for functions to use only lexical
variables. Why? Not because all the books say so. It is because
functions that use global variables are hard to maintain and reuse,
and make life more difficult. Life is easier when functions use only
lexical variables. And that is *why* all the books say so.
It is almost always good programming practice to have 'strict refs'
declarations active in your Perl program. Why? Not because all the
books say so. Not even because Brian McCauley says so. It is because
'strict refs' helps catch certain kinds of run-time errors that would
otherwise make life difficult. Life is easier when 'strict refs' is
on. And that is *why* all the books say so and why you say so too.
Sometimes, in peculiar circumstances, life is easier when a function
uses a global variable for something or other. In these peculiar
circumstances, using the global variable is good programming practice.
Sometimes, in peculiar circumstances, life is easier when 'strict
refs' is off. In these peculiar circumstances, using turning off
'strict refs' is good programming practice.
Many times I have seen people following completely blockheaded
programming practices that are promulgated because they were
supposedly 'good programming practices'. Many real programs are
tremendously complicated because some ass got stuck on some theory of
'good programming practice' and forgot that 'good programming
practice' should be grounded in the reality of what makes real
programs easier to write and maintain.
One common pattern, for example, is the 100-line script whose first 40
lines are
my (%index_hash,
$dev_type,
$ref_label
... (35 more omitted)
$read_dir_def,
$write_dir_def);
So you ask "Why does your program start off with 40 lines of
declarations?" and the answer is "Because otherwise it doesn't work
under 'strict'." This is a fine answer as long as there is more to
it, like "...and I decided that the cost of maintaining the
declaration was worth paying for the benefit of getting spelling
errors diagnosed in variable names."
But if the rest of the answer is "I don't know but someone told me
that everyone should always use strict all the time," it's a lousy
answer. That is exactly cargo-cult programming. There are two
problems with cargo-cult programming. The two problems support each
other.
The first problem is that cargo-cult programming promulgates
ineffective or destructive programming practices by elevating them to
that status of 'good programming practice'. Then people use the bad
practices just because they are labeled 'good'. Even when a practice
are generally good, there is usually some circumstance in which it
should be avoided, because hardly any practice is always good. But
cargo-cult programming promulgates the use of the 'good' practices
even in circumstances for which they are unsuitable.
The second problem of cargo-cult programming is that the labeling
process discourages critical thought about the meaning of the labels.
People are encouraged to adhere to certain practices because they are
'good', and to avoid others because they are 'bad'. The goodness and
badness have become divorced from anything in reality; people
habitually select practices based on the labels, and not based on
reality. They forget that there *is* an underlying reality, as the
labels become the end goal, rather than a means to achieve an end goal
of making life easier. As people lose track of the end goal of making
life easier, life becomes more difficult. Programmers adopt bad
practices because some yahoo has labeled them 'good' and because they
have lost the ability to look at the end result of the practices and
judge for themselves.
Telling people to do stuff that they don't understand often appears to
make things easier for them, but it only does so in the very short
run.
In the medium term, you are just setting up a bigger, nastier
programming surprise for them, when they get the error message (that
you told them to enable) and they don't understand what it means or
how to diagnose or repair the problem that it represents.
In the long term, you are failing in your duty as a teacher, by
encouraging ineffective patterns of thought. Instead of encouraging
"this is what 'use strict' does and this is when and why I would want
to use it", you are encouraging "Brian says to do this, so I will."
In the short term, that might work, but it will not help the student
become a better programmer.
When I say "use MODULE" I only need to know what it does upto some
level. The whole point about modularisation is that I don't need a
full understanding of the internals.
You are confused about what I said. (Or else you are twisting my
words, but I'll give you the benefit of the doubt.) I did not say
"when you don't know how it works". I said "what you don't know WHAT
IT DOES".
We are not talking about the internals here. I am not advocating that
people should understand that behavior of the $^H variable before
using 'strict'. I am advocating that that should know WHAT IT DOES.
I would tell them the truth:
But not the whole truth. You'll tell them the policy, but not the
technical reality that led to the policy. But that's what I find
disrespectful. These profesionals are supposed to be able to
understand the technical aspects of the policy, but you're not giving
them enough information to do that. If you think that the
programmer's job is to unquestioningly implement the policies laid
down by his supervisor, it's enough. But I don't think that, and I
think it's unethical to promulgate that idea.
Once I've given them enough information for them to understand why
omitting "use strict" should be considered a positive action that very
same argument "putting stuff into your program when you don't know
what it does is the very worst of all possible programming practices"
now applies to leaving out strict.
That is a phenomenal display of doubletalk. ("Ignorance is Strength!")
Regardless of the merits of the rest of your post, I feel sorry for
you that you could write this last paragraph without realizing what a
load of bullshit it is.