Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Dumb Mistakes

by Chady (Priest)
on Oct 03, 2001 at 12:33 UTC ( #116380=perlmeditation: print w/ replies, xml ) Need Help??

my first programming encounter was with QBasic. Until I found out about perl, I had no programming skill or style at all, and while discovering the new ways to program, it was pretty interesting.

As soon as I knew about a function I tried to use it whenever possible, and a while ago it hit me; I had hacked quite an amount of form to email scripts for the company I work for, and while looking at one, I saw a terrible line of code:

my $address = $query->param('address') ? $query->param('address') : 'N +o address specified';

And that's only one param, imagine what the script looks like. It seems that I got too excited with the CONDITION ? VALUE_IF_TRUE : VALUE_IF_FALSE form that I started using it everywhere without looking at how simple it can be to use ||

Is anyone interested in sharing similar dumb mistakes? I'd like to know that I'm not the only one, maybe I'll feel better ;)


He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

Chady | http://chady.net/

Comment on Dumb Mistakes
Select or Download Code
Re: Dumb Mistakes
by MZSanford (Curate) on Oct 03, 2001 at 14:51 UTC
    I have seen some of my own early code using things like the following :
    ## stats ? -s ? naaaaa $size = `ls -l $FILE | awk '{ print $5 }'`; ## what's opendir() ? @files = `ls $DIR`; ## And, this is not mine, but i saw it # in some code at work the other day # where all logging was like this ... `echo "Process starting" >> $LOGFILE`;

    "They shall not overcome. Whoever told them that the truth shall set them free was obviously and grossly unfamiliar with federal law."
        -- John Ashcroft
Re: Dumb Mistakes
by demerphq (Chancellor) on Oct 03, 2001 at 15:53 UTC
    Well, i'm not so sure this is a dumb thing to do. For one it allows more flexibility than ||, because you can add the word 'defined' to the beginning which is often the best way to handle defaults. Consider
    my $value=0; my $string1=$value || "No value assigned" my $string2=$value ? $value : "No value assigned" my $string3=defined $value ? $value : "No value assigned"
    Only $string3 will have the correct value.

    What did I do as a mistake in my early stages? I underutilized modifiers leading to hard to read code, I had a lot of $var->{key}->{key}->{key}->{key} kind of stuff. Using temporary variables cleaned that up as well as learning that the form $var->{key}{key} is legit.

    Yves
    --
    You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM)

      learning that the form $var->{key}{key} is legit.

      It is legit, but I wonder how many monks use it. I personally like the -> and I always write $var->{foo}->{bar}. I find it aesthetically pleasant as well as a good reminder of the fact that $var->{foo} is a reference and not a hash.

      I guess I am not the only one, given the overwhelmingly negative reaction to the replacement of the arrow by a dot in Perl 6 (which was probably Larry's goal now that I think of it, just to drive the point that Perl 6 is different from Perl 5 and that nothing is sacred).

        I'd like to know the rationale behind the decision before completely rejecting the change (see #43 thanks tilly) but it does seem to be an odd thing to change. Also if I've heard correctly the concat operator will be a underbar? Now that just reminds me of the broken VB run on statement syntax, which IMO is a bad recommendation. If you see what I mean.

        :-) Yves
        --
        You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM)

Re: Dumb Mistakes
by premchai21 (Curate) on Oct 04, 2001 at 04:31 UTC

    In my earliest baby Perl, I:

    • Didn't know hashes existed and used masses of scalars instead.
    • Didn't know chomp, split, etc. existed and used masses of regexen (which occasionally, but not always were appropriate) instead.
    • Didn't use any subs.
    • Didn't use strict or warnings. Didn't know that they existed.

    Looking back, it's some of the worst code I've ever seen. Now I've made some improvement, but am still learning. If only I had found the Monastery sooner...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://116380]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2014-08-30 18:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls