Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: When do you include the usual use pragmas in your example code?

by davido (Archbishop)
on Aug 03, 2013 at 16:45 UTC ( #1047723=note: print w/replies, xml ) Need Help??


in reply to When do you include the usual use pragmas in your example code?

I used to show use strict; and use warnings; at the top of almost all of my example code. Then I read and thought a lot about MJD's "Twelve Views, #8: Why I Hate strict". From that article, there's this:

People come into the Usenet comp.lang.perl.misc group with some question, which they demonstrate with a four-line example program, and other folks there jump on them: ``Why didn't you use strict?'' Well, because it's a four-line example program I concocted as an example in my Usenet article---duh!

After digesting that article I kind of shifted my thinking a bit. Now, often I'll post only the code necessary to demonstrate my point. Usually it's stand-alone and runnable. Occasionally just a snippet. I will use lexical variables almost always, but may not explicitly demonstrate "strict" and "warnings" if they're not part of the solution, or part of the point I'm trying to make.

If I do advocate for the use of strictures and warnings, I'll also try to point out which aspect of "strict" would have caught some problem in the user's code, or which warning might have been raised had warnings been enabled. I feel this is far more helpful than simply carping "You should use strict and warnings." Another quote from the article:

Any time you hear anyone saying ``you should be using strict,'' you can be fairly sure they're not thinking about what they're saying, because strict has these three completely unrelated effects. A more thoughtful remark is ``you should be using strict 'vars''' (or whatever). As an exercise in preventing strict zombie-ism, ask yourself ``Which of the three strict effects do I find most useful? Which do I find least useful?''


Dave

Replies are listed 'Best First'.
Re^2: When do you include the usual use pragmas in your example code?
by educated_foo (Vicar) on Nov 07, 2013 at 01:53 UTC
    Too few people have read that MJD piece, much less understood it. Seeing it again now just makes me sad about what Perl and, much more, its community have become.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1047723]
help
Chatterbox?
[erix]: then you might as well send that patch to the DBIC guys :)
[Corion]: erix: Yeah, I just found that it has no documentation at all on how to circumvent/ eliminate "1+n SELECTs" by building a local hash... I guess I have to make ->has_many do the hash lookup instead of doing the SQL query. But as the problem ...
[Corion]: ... has only manifested itself so far through the puzzled questions of other bystanders, I won't go deeper at this time. But the DBIx::Class documentation could well do with a document on how to make "it" (that is, ORMs in general) faster ;)
[Corion]: I find that DBIx::Class, like most ORMs makes things easy until they become performance critical and then makes it horribly hard to change things because the design is highly inflexible if you don't already know about the problems of 1+n :-/
[choroba]: that's why I don't like similar libraries. They pretend you don't have to learn SQL, but in the end, you have to learn how SQL plus to overcome their own limitations
[Corion]: "Just write the proper SQL beforehand" is of course the appropriate solution, but if you did that, you wouldn't/couldn't use DBIx::Class either. At least not in an obvious (to me) way.
choroba scratches a "how"
[Corion]: choroba: Exactly... But maybe that's just because I'm old and grumpy ;)
[Corion]: But maybe that could also be a nice talk, how to restructure your DBIx::Class-based app to remove 1+n-style query patterns
[Corion]: In theory, that should be easy because you should have the "where" clause from part 1 of the patterns and then do the corresponding single select using that where clause to select all rows in one go for the n other parts.

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2017-09-25 11:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (279 votes). Check out past polls.

    Notices?