Page 6 of 6

Re: The "I Love Lua, but..." post

Posted: Wed May 04, 2011 7:30 pm
by Robin
BlackBulletIV wrote:

Code: Select all

-- take the first argument, remove all quotes, split words into an array, capitalize each word, join them back together into a string
ARGV[0].gsub(/'|"/, '').split.map {|v| v.capitalize }.join
-- generates a random 7 character strings with characters from 0-z
('0'..'z').to_a.shuffle[0..7].join
That Ruby code is channelling Pearl, banish it! Burn, ye devil! :shock:

Re: The "I Love Lua, but..." post

Posted: Wed May 04, 2011 8:25 pm
by BlackBulletIV
It would probably looking cleaner without the comments, but it's all a matter of preference. However, I don't understand what "channelling Pearl" means; only thing I can make out of it is you think it's bad, and there may be a reference to Perl (which is one of the three languages Ruby is based on - Smalltalk, Perl, Python).

Re: The "I Love Lua, but..." post

Posted: Wed May 04, 2011 8:49 pm
by Robin
Yeah, I meant Perl, can't believe I misspelt that.

Anyway, Perl has the reputation of being executable line noise. Ruby's Dark Side is mostly the part that's based on the magic and cryptic notations Perl is famous for.

Re: The "I Love Lua, but..." post

Posted: Wed May 04, 2011 9:07 pm
by BlackBulletIV
Believe me, I don't like Perl at all. But I'm not sure why you call that cryptic, unless of course you're not familiar with the language's core API (but this happens for every language to a certain degree). But, the strange global variables are the cryptic things in Ruby (inherited from Perl I believe) like $_, $` and so on; not that you have to use them in your code though.

Re: The "I Love Lua, but..." post

Posted: Wed May 04, 2011 9:16 pm
by Robin
You're right, this particular piece of code isn't that bad. But I'm not a fan of literal regexes and magic ARGV (I'm glad Lua ditched that in favour of "...").

Re: The "I Love Lua, but..." post

Posted: Wed May 04, 2011 10:47 pm
by BlackBulletIV
Well that's a point we differ on, I love regex literals. But anyway, each to their own. But I do wish ARGV could be named something more, friendly-looking; that old name was inherited from C:

Code: Select all

int main(int argc, char* argv[])

Re: The "I Love Lua, but..." post

Posted: Thu May 05, 2011 8:44 am
by Robin
Let's stop here, I've got a lot more to say, but we're derailing the thread here. ;)

Re: The "I Love Lua, but..." post

Posted: Thu May 05, 2011 9:39 am
by BlackBulletIV
*train crash* :P Alright yeah, good idea.