Where 'COUNT' is the number of times the loop iterates ... int i = 0, COUNT = ##;
bar = baz();
while(i < COUNT) {
bar = bar.foo();
++i;
}
Now, was that so hard? The type of bar, if that's even applicable, is left as a requirement for the user to define.
>>4
int i;
for(i=0,bar=baz();i++<COUNT;bar.=foo()); OMG OPTIMIZED
Name:
Anonymous2011-05-07 15:51
It was general question and code, that I posted was only example. Sure, that if there would be only bar() methods it should be written like mentioned. But what about more realistic example:
bar = object.perform_some_action_A().perform_some_action_B().perform_some_action_C()
Most people say, that there should be temporary variables to make line shorter and more readable. Well, maybe back in time, when low resolution CRT monitors were used it was OK, but now? I also don't agree, that this indicate, that code is wrongly designed, because, as I mentioned it actually increased density and readability.
>>8
Really, you're unimaginative. bar = object.perform_some_action_A()
bar = bar.perform_some_action_B()
bar = bar.perform_some_action_C()
You don't need to put them all on the same line.
>>18
Remember, that variable's name should describe, what is stored in this variable. What if when bar.perform_some_action_B() returns something completely different, that bar.perform_some_action_C() ? Your concept is incorrect.
I wanted to spaz over the unsightly line-ending '\' convention but it never seems to come up.
Perl6's real line lengthening issue is chained method calls, but feeds take care of that:
@foo.grep: /^a/ ==>
.map: *.chars ==>
.reduce: *+*
Or:
@foo.grep: /^a/
==> .map: *.chars
==> .reduce: *+*
The worst thing you can do is mix the two. Imagine instead of @waldo, you have $waldo.split(/\s/).comb(/<[a..zA..Z]>/).
Name:
Anonymous2011-05-07 20:57
>>23
Btw that is a good example to illustrate the purpose of unspace. If you like to line things up and maybe format things a little differently you'll want unspace here and there:
@a\ .grep: /^a/
==> .map: *.chars
==> .reduce: *+*
(Though you could just feed into the initial .grep too.)