From: Nat Pryce Date: 2001-08-21T09:28:04+09:00 Subject: [ruby-talk:20040] Re: Ruby Article This is a multi-part message in MIME format. ------=_NextPart_000_0057_01C129DE.F084AD30 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable "Joshua Drake" wrote in message = news:to335diag2p2ff@corp.supernews.com... > Hello, >=20 > I am the author of the Programming in ruby on IBM Developworks. ... > I am getting ready to release the second article, but I want to get > some feedback from the ruby community first. I would like the second > article to be more ruby centric and will need some help. ... > while 1 ... > end Although this loops forever, as you intend, I would guess that it = doesn't do so for the reason you think. Also it is very misleading code = because people who are used to C would expect that 'while 0 ... end' = would not loop at all, but in Ruby it is also an infinite loop. Ruby = treats all values except false and nil as meaning 'true'. Secondly, Ruby provides an infinite loop method: 'loop {block}'. I = would use this in preference to 'while true ... end'. Finally, please refactor your program before publishing the article. = The code, as it is, is poorly structured and therefore not a good = example of Ruby -- the script uses global variables for no reason, the = methods are far too long, code structures are repeated instead of being = abstracted as methods, and so on. Also, the program doesn't use any of = Ruby's interesting features, such as creating domain specific iteration = statements. I would suggest rewriting the example using these kind of = idioms, otherwise all you are demonstrating is that Ruby has a different = syntax to Perl. You could also demonstrate Ruby's open classes by = defining your iterators as methods of the built-in File class, and = demonstrate Ruby's singleton methods by adding methods to the STDIN = object. E.g. the main loop should look something like this: File.open( address_file ) do |file| STDIN.each_address_input do |addr| file.write_address( addr ) end end The each_address_input method is a singleton method that reads addresses = from the input stream until the user inputs END.=20 The write_address method would write an address into the file in the = standard format. ------=_NextPart_000_0057_01C129DE.F084AD30 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
"Joshua Drake" <jd.nospam@commandprompt.com>=20 wrote in message news:to335diag2p2ff@corp.= supernews.com...
> Hello,
>
> I am the author of the Programming in = ruby on=20 IBM Developworks.
...
> I am getting ready to release the = second=20 article, but I want to get
> some feedback from the ruby community = first.=20 I would like the second
> article to be more ruby centric and will = need=20 some help.
...
>  while 1
...
>  end

 
Although this loops forever, as you intend, I would guess that it = doesn't=20 do so for the reason you think.  Also it is very misleading code = because=20 people who are used to C would expect that 'while 0 ... end' would not = loop at=20 all, but in Ruby it is also an infinite loop.  Ruby treats all = values=20 except false and nil as meaning 'true'.
 
Secondly, Ruby provides an infinite loop method: 'loop = {block}'.  I=20 would use this in preference to 'while true ... end'.
 
Finally, please refactor your program before publishing the=20 article.  The code, as it is, is poorly structured and therefore = not a good=20 example of Ruby -- the script uses global variables for no reason, the = methods=20 are far too long, code structures are repeated instead of being = abstracted as=20 methods, and so on.  Also, the program doesn't use any of = Ruby's=20 interesting features, such as creating domain specific iteration=20 statements.  I would suggest rewriting the example using these kind = of=20 idioms, otherwise all you are demonstrating is that Ruby has a different = syntax=20 to Perl.  You could also demonstrate Ruby's open classes by = defining your=20 iterators as methods of the built-in File class, and demonstrate = Ruby's=20 singleton methods by adding methods to the STDIN object.
 
E.g. the main loop should look something like this:
 
File.open( address_file ) do |file|
    STDIN.each_address_input do |addr|
        file.write_address( addr = )
    end
end
 
The each_address_input method is a singleton method that reads = addresses=20 from the input stream until the user inputs END. 
 
The write_address method would write an address into the file in = the=20 standard format.
 
------=_NextPart_000_0057_01C129DE.F084AD30--