Re: Is it me?
by jacques (Priest) on Sep 14, 2005 at 18:04 UTC
|
Using warnings and strict is a good, smart practice. But not using them is not always a "mistake". Note, for example, that CGI.pm does not use strict.
In advice forums, people who *constantly* tell others to use strict/warnings often give me the impression that they know little about Perl or else they would have something more to say. ;-) | [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
Re: Is it me?
by derby (Abbot) on Sep 14, 2005 at 18:12 UTC
|
I'm having a hazy re-collection that this issue has come up before. I believe the reasoning is that most error checking and such is left out of magazines in the interest of conserving space for the core idea of the article.
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] [d/l] |
|
In such cases it is generally a good idea to say explicitly that error checking has been omited for the sake of clarity.
The danger of not including the checking and of not making it clear that there should be error checking, is that such code becomes the example that people follow.
Perl is Huffman encoded by design.
| [reply] [Watch: Dir/Any] |
Re: Is it me?
by monarch (Priest) on Sep 15, 2005 at 07:55 UTC
|
Was every school teacher that you had an authority on the subject they were teaching?
Was every presentation you ever went to one of quality?
I only ask, because I view articles much in the same way as anything in life - it is a person's opinion; they are not necessarily a distinguished individual in that field, they are merely presenting something for fame, credit, or money.
I've learnt a lot from magazines, particularly in my teenage years when I was thirsty to learn anything I could about programming and computers; these days I rarely, if ever, buy magazines - there's plenty of information to be had from open source code, online manuals, and news articles (and PerlMonks of course!).
As some others have commented, I don't believe it is necessarily a crime to present bad quality source; an individual who is interested enough will learn from experience why certain coding styles (such as use strict) are a good idea. I know I've learnt a lot of programming lessons the hard way. | [reply] [Watch: Dir/Any] [d/l] |
Re: Is it me?
by chas (Priest) on Sep 14, 2005 at 18:22 UTC
|
If a script is developed (using strict and warnings), and is
considered complete and working as expected, is there a reason to leave the use strict (or warnings) turned on? I suppose it doesn't hurt and could be useful for someone else who might edit the script, but other than the latter possibility, I'm really not sure.
chas | [reply] [Watch: Dir/Any] [d/l] |
|
Most of the time, you don't get 100% coverage when you test things. That means there might still be a situation where something unexpected goes wrong, and a useful warning helps you track down what it was.
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
|
Well, in that case, you would want to keep them in there since programs are almost never "complete" including your own.
| [reply] [Watch: Dir/Any] |
|
...is there a reason to leave the use strict (or warnings) turned on?
Flip that around -- why would you turn it off? If you can't justify turning it off, then it should stay on.
Brainstorming here, possible reasons to turn strict and warnings off:
Speed: Not performing all of those compile- and run-time checks is bound to improve speed. Only benchmarking will tell if it's a real gain or not.
Confusing users with warning messages: If code spits out warning messages, it should be for a good reason, and it should be meaningful to the user. For example, if the file doesn't exist, that's something the user should understand. If the Beeblebrox is in Ratzafratza, then maybe the message should be changed to something like:
The Beeblebrox is in Ratzafratza. This should never happen. Please contact the maintainer of this script.
If your code sometimes innocuously spits out warnings that you know don't make any difference, for maintenance reasons you are better off to use no warnings around the offending statement, rather than turn off warnings everywhere.
Laziness: OK, I'm not sure how this would apply.
Hubris: Umm, I'm really not sure how this would apply.
Any others?
-QM
--
Quantum Mechanics: The dreams stuff is made of
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
Leave it in. People forget to put it in, turn it on, flip the switch and diddle the nob. It doesn't really impact performance beyond negligible.
Lord knows how many time I've forgotten nuances and rules of things to check when things break. When things aren't working right, make it obvious. Use strict.
(paid for by the strict.pm party. strict.pm for prez, 2008!)
----
Give me strength for today..
I will not talk it away..
Just for a moment..
It will burn through the clouds..
and shine down on me.
| [reply] [Watch: Dir/Any] |
Re: Is it me?
by samizdat (Vicar) on Sep 15, 2005 at 13:42 UTC
|
In my mind, code in magazines and on the Net is always 'buyer beware'. Code in shrink wrap is no better, but at least with open source, you have a choice. As a programmer, you have an *informed* choice. Certainly the 'use x & y' mantra is oft enough repeated around here that anybody beyond the Rabbit-book level is educated enough to be aware of what those pragmas can do for you, if not necessarily what they can do _to_ you.
I've written for print mags and online before, and I always distill my code down to the essence because if I don't, the editor will take a meataxe to it. The point made upthread about explaining the omission is a great one; I'll add a para to my future texts about that because I'm always out to educate future proggies to give them a chance to become better than me... :D | [reply] [Watch: Dir/Any] |