

Why I Like Ruby - robconery
http://blog.wekeroad.com/thoughts/why-i-like-ruby

======
pbz
One thing that puzzles me is the "expressiveness" factor. When I read code, in
any language, I translate that code into blocks / models, not English. I don't
read the code as I would read a book or an article. That would take too much
effort / time because right after "reading" it, I would still have to parse it
into the mental model.

For me, if you write "if (myvariable != null) { }" or "unless(myvariable.nil?)
end" doesn't make a difference. In fact, if I were to read it as English "if
my variable is not null do" sounds better than "unless my variable is null,
question mark?" -- I'm actually puzzled how you would "read" that.

In any case, my argument is that a translation from code -> mental model is
more efficient than code -> English -> mental model, in which case
expressiveness is only helpful in as much as it helps in parsing the code and
not "reading" it in English.

~~~
texel
The given example of "unless myvariable.nil?" is a little bit awkard. In fact,
the use of the "unless" keyword is, in my opinion, almost always awkward
unless it's postfixed: "do_a_thing unless wait?"

Not only that, but _most_ of the time, the expression could simply be written
"if myvariable; ...; end", seeing as the vast majority of the time, we only
care if the thing we're testing is falsy.

Ruby does give you the tools to be very expressive, indeed almost
conversational in your coding style, but it also gives you enough rope to hang
yourself.

~~~
draegtun
Damian Conway in _Perl Best Practices_ recommends not to use negative control
statements at all ( _unless_ and _until_ ).

So this would be a no-no:

    
    
        unless ($this > $that) {
            do_something();
        }
    

He's happy they're used to postfix statements however he says that these
should only be used for flow control. For eg.

    
    
        for my $i (@list) {
            next unless $i % 2 == 0;
            do_something();
        }

~~~
draegtun
Correction: Conway says _don't use postfix unless, for, while or until_

So last example should be:

    
    
        for my $i (@list) {
            next if not $i % 2 == 0;
            do_something();
        }
    

Personally I don't follow the bible to the letter :) I do use prefix & postfix
_unless_ but only with simple truth conditions like this:

    
    
        unless ($this) { ... }
    
        next unless $this;

------
barrydahlberg
My thoughts as someone who's been full time on C# for the last 5 or so years:

 _Case 1 -_ His examples are toys, I don't think there's really an argument
here. Better examples might convince.

 _Case 2 -_ This is less about the language and more about the tools and the
culture. The ecosystem in C# land is focused much more heavily in the business
/ enterprise direction which personally I hate. Point to Ruby.

 _Case 3 -_ Half a point maybe. The .Net library is actually pretty good and
each version of C# brings the language a step closer to the sort of concise
code he shows. You can certainly get very close with a few wrappers here and
there.

 _Case 4 -_ Meta Programming, oh yes. 10 points to Ruby. It has been said
elsewhere that C# doesn't have meta programming because it was designed to be
predictable for whoever has to read it. In practice this seriously restricts
our ability to express certain types of concepts that don't fit the basic OO
model. Aspect oriented programming and mix-ins are the two currently
frustrating me.

We try to tackle this with all sorts of hacks (e.g. PostSharp, mangling .dlls
after compilation) but they don't fit well with the rest of the tools.

This means lots of boiler plate repetition we can't kill. Microsoft likes to
use code generation for this which I also hate.

~~~
mathgladiator
C# has some meta-programming with the addition of closures and good
polymorphism. Check out how <http://kayakhttp.com/> uses them to build a
fairly sophisticated async web server.

------
ecoffey
I skimmed part of this, and had to giggle a bit at this quote (of a quote):

"It's clear that C# isn't the best language to use for Web Development. Just
ask the guys who are writing the frameworks with it."

Sure C# is verbose. But I still feel it's pretty expressive. I'm working on a
web framework in C# (<http://github.com/ecoffey/Bebop>). Granted it's totally
a toy thing, but still. Looks beautiful to me :-P

Also it annoys me he compares non-idiomatic C# with idiomatic Ruby.

I guess I should quote this FTA: "My whole point here is to tell you why _I_
like it - not to convince you of anything.", and finish with it all comes back
to the right tool for the job _shrug_.

~~~
joe_the_user
The verbosity of both C# and Java just appall me.

It would seem to me that verbosity and expressiveness are opposites - a
language which inherently uses many lines to express an action is a language
which inherently expresses little per line. How could it be otherwise?

~~~
jasonlotito
I realize I'm going outside the context of the discussion here, but just
wanted to comment on this.

> a language which inherently uses many lines to express an action is a
> language which inherently expresses little per line

Depends on what you an action is. It's nice working in a language where each
thing does one thing and one thing only. A single line that does numerous
things at once can get pretty crazy, with magical processes spreading pixie
dust over your data.

------
macuser1234
For a web designer that works with css, html, and php, the only thing keeping
me away is deployability. It seems that without learning git and the ways of
my terminal, I have no way to make a web app with RoR. Not that I don't want
to learn. I do, badly. But I just wish the barrier to entry could be lower.
Either that or I just need to find a better tutorial going from nothing to a
very simple app on Heroku and showing me how to experiment with it.

~~~
bad_user
You don't need Git to use RoR ... but try and learn it. It's awesome ;)

Git also comes with a SVN bridge, which works wonderfully for me.

Also ... Rails has its own development web-server. You don't need to have a
production environment to learn it.

And I really recommend that when learning about any web framework, in any
language ... just learn how to deploy a production server by yourself. It
saves a lot of pain later on ;)

Not to mention that I wouldn't use Heroku ... sure they provide a valuable
service, but personally I get a cheaper deal by getting EC2 instances and
configuring them myself. It's hard the first time, but then you can scale your
infrastructure easily ... EC2 is wonderful in that regard.

~~~
latentflip
Do you have any guidance or suggestions for reading material for how to
migrate from using Heroku to going directly to EC2, for someone who is
somewhat new to sysadmin?

------
Tichy
I am still not sure how unicode works in Ruby. Therefore I never dare to do
any String operations like regular expressions or the the chomp/split he does.

The pragmatic book mentions something about kcode (I think), but Rails seems
to use something else. Back when I last tried, I couldn't find any definite
answers to this.

Maybe Ruby 1.9 solves this problem - but is it ready yet? Again, last I tried,
there wasn't even a MySQL driver for it.

~~~
draegtun
To be fair unicode has never been without issues in Perl & Python either! Perl
has generally been the best of the three (IMHO) but Python 3.0 & Ruby 1.9 have
probably now caught up.

------
sigzero

      raise "Hey dude! Where's My Variable Assignment" if my_variable.nil?
    

I really hate raising an exception like that. I am surprised Rubyists like it
like he says they do.

~~~
substack
I prefer:

    
    
        my_variable or raise 'Hey dude! Where's My Variable Assignment'
    

or else:

    
    
        my_variable.nil? and raise 'Hey dude! Where's My Variable Assignment'
    

since it puts what's being tested in front like with if/then but is also
syntactically light-weight.

------
GrandMasterBirt
Well explained. However many tools of ruby. Tools that we as good developers
carry at the bottom of our toolbox for those rare cases where they make life a
billion times easier, can also be tools of spaghetti. One of these is the
ability to inject behaviors into a class. Its like adding to Array.prototype.
The point is that just like a goto statement, it has a few legitimate uses,
but most of the time leads to spaghetti code. I think every language has this,
and there should be big flashing warnings when tutorials show this methodology
stating that "use this only where appropriate, and it is usually only
appropriate in these situations:..."

