in reply to Re: Doing "it" only once
in thread Doing "it" only once
Now, BrowserUK informed us here that this kind of code self-modification was very common in early languages, but also regarded as a horror, which is one of the reasons that led to structured programming and later to OO programming, etc. OTOH it has become common again, in FP languages, as a compiler optimization.
But then it's hard to think that in such a dynamic and multi-paradigmatic language like Perl, be it 5 or 6, something exactly along these lines could be done. So my question, in the context of Perl6, regarded the possibility to do so by means of some syntactic sugar visually distinctive enough to avoid an unintentional use of it and to make clear what that the one using it wants and at the same time cheap enough, type-wise, to make it preferable over any of the already proposed alternatives.
Now, wrt you code above:
it obviously looks nice enough and it makes clear why you're doing so. But it's still nearly double the code that one conceptually could want. Not only: if print were really a longer portion of code, you may {want,need} to refactor it into a sub, with the added overhead of a sub call (and here we're being -for once- really paranoid 'bout efficiency and micro-optimizations), which would not have been necessary at all if we had that kind of syntactic sugar...while ( <FH> ) { last if $_ eq 'foo'; # Where foo can only appear once in the file print; } while ( <FH> ) { print; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Doing "it" only once
by Anonymous Monk on Sep 22, 2005 at 10:57 UTC | |
by blazar (Canon) on Sep 22, 2005 at 11:00 UTC |