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

Re^2: Best practice or cargo cult?

by dsheroh (Parson)
on Jun 20, 2006 at 15:21 UTC ( #556430=note: print w/ replies, xml ) Need Help??


in reply to Re: Best practice or cargo cult?
in thread Best practice or cargo cult?

I suppose I can agree that adopting someone else's programming style is a form of voluntary cargo cult programming, but I do not believe that assembling your own style by considering various options and choosing those which you consider to be the best for you would be CC (even if the end result happens to be identical to someone else's style).

As to the merits of always using the switches, they all come at the expense of changing the regex semantics to be different from the standard/default semantics. I do not consider this to be "little to no expense". When there are defined standards and well-known semantics, I find it much better to stick with them where possible and only deviate when needed rather than making deviation the default.


Comment on Re^2: Best practice or cargo cult?
Re^3: Best practice or cargo cult?
by ikegami (Pope) on Jun 20, 2006 at 16:24 UTC

    but I do not believe that assembling your own style by considering various options and choosing those which you consider to be the best for you would be CC

    Definitely. That's why I said "the real question is whether the style was created with thought".

    they all come at the expense of changing the regex semantics to be different from the standard/default semantics.

    "standard/default"? They're not the same. Personally, I use the modifiers only when needed. I need s more often than not, so my standard usage is with s, which is not the default. From what I see, when people don't use s on a regexp that uses ., it rarely would cause no harm to use s, and it's often an error not to use s.

    When there are defined standards and well-known semantics, I find it much better to stick with them where possible and only deviate when needed rather than making deviation the default.

    When there are defined standards and well-known semantics, I'd love to here about them. There's obviously differences in the standard usage of the modifiers (default vs Damian's, for example), and the semantics are far from constant.

      That's why I said "the real question is whether the style was created with thought"

      In that case, I misunderstood whose thought you were referring to and had taken you mean the originator of the coding style rather than the one using it.

      When there are defined standards and well-known semantics, I'd love to here about them.

      The defined standard is documented in perlre and the well-known default semantics are those which are used in the absence of any modifiers. There are certainly times when the default semantics need to be changed, thus the standard includes modifiers such as /s to alter them, but this does not change my original point that it is generally better to stick with the default (no modifiers) semantics where possible and only invoke modified semantics when there is a need to do so.

        I'm not sure what you mean by standard, because I see nothing about the standard usage of x, s and m in perlre.

        You changed from "well-known semantics" to "well-known default semantics". My point is that they're not the same. The semantics of ., ^ and $ are not well-known, since they are context-sensitive. The defaults are overriden regularly — more often than not, in my experience — so relying on the default semantics is no good. If you wanted well known semantics in your code, without loss of functionality, it would have to be done through the enforcement of xms.

        The problem is that the world on which xms can be enforced is limited, so the "well-known semantics" would only be well-known within that world. However, that's more consistency in semantics than one would enjoy otherwise.

      and it's often an error not to use s.

      It is, but never forget that it can also be a bad to use /s with .. Matching \n just like any other character is not always natural; this default for . is NOT arbitrary or accidentally introduced. It actually makes sense a lot of the time, and in fact, I encounter more line based data than data that's differently delimited.

        It actually makes sense a lot of the time

        Do you have any examples? I can't think of anything realistic.

        • When dealing with line data, I'd be in a while (<FILE>) { chomp; ... } loops, so my data would never have any \n in it.

        • When dealing with data where \n is considered whitespace, it's no more special than a space, so I'd use the s modifier.

        • When dealing with multiline records, I tend to treat the data as line data — especially if I can use the flip-flop (..) operator — so my data would never have any \n in it. This is probably where I'd be least likely to use the s modifier.

        • When dealing with binary data, \n is not special, so I'd use the s modifier.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2014-12-22 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (112 votes), past polls