That Ruby code is channelling Pearl, banish it! Burn, ye devil!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
The "I Love Lua, but..." post
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: The "I Love Lua, but..." post
Help us help you: attach a .love.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: The "I Love Lua, but..." post
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).
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: The "I Love Lua, but..." post
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.
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.
Help us help you: attach a .love.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: The "I Love Lua, but..." post
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.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: The "I Love Lua, but..." post
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 "...").
Help us help you: attach a .love.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: The "I Love Lua, but..." post
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[])
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: The "I Love Lua, but..." post
Let's stop here, I've got a lot more to say, but we're derailing the thread here.
Help us help you: attach a .love.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Who is online
Users browsing this forum: zingo and 5 guests