Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: P2P Golf: MoleSter

by blazar (Canon)
on Dec 20, 2004 at 14:51 UTC ( [id://416196]=note: print w/replies, xml ) Need Help??


in reply to Re^2: P2P Golf: MoleSter
in thread P2P Golf: MoleSter

You actually cannot use pop instead of shift in the first line unless you rearrange the argument list order. The same goes for most of the subroutines.
WOW! Thank you so much for having pointed out so: I would have never imagined myself...

What I wanted to stress is that even for a mediocre golfer like me at a first glance the code, despite some evident conciseness still was largely suboptimal from this point of view for just applying a standard golfing technique like using pop() instead of shift() (and reversing the order of the arguments - pointing out the obvious, just to keep you satisfied) wherever applicable would have saved quite a lot charachters.

But then it's well known that experienced golfers use any sort of more refined tricks. For example I can remember one case in which there were four arguments to take from the cmd line and it was practically mandatory to assign these to variables so they used something along the lines of this (since the golf rules did not require strictures or warnings): $$_=pop for a..d;

You cannot use open F,pop; because there are 3 args coming in, not 2.
Huh?!?
The &x() syntax is actually the golfed version in several places, particularly &$3($2,$4,$');. Now, in others, it can be removed. But, I sincerely doubt it has anything to do with the author's skills as a programmer. Personally, I'm impressed with a P2P client in under 1000 characters.
Well, indeed if we're talking symrefs then you're right. It may also save some chars in other situations. Generally with modern enough perls the &-syntax does not do what one expects, and as a matter of a fact unless there's a really good reason to adopt it (and indeed in golfing and obfuscation games there may be some well beyond "regular" ones), code that abuses it reveals that he/she who wrote it is still programming Perl4. I'm not sure if this is the case with this particular program, but this is the impression I got at a quick glance.

Replies are listed 'Best First'.
Re^4: P2P Golf: MoleSter
by dragonchild (Archbishop) on Dec 20, 2004 at 15:06 UTC
    >> You cannot use open F,pop; because there are 3 args coming in, not 2.

    Huh?!?

    The function in question is

    sub g{ open(F,'<',$_[1])&&&s($_[0],$a,"e$_[1]",<F>); close F }

    On first glance, it looks like you can replace $_[1] with pop for a 2-character savings. However, look at where g() is called - &$3($2,$4,$'). There are three scalars in @_, not two. The fact that g() only uses two is irrelevant.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      >> You cannot use open F,pop; because there are 3 args coming in, not 2.

      Huh?!?

      The function in question is

      sub g{ open(F,'<',$_[1])&&&s($_[0],$a,"e$_[1]",<F>); close F }

      On first glance, it looks like you can replace $_1 with pop for a 2-character savings. However, look at where g() is called - &$3($2,$4,$'). There are three scalars in @_, not two. The fact that g() only uses two is irrelevant.

      Again, in my OP it was implicit that one should change (if possible/convenient) the way subs are actually called... it was meant to be a very generic cmt.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2024-04-19 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found