Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: Breaking output lines into N-element chunks

by Juerd (Abbot)
on Apr 11, 2002 at 21:06 UTC ( [id://158429]=note: print w/replies, xml ) Need Help??


in reply to Re: Breaking output lines into N-element chunks
in thread Breaking output lines into N-element chunks

sub LIMIT { 4 }

What is the point in defining LIMIT when you don't use it? :) Oh, and adding an empty prototype makes your LIMIT inlineable, which will increase speed (okay, in scripts like these you'll hardly notice the difference, but hey, it's only two extra characters (or three if you want whitespace, like I do)).

sub LIMIT () { 4 }
No, this is not a bad use of prototypes. Actually, this is a very good feature which allows for constants to be used (the constant pragma does the same)
use constant LIMIT => 4;
I don't like that syntax, though, so I stick to subs with empty prototypes.

Yes, I reinvent wheels.

Replies are listed 'Best First'.
Re^3: Breaking output lines into N-element chunks
by particle (Vicar) on Apr 11, 2002 at 23:08 UTC
    What is the point in defining LIMIT when you don't use it? :)

    oops! i hastily added the LIMIT sub between preview and submit, and deleted both the empty prototype, and the call in the splice. thanks for catching my bug and optimizing my code!

    ~Particle ;Þ

Re: Re: Re: Breaking output lines into N-element chunks
by demerphq (Chancellor) on Apr 12, 2002 at 13:43 UTC
    I don't like that syntax, though, so I stick to subs with empty prototypes

    While I agree with you that the constant syntax is not that nice I believe that in the long run you are probably doing yourself a disservice with not using it.

    The advantage of using constant is that it clearly announces to a maintainence coder or equiv what is going on. They would need to be fairly experienced to know what the purpose is of such an unusual looking sub, and if they were like me might even remove the prototype on principle.

    A second point is that by using the module you are implicitly documenting what you are doing. Not just on a literal programming level but also simply on the level that the maintainence coder can then review constant.pm documentation and see that there _are_ quirks with this technique. Now these quirks apply whether you do it by hand or by using contant.pm, the only difference being that if you do all your constants by hand its up to YOU to document these quirks to future programmers.

    Being a lazy type, especially when it comes to documentation I would use constant.pm for this reason alone...

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.

      unusual looking sub

      If subs with empty prototypes and only a return value are unsual looking to you, better read some Perl :) It's one of the most occuring idioms, very useable, fast and reasonably clear.

      Besides, ALLCAPS names often indicate constants too, and if you don't recognise it as a constant, ANY coder (not just Perl coders) should be able to deduct its meaning within a matter of seconds.

      its up to YOU to document these quirks to future programmers.

      Anyone who doesn't see it's a constant (single return value, empty prototype, name in ALLCAPS, defined before any other sub and often found in @EXPORT), should not be maintaining my code. I like my code to be maintained by programmers, not HTML monkeys. If someone hires a non-coder to do code maintenance, that's not my problem :). And when it does become my problem, I get paid for it ;).

      No offense meant.

      Yes, I reinvent wheels.
      

        better read some Perl :)

        Juerd thats a big load of hoo-hoo and you know it.

        most occuring idioms,

        Do a grep of site/lib and you'll see just how common that idiom is. I think youll be suprised.

        Anyone who doesn't see it's a constant (single return value, empty prototype, name in ALLCAPS, defined before any other sub and often found in @EXPORT), should not be maintaining my code.

        The fact is that these "constants" (they arent really so lets be careful with that term) will not behave as expected in about 5% of situations. And you've just demonstrated my point. You didnt even realize what quirks I meant. So if you didn't why the hell would the maintainence programmer? Oh and the other point is that you will almost never have the choice of who maintains your code.

        If someone hires a non-coder to do code maintenance, that's not my problem :)

        Actually, 99% of the time it will be your problem. It will be your problem when your boss fires you for writing unmaintainable code, itll be your problem when your boss tells you to drop the sexy new project you are working on to do maintainence on old code that has been written poorly, it will be your problem when you stop getting work because you have a reputation of writing unmaintainable code.

        Unmaintable code is bad code. Its your job as a developer to anticipate _everything_ including the skill levels of those that come after you. Which you should expect to be lower than your own.

        Frankly juerd im a little disappointed about your reply and I think that if you sit back and reconsider so will you.

        Yves / DeMerphq
        ---
        Writing a good benchmark isnt as easy as it might look.

      while i agree with you that using the constant module (pragma?) is better for maintainence, i don't like the syntax at all. i'd prefer syntax like

      use MyConstant; MyConstant LIMIT { 4 };
      which would create a sub named LIMIT with an empty prototype. unfortunately, i don't know how to do this. i think a well-written module with this functionality would satisfy both syntax and maintainence issues.

      can someone point me in the right direction towards writing a module like this?

      ~Particle ;Þ

        Im not really sure. I have a feeling that you'd need something like a filter module.

        To be honest considering the tradeoffs I would just stick with contant. The syntax isnt _that_ bad..

        Yves / DeMerphq
        ---
        Writing a good benchmark isnt as easy as it might look.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2024-04-26 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found