Tumblelog by Soup.io
Newer posts are loading.
You are at the newest post.
Click here to check if anything new just came in.

June 29 2009

citizen428
16:09

Pascal vs. Ruby

On ruby-talk somebody was asking for a method which will be used to generate a random string, by returning either a lowercase letter or one of the digits 0-9 when called. As an example he posted the following Pascal program:

function GetRandomChar: char;
var
 r: integer;
begin
 r := random(36);
 case r of
   0..25: result := chr(ord('a') + r);
   else : result := chr(ord('0') + r);
 end;
end;

“Translating” this to Ruby, this is what I got:

In your face, Niklaus Wirth! ;-)

P.S. Actually I do have fond memories of the good old Turbo Pascal days.