Archive for ruby

Learning some new languages

Posted in Uncategorized with tags , , , , , , on November 20, 2008 by dlamotte

I’ve started learning ruby and erlang.

I’d like to learn ruby because I want to know what all the fuss is about.  Ruby is so slick!  It seems liked jazzed up perl to me, with even more hacks to make coding “easier” and “fun”.  To be honest, I have fun implementing in any language.  In fact, I have fun with the concepts, not language in which they were written.  Its nice to just see your code do so much amazing stuff just like you thought it would after you’ve written it.  Things like this make me think of perl with hacks:

irb(main):001:0>  %w(some words that get seperated like qw in perl).each { |f| puts “item: ” + f }

item: some
item: words
item: that
item: get
item: seperated
item: like
item: qw
item: in
item: perl
=> ["some", "words", "that", "get", "seperated", "like", "qw", "in", "perl"

Doesn't that just feel like perl with less words?

for my $word (qw(some words for you)) {
print "item: $word\n";
}
item: some
item: words
item: for
item: you

As for erlang, I read some posts a while back about erlang being an awesome language in the future.  I'd link to them, but I don't feel like finding the links.  Erlang is much more complicated than your typical "language", as this goes for all functional languages.  I've also noticed it is syntax heavy.  In fact, my programmer eyes couldn't pick up some small errors at first.  This is due to the fact that I don't copy code and insist on retyping things that I read, but thats a topic for another day.  Lets see if your eyes can catch the error between these two snippets.

-module(test).
-export([fac/1]).

fac(0) -> 1;
fac(N) -> N * fac(N-1).

That compiles, this next one doesn’t…

-module(test).
-export([fac/1]).

fac(0) -> 1;
fac(N) -> N * fac(N-1);

It took me a good couple sweeps to see the difference.  Its subtle isn’t it?  Coming from a programming background that all statements are terminated by a ‘;’ to a language that seems to mix ‘;’ and ‘.’ has made it quite complex.  If you are still reading, but haven’t seen the difference, its on the last line and has to do with the last character on the line.  Crazy huh?

I’m learning erlang because I’m curious how these “functional” languages work.  I think it will give me a different viewpoint on the entire situation.  In fact, recently, I’ve decided I no longer have an Object Oriented bias.  I’ve noticed the benefits of Functional programming as much as Object Oriented.  Its a turning point in my programming career as I was asked in an interview “Contrast Object Oriented and Funtional programming.  Which is your favorite?” and I responded Object Oriented.  Today, I would show no bias between the two and would leave it up to mere opion and preference.

Follow

Get every new post delivered to your Inbox.