Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: I know what I mean. Why don't you?

by Perl Mouse (Chaplain)
on Nov 22, 2005 at 11:12 UTC ( #510725=note: print w/ replies, xml ) Need Help??


in reply to I know what I mean. Why don't you?

If there is a line, or even a character that you can remove and still show the problem you have too much code.
Oh, yeah, sure. Golfing examples to show the unwanted behaviour!

I seriously advice to not follow this advice to the letter. Else, you'll remove from your example an easy 2 lines and 25 characters, and are pelted by remarks you should use 'strict' and 'warnings'! Or in an effort to remove characters, you reduce your example to use single letter variables (without using my!) - and instead of people spotting your error, you'll get a ton of replies to use better variable names.

Writing a short example is good - but don't golf. The example should be clear: it should only do what causes the problem, and it should be optimized for the reader. Which isn't the same as "write it in as little lines and characters as possible".

Perl --((8:>*


Comment on Re: I know what I mean. Why don't you?
Re^2: I know what I mean. Why don't you?
by herveus (Parson) on Nov 22, 2005 at 15:08 UTC
    Howdy!

    I think you take GrandFather too literally.

    If the offending code runs the same with or without strictures/warnings, then they aren't essential to the code fragment. One can speak to strictures/warnings in the exposition. The key is to remove all distractions from the problem at hand. It's not a golfing thing.

    I think the recommendations are sound, especially if taken intelligently instead of mechanically.

    yours,
    Michael
      If the offending code runs the same with or without strictures/warnings, then they aren't essential to the code fragment.
      I know that, you know that. Unfortunally, it happens over and over again that someone posts a code fragment with a problem, without 'strict' or 'warnings', and where it doesn't matter whether strict and warnings are on or not, and people will reply with pointless posts saying "I don't know what the problem is, but it's better to use strict and warnings".

      That's why I recommend to not golf. It's a pre-filter, it keeps out some of the useless replies.

      One can speak to strictures/warnings in the exposition.
      Sure, but then you might as well say it in the code.
      The key is to remove all distractions from the problem at hand.
      Exactly. Remove all distractions from the readers. That includes not emitting things that might cause replies of the form "perhaps you should try adding this".

      The absense of 'use strict' or the use of '$a' is a trigger for people to respond. Not to the problem, but to the distraction. Add characters - to eliminate distractions.

      Perl --((8:>*

        Judging the use of strict and warnings by the presence of the pragmata alone is stupid. No my in sight in a longer snippet that uses multiple variables is a much better indicator. Global filehandles and two-argument open are additional red flags. Basically, Iíve seen enough bad Perl code that I can tell it by the ďsmellĒ Iím not even sure all of the hints I pick up on are conscious.

        Though in general, unless the problem is obviously caused by a lack of strictures or would clearly have been pointed out by a warning, I only suggest that the poster may make his life easier by using them. And Iíve downvoted a fair number of nodes where someone just hawks about strictures and warnings when they obviously havenít even taken the time to read the posterís problem description and code. (I remember there was a thread recently where half a dozen people worthlessly posted about strict and warnings when the problem had absolutely nothing to do with that. Way to pollute the forum.)

        Makeshifts last the longest.

Re^2: I know what I mean. Why don't you?
by GrandFather (Cardinal) on Nov 22, 2005 at 20:09 UTC

    I agree with the golf comment and actually intended to make a comment along those lines, but forgot when it came to posting time. I'm sure anyone who actually follows the overall advise is unlikely to golf.


    DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-12-28 08:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (179 votes), past polls