Home > Archive > Ruby > August 2005 > Aesthetics of while ... do ... end versus while ...: ... end
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Aesthetics of while ... do ... end versus while ...: ... end
|
|
| Nikolai Weibull 2005-08-29, 9:57 pm |
| OK, this is really quite lame, but what do you people prefer:
while <test> do <something> end
or
while <test>: <something> end
?
The latter is shorter, but the puncutation sometimes meshes badly with
the test. Any insights?,
nikolai
--
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
| |
|
|
Nikolai Weibull wrote:
> OK, this is really quite lame, but what do you people prefer:
>
> while <test> do <something> end
>
> or
>
> while <test>: <something> end
>
> ?
>
> The latter is shorter, but the puncutation sometimes meshes badly with
> the test. Any insights?,
> nikolai
>
<something> while <test>
x = 3; p x -= 1 while x > 0
daz
| |
| Nikolai Weibull 2005-08-30, 7:58 am |
| daz wrote:
> <something> while <test>
>
> x = 3; p x -= 1 while x > 0
Yeah, that's what I'd use, but the problem is that x is first defined in
the test, so I have to use one of the two forms listed above,
nikolai
--
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
| |
| Doug Kearns 2005-08-30, 7:58 am |
| On Tue, Aug 30, 2005 at 08:52:12AM +0900, Nikolai Weibull wrote:
> OK, this is really quite lame, but what do you people prefer:
>
> while <test> do <something> end
I always use 'do' with 'while', 'until' and 'for' - probably the result
of too much shell programming.
> or
>
> while <test>: <something> end
I don't think I've ever actually seen this used in anger and a quick
search of lib/ didn't seem to turn up any.
> ?
>
> The latter is shorter, but the puncutation sometimes meshes badly with
> the test. Any insights?,
Not really. ;-)
Regards,
Doug
| |
| David Vallner 2005-08-30, 7:02 pm |
| Nikolai Weibull wrote:
>OK, this is really quite lame, but what do you people prefer:
>
>while <test> do <something> end
>
>or
>
>while <test>: <something> end
>
>?
>
>The latter is shorter, but the puncutation sometimes meshes badly with
>the test. Any insights?,
> nikolai
>
>
>
I could've sworn you could ommit the "do", as in:
while fred is barney
frobnicate(womble, fluff)
end
if you do yourself some good and resist the urge to golf the loop on a
single line.
David Vallner
(hate not having Ruby and an internet connection on the same computer)
| |
| Christian Neukirchen 2005-08-30, 7:02 pm |
| Nikolai Weibull <mailing-lists.ruby-talk@rawuncut.elitemail.org> writes:
> OK, this is really quite lame, but what do you people prefer:
>
> while <test> do <something> end
>
> or
>
> while <test>: <something> end
>
> ?
>
> The latter is shorter, but the puncutation sometimes meshes badly with
> the test. Any insights?,
I generally use
while predicate?
code
end
or, if I want it to be on a single line (can't remember doing that for
while-loops):
while predicate?; code; end
> nikolai
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org
| |
| Nikolai Weibull 2005-08-30, 7:02 pm |
| Christian Neukirchen wrote:
> Nikolai Weibull <mailing-lists.ruby-talk@rawuncut.elitemail.org> writes:
>
> I generally use
>
> while predicate?
> code
> end
>
> or, if I want it to be on a single line (can't remember doing that for
> while-loops):
>
> while predicate?; code; end
I'd rather use : or do than ; here. My question was with regards to
putting the whole while on one line, yes. That's why I wrote my
templates the way I did. I guess I should have been a bit more explicit
about it, though, as two of you commented on this. I'd write one-liners
as
<something> while <test>
but the problem is that <something> sometimes uses a variable defined in
<test>, so this won't always pass initial checking,
nikolai
--
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
| |
| Christian Neukirchen 2005-08-30, 7:02 pm |
| Nikolai Weibull <mailing-lists.ruby-talk@rawuncut.elitemail.org> writes:
> Christian Neukirchen wrote:
>
> I'd rather use : or do than ; here. My question was with regards to
> putting the whole while on one line, yes.
I disagree, and I don't see why everyone hates the semicolon.
I think it is more consistent to write
while foo; bar; baz; quux; end
than to write
while foo: bar; baz; quux; end
because, after all, this is not allowed:
while foo: bar: baz: quux: end
";" just means the same as a newline, and is meant to be used that
way, YMMV.
> nikolai
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org
| |
| Nikolai Weibull 2005-08-30, 7:02 pm |
| Christian Neukirchen wrote:
> Nikolai Weibull <mailing-lists.ruby-talk@rawuncut.elitemail.org> writes:
[color=darkred]
[color=darkred]
[color=darkred]
> I disagree, and I don't see why everyone hates the semicolon.
>
> I think it is more consistent to write
>
> while foo; bar; baz; quux; end
>
> than to write
>
> while foo: bar; baz; quux; end
>
> because, after all, this is not allowed:
>
> while foo: bar: baz: quux: end
Yes, but you can write it as
while foo: bar; baz; quux end
Which, in my opinion, clearly separates the foo from the bar and the
baz.
> ";" just means the same as a newline, and is meant to be used that
> way, YMMV.
And so is : or do after a while. I have nothing against ; per se, but
in this case I'd rather use : or do,
nikolai
--
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
| |
| Daniel Brockman 2005-08-31, 7:00 pm |
| Nikolai Weibull <mailing-lists.ruby-talk@rawuncut.elitemail.org> writes:
>
> Yes, but you can write it as
>
> while foo: bar; baz; quux end
>
> Which, in my opinion, clearly separates the foo from the
> bar and the baz.
Since we're already discussing mitutiae, I'll chime in and
say that I too prefer the colon here, simply because it
makes for more readable code. I'd write it as follows:
while foo: bar ; baz ; quux end
I always put spaces around semicolons in Ruby code ---
perhaps to reflect their rather symmetrical nature...
Actually, I'd probably use `do' rather than the colon.
I'd like to see `do' and `:' allowed after `def'.
def delta: last - first end
def request_foo do send "NEED FOO" end
In re while modifiers, I have defined a high-precedence
statement separator operator called `and then', which I
occasionally use when writing two-statement while loops:
lather and then rinse while dirty?
Apart from the higher precedence, the semantics of `foo and
then bar' is the same as `foo ; bar'. The preprocessor
translates `foo and then bar' into `foo or true and bar'.
No punchline, just some random thoughts.
--
Daniel Brockman <daniel@brockman.se>
|
|
|
|
|