Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Ruby annoyances for a newb

Reply
Thread Tools

Ruby annoyances for a newb

 
 
Miguel Fonseca
Guest
Posts: n/a
 
      02-24-2008
Hello!

I'm a fresh ruby programmer from Portugal and until now I've been coding
mostly java programs. I'm posting here to find out what you think about
two things that annoy me in ruby:

- The fact that variables dont have type! Sure this is andy in several
situations but it can also be a source of problems with wrong input
being passed to the methods! Because of this I'me forced to check
manually for the type in the begining of methods (ex: if
price.instance_of? Fixnum )

- Second fact has to do with exceptions, in contrast to what happens in
java the catching of exceptions is not forced, so most times I end up
not coding the catch statement wich leads to a lot of run-time errors,
also for system functions I dont't know wich exceptions they throw!

I would like to know your opinion about these two matters. Probably
these are not problems at all, only my java side confusing me! =D

Hope I was able to express myself correctly
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Christopher Dicely
Guest
Posts: n/a
 
      02-24-2008
On Sun, Feb 24, 2008 at 8:25 AM, Miguel Fonseca <(E-Mail Removed)> wrote:
> Hello!
>
> I'm a fresh ruby programmer from Portugal and until now I've been coding
> mostly java programs. I'm posting here to find out what you think about
> two things that annoy me in ruby:
>
> - The fact that variables dont have type! Sure this is andy in several
> situations but it can also be a source of problems with wrong input
> being passed to the methods! Because of this I'me forced to check
> manually for the type in the begining of methods (ex: if
> price.instance_of? Fixnum )


While there may be some cases where you need to check for the class of an object
at the beginning of methods, its generally viewed as a practice to be avoided
unless you've identified a specific need for it. The capacity of Ruby objects
to participate in operations is determined by the methods they support
("duck typing") not their class. For the most part, library methods
should document
what they expect and it is the responsibility of client code to
provide an object that
behaves appropriately.

> - Second fact has to do with exceptions, in contrast to what happens in
> java the catching of exceptions is not forced, so most times I end up
> not coding the catch statement wich leads to a lot of run-time errors,
> also for system functions I don't know wich exceptions they throw!


You should be only rescuing exceptions that you can usefully do
something about. Most core methods should identify what they
raise and when in their documentation, and you can use that to
identify what you could rescue, but if you can't reasonably
deal with an error, you shouldn't rescue it.

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      02-24-2008
On 24.02.2008 17:25, Miguel Fonseca wrote:
> I'm a fresh ruby programmer from Portugal and until now I've been coding
> mostly java programs. I'm posting here to find out what you think about
> two things that annoy me in ruby:
>
> - The fact that variables dont have type! Sure this is andy in several
> situations but it can also be a source of problems with wrong input
> being passed to the methods! Because of this I'me forced to check
> manually for the type in the begining of methods (ex: if
> price.instance_of? Fixnum )


No, you're not. Please read about "duck typing". If you do not want a
dynamically typed language then clearly Ruby is not for you and you are
better served with Java. If you want to program in Ruby, you need to
adjust your mindset. You cannot expect that Ruby is just another Java
even though some things look familiar.

> - Second fact has to do with exceptions, in contrast to what happens in
> java the catching of exceptions is not forced, so most times I end up
> not coding the catch statement wich leads to a lot of run-time errors,
> also for system functions I dont't know wich exceptions they throw!


This is only partly true: even in Java there is a ton of exceptions that
nobody forces you to catch. There has been a lot of debate about
checked vs. unchecked exceptions in general. I guess by now everything
is said about it elsewhere. There are pros and cons to both
approaches. IMHO unchecked exceptions fit Ruby very well while Java's
model fits Java very well.

> I would like to know your opinion about these two matters. Probably
> these are not problems at all, only my java side confusing me! =D


Probably. I suggest you get accustomed to the Ruby way, revisit your
criticism after a while and see whether you still think it's valid.

> Hope I was able to express myself correctly


Absolutely. If you are interested, these topics have been discussed
excessively here so you will find plenty material in the archives.

Kind regards

robert
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ruby annoyances ... mine is line continuation, what's yours? scooterm@hotmail.com Ruby 10 01-19-2008 03:16 AM
cpl VS.NET annoyances JV ASP .Net 0 05-31-2005 09:05 PM
2 small annoyances RAH Computer Support 1 10-29-2004 01:11 AM
Windows Media Annoyances rnd Computer Support 1 04-08-2004 05:59 PM
A Couple of XP Annoyances Sam Computer Support 2 02-12-2004 02:05 PM



Advertisments