In http://blog.simon-cozens.org/blosxom.cgi/2002/Sep/16#6255, Simon muses about programming without variables, and how everything looks nice and clean.
I've been there too. Except now I err on the side of using variables. Why? Because my personal debugging technique is to dump stuff to STDERR and examine it. I never ever ever use the perl debugger. So in order to be able to insert random debugging events here and there I generally have to use variables.
At least that's my excuse
Ugh. Bad Code! (Score:0, Troll)
Didn't Simon write a Beginner's Perl Book? Maybe I should distrust more and more of that book.
Re:Ugh. Bad Code! (Score:1, Flamebait)
Bzzt! That can't happen.
Notice the sub calledIsApplicable? That's tested before theProcesssub is called.But I suppose you couldn't pass up an excuse to trash a competing book.
Re:Ugh. Bad Code! (Score:2)
Geez.
Re:Ugh. Bad Code! (Score:2)
I have to agree with Randal, and I'm surprised that Simon would say "that can't happen" [perl.org].
--
xoa
Re:Ugh. Bad Code! (Score:2)
You must test the result of the match to see if it matched or not.
Re:Ugh. Bad Code! (Score:2)
--
xoa
Re:Ugh. Bad Code! (Score:1)
print SSH $1 if $foo =~
And, for those of you who might think Randal is being harsh, well, try pair programming with him. You guys have it easy. He holds Stonehenge instructors to an even higher, higher standard (and I thank him for that).
We all write bad code. It's how we act when someone points it out that matters.
Re:Ugh. Bad Code! (Score:2)
And, it's not so much that you have a "competing" book, except that I mentioned that because I hold anyone who teaches (or writes for) beginners on a regular basis to a higher standard.
Since you have made yourself one of those people, you get judged more critically by me. You have a higher responsibility to write more robust and cleaner code, and counter-examples will be pointed out in that context because it discredits your consistency of mission.
At l
Re:Ugh. Bad Code! (Score:2)
if (m/\w+\d+\w+/) {
s/(\d+)//;
print $1, "\n";
}
Would you put a double extra check on the s///?
Then, can't you reasonably say "it won't fail!"?
I think you can, sometimes.
(and as someone else pointed out, Simon could easily rewrite the code to do the check without an extra variable; I agree that the calls to open, print to and close SSH should have error checking though).
-- ask bjoern hansen [askbjoernhansen.com], !try; do();
Re:Ugh. Bad Code! (Score:1)
Not right now. But after three changes to the first regexp, and the second regexp being pushed down a few lines (so it´s not in proximity to the first), it´s not that obvious anymore, right?
It´s far fetched (and maybe not worth fuzzing about), but not _that_ far fetched