# Not quite getting it

**URL:** <https://rubytalk.org/t/not-quite-getting-it/46554>\
**Category:** ruby-talk\
**Created:** [16 May 2008 18:45 UTC](https://rubytalk.org/t/not-quite-getting-it/46554 "2008-05-16T18:45:50Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roger\_Alsing](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@Roger\_Alsing](https://rubytalk.org/u/Roger_Alsing)\
**Post date:** [16 May 2008 18:45 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/1 "2008-05-16T18:45:50Z")

</div>

Hi,  
I'm trying to get whats Ruby is all about.  
I've been doing .NET since beta so I'm kind of stuck in the static typed  
mindset.

The parts that I do get:

I love metaprogramming, I was able to make a port of my .NET AOP  
framework that took about 3 months to do in .NET in a week in Ruby (w/o  
ever touching ruby before.. )

I also understand that its nice with auto promotion of number types when  
they would overflow in other languages.

What I don't get:

How do you deal with ducktyping?  
How can anyone assume that just because a method exists that the  
semantics is the same?

Brush.Draw( x , y )  
vs  
Cowboy.Draw( direction, speed )

The same name and signature, not even close to the same semantic  
meaning.

Doesnt this put an extra burden on the developer, that he has to know  
the exact intention of each and every method?  
Where in a language that supports ifaces you simply know that the  
methods associated with the interface have a certain meaning.

The backside of dynamic typing.  
I got a mail from a newsgroup a few days ago with the title "we once  
overflowed a long at google"

Ok ok, as I said, I get type promotion.  
But what if you assign a "Giraffe" to a property called "Orders" , isnt  
that just as bad or even worse than overflowing a number?

If someone say "that should be caught in a unit test" , well so should  
the overflowed long (And Java and .NET can use big integers etc too if  
you need)

And the thing that I have the hardest time with, how the heck do you  
learn to use someone elses framework / api ?

in a typed language with decent intellisense I can see what types Im  
supposed to pass in and what I get back.  
One can often understand how to use an API by just looking at the  
intellisense.

While I found myself browsing ruby docs back and forth just to see if  
the result of a method would be a string or an object etc.

So can someone try to convert me or am I forever lost? 😛

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Roger\_Alsing](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@Roger\_Alsing](https://rubytalk.org/u/Roger_Alsing)\
**Post date:** [16 May 2008 18:48 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/2 "2008-05-16T18:48:15Z")

</div>

"in a typed language"

Before I get killed, I ment static typed..

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Dave\_Mail\_Archive](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Dave\_Mail\_Archive](https://rubytalk.org/u/Dave_Mail_Archive)\
**Post date:** [16 May 2008 18:57 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/3 "2008-05-16T18:57:49Z")

</div>

I kinda think that this is the basis of programming in any language...

Here's the thing. I'm sure many people will try to convince you--this may end up being a thread that runs and runs.

Ignore them. They'll never change your mind.

The only thing that will is for you to try it. Try Ruby on larger programs. Try it for a month or too. And see what happens. If your programs die because brushes end up shooting people, then Ruby isn't the language for you. If instead you continue to enjoy a factor of 12 productivity improvement, maybe it is.

Everyone's mileage will vary.

Dave

> **···**
>
> On May 16, 2008, at 1:45 PM, Roger Alsing wrote:
> 
> > Doesnt this put an extra burden on the developer, that he has to know  
> > the exact intention of each and every method?

---

<div class="post-metadata">

**Author:** ![Jason\_R](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Jason\_R](https://rubytalk.org/u/Jason_R)\
**Post date:** [16 May 2008 19:02 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/4 "2008-05-16T19:02:33Z")

</div>

Very oft brought up question, and valid in some points.

int someInterestingMethod(int x, int y, float spock) {  
...  
}

What do those parameters mean? What do you pass into this function and  
what are you supposed to get out? Just having static types does not at  
all help with understanding what a function does. You need well named  
functions and arguments, with \*documentation\* on what the function  
does and what parameters are supposed to be. This is no different in a  
statically typed language vs dynamically typed language.

The only thing a static typed language guarantees is that proper types  
were passed into the function. That's no guarantee that you're using  
the function correctly or that the function itself works at all. Only  
a comprehensive test suite will catch these kind of problems.

Things like overflowing a float will happen to anyone in any language.

So in short, all code should have:

1) documentation of what the method does, what the parameters are and  
what the return is.  
2) properly named functions and parameters.

neither of which has anything to do with the typing system of the  
language. There will be libraries who's maintainers don't document  
anything, leaving you to experiment and ask around. This is true for  
all programming and is something we just have to live with (and  
hopefully not propogate).

Hope that helps you understand why dynamic vs static typing really  
isn't a issue.

Jason

> **···**
>
> On 5/16/08, Roger Alsing \<roger.alsing@precio.se\> wrote:
> 
> > Hi,  
> > I'm trying to get whats Ruby is all about.  
> > I've been doing .NET since beta so I'm kind of stuck in the static typed  
> > mindset.
> > 
> > The parts that I do get:
> > 
> > I love metaprogramming, I was able to make a port of my .NET AOP  
> > framework that took about 3 months to do in .NET in a week in Ruby (w/o  
> > ever touching ruby before.. )
> > 
> > I also understand that its nice with auto promotion of number types when  
> > they would overflow in other languages.
> > 
> > What I don't get:
> > 
> > How do you deal with ducktyping?  
> > How can anyone assume that just because a method exists that the  
> > semantics is the same?
> > 
> > Brush.Draw( x , y )  
> > vs  
> > Cowboy.Draw( direction, speed )
> > 
> > The same name and signature, not even close to the same semantic  
> > meaning.
> > 
> > Doesnt this put an extra burden on the developer, that he has to know  
> > the exact intention of each and every method?  
> > Where in a language that supports ifaces you simply know that the  
> > methods associated with the interface have a certain meaning.
> > 
> > The backside of dynamic typing.  
> > I got a mail from a newsgroup a few days ago with the title "we once  
> > overflowed a long at google"
> > 
> > Ok ok, as I said, I get type promotion.  
> > But what if you assign a "Giraffe" to a property called "Orders" , isnt  
> > that just as bad or even worse than overflowing a number?
> > 
> > If someone say "that should be caught in a unit test" , well so should  
> > the overflowed long (And Java and .NET can use big integers etc too if  
> > you need)
> > 
> > And the thing that I have the hardest time with, how the heck do you  
> > learn to use someone elses framework / api ?
> > 
> > in a typed language with decent intellisense I can see what types Im  
> > supposed to pass in and what I get back.  
> > One can often understand how to use an API by just looking at the  
> > intellisense.
> > 
> > While I found myself browsing ruby docs back and forth just to see if  
> > the result of a method would be a string or an object etc.
> > 
> > So can someone try to convert me or am I forever lost? 😛
> > 
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Phil](https://avatars.discourse-cdn.com/v4/letter/p/e95f7d/32.png) [@Phil](https://rubytalk.org/u/Phil)\
**Post date:** [16 May 2008 19:21 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/5 "2008-05-16T19:21:04Z")

</div>

Roger Alsing wrote:

> How do you deal with ducktyping?  
> How can anyone assume that just because a method exists that the  
> semantics is the same?

Well, if it walks like a duck, and it talks like a duck, it probably is  
a duck.

I.e. if a Class or variable reacts to certain methods, it probably is of  
the correct type.

> Brush.Draw( x , y )  
> vs  
> Cowboy.Draw( direction, speed )
> 
> The same name and signature, not even close to the same semantic  
> meaning.
> 
> Doesnt this put an extra burden on the developer, that he has to know  
> the exact intention of each and every method?

That's true of any language. .NET baffles \*me\*, for example. 😛

> Where in a language that supports ifaces you simply know that the  
> methods associated with the interface have a certain meaning.

It's similar in Ruby (but not quite). Unlike more 'blue-collar'  
languages (not my term! And it is usually used in conjunction with Java,  
but it probably applies to .NET as well), Ruby doesn't try to protect  
you. It has some 'safety' measures, though.

'a string' + 2 Won't work, as the string is, well, a string, and the 2  
is an integer. And you can't implicitly cast types in Ruby, for example.

> The backside of dynamic typing.  
> I got a mail from a newsgroup a few days ago with the title "we once  
> overflowed a long at google"
> 
> Ok ok, as I said, I get type promotion.  
> But what if you assign a "Giraffe" to a property called "Orders" , isnt  
> that just as bad or even worse than overflowing a number?

Depends on the scenario, I guess, and what 'Orders' is supposed to do.  
If it is, for example, an array holding all items in a shopping cart,  
there is no issue. If 'Orders' is only supposed to contain objects of  
the class 'Fruit', you are of course in a bit of a pickle. However, the  
class 'Orders' is supposed to handle that.

Note: I don't think that data structures like arrays or hashes can  
actually overflow. You can create them with arbitrary lengths (subject  
to limitations like available memory, obviously).

Ruby's Array's aren't like (I think this is .NET syntax, but feel free  
to correct me, it's been a while) Array ary = Array[9];, where ary can  
hold only 10 members.

> If someone say "that should be caught in a unit test" , well so should  
> the overflowed long (And Java and .NET can use big integers etc too if  
> you need)

Well, this probably more an issue with the developer, than the language,  
from what I can see.

> And the thing that I have the hardest time with, how the heck do you  
> learn to use someone elses framework / api ?

How did you learn .NET? Same thing, really: Reading documentation, using  
tutorials, experimentation.

> in a typed language with decent intellisense I can see what types Im  
> supposed to pass in and what I get back.  
> One can often understand how to use an API by just looking at the  
> intellisense.

NetBeans, Eclipse, and Ruby in Steal (which is built upon visual Studio,  
but isn't free, but has actual IntelliSense(tm)) can do that for you.

It hinges on the documentation provided by the gem / application you use  
to tell you what the method expects.

> While I found myself browsing ruby docs back and forth just to see if  
> the result of a method would be a string or an object etc.

Well, usually a Ruby object returns what you pass in. So, something that  
handles arrays, returns an array. I think. If that is what you mean. 🙂

> So can someone try to convert me or am I forever lost? 😛

Hey, doing something that took you 3 months in .NET in 1 week in a  
foreign language is a rather strong testimonial, isn't it?

Though, as Dave Black suggested, you'll have to try for yourself. Work  
with Ruby for a while, and if you like it, you like it, and if you don't  
like it, then you don't like it. 🙂

In my, admittedly limited experience in using statically typed language  
versus Ruby, I don't need the additional safety or benefits the static  
types provide. How ever, you mileage will vary.

- --  
Phillip Gawlowski  
Twitter: twitter.com/cynicalryan  
Blog: [http://justarubyist.blogspot.com](http://justarubyist.blogspot.com)

~ - You know you've been hacking too long when...  
...you're trying to get to sleep but can't because you don't know the  
right VMS logical--you keep typing SHOW LOGICAL \*SLEEP\* and never get  
anything but: SHOW-S-NOTRAN, no translation for logical name \*SLEEP\*

---

<div class="post-metadata">

**Author:** ![Florian\_Gilcher](https://avatars.discourse-cdn.com/v4/letter/f/57b2e6/32.png) [@Florian\_Gilcher](https://rubytalk.org/u/Florian_Gilcher)\
**Post date:** [16 May 2008 20:16 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/6 "2008-05-16T20:16:54Z")

</div>

Actually, how do you guarantee those semantics in a statically typed language?

Consider this (pseudo-java, sorry 😉 ):

interface Drawable  
{  
&nbsp;&nbsp;&nbsp;&nbsp;abstract public void draw(int a, int b);  
}

class Point implements Drawable  
{  
&nbsp;&nbsp;&nbsp;public void draw(int x, int y)  
&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Canvas.drawPoint(x,y);  
&nbsp;&nbsp;&nbsp;}  
}

class CarThief implements Drawable  
{  
&nbsp;&nbsp;&nbsp;public void draw(int x, int y)  
&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Car c = steal(Cars.random());  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c.drive\_to(x,y);  
&nbsp;&nbsp;&nbsp;}  
}

Both Classes implement Drawable but there is no way to check on two "Drawable" whether  
they share the same semantics.

Regards  
Skade

> **···**
>
> On May 16, 2008, at 8:45 PM, Roger Alsing wrote:
> 
> > How do you deal with ducktyping?  
> > How can anyone assume that just because a method exists that the  
> > semantics is the same?
> > 
> > Brush.Draw( x , y )  
> > vs  
> > Cowboy.Draw( direction, speed )
> > 
> > The same name and signature, not even close to the same semantic  
> > meaning.

---

<div class="post-metadata">

**Author:** ![a11](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/a11/32/8169_2.png) [@a11](https://rubytalk.org/u/a11)\
**Post date:** [16 May 2008 23:02 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/7 "2008-05-16T23:02:27Z")

</div>

then you will need a tall box.

a @ [http://codeforpeople.com/](http://codeforpeople.com/)

> **···**
>
> On May 16, 2008, at 12:45 PM, Roger Alsing wrote:
> 
> > Ok ok, as I said, I get type promotion.  
> > But what if you assign a "Giraffe" to a property called "Orders" , isnt  
> > that just as bad or even worse than overflowing a number?
> 
> --  
> we can deny everything, except that we have the possibility of being better. simply reflect on that.  
> h.h. the 14th dalai lama

---

<div class="post-metadata">

**Author:** ![Huw\_Collingbourne](https://avatars.discourse-cdn.com/v4/letter/h/71e660/32.png) [@Huw\_Collingbourne](https://rubytalk.org/u/Huw_Collingbourne)\
**Post date:** [18 May 2008 18:40 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/8 "2008-05-18T18:40:23Z")

</div>

Roger Alsing wrote:

> in a typed language with decent intellisense I can see what types Im  
> supposed to pass in and what I get back.

You can still have decent IntelliSense with Ruby. Take a look 😉

[http://www.sapphiresteel.com/](http://www.sapphiresteel.com/)

best wishes  
Huw

SapphireSteel Software  
Ruby and Rails In Visual Studio  
[http://www.sapphiresteel.com](http://www.sapphiresteel.com)

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Paddy](https://avatars.discourse-cdn.com/v4/letter/p/77aa72/32.png) [@Paddy](https://rubytalk.org/u/Paddy)\
**Post date:** [25 May 2008 06:44 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/9 "2008-05-25T06:44:53Z")

</div>

> Hi,  
> I'm trying to get whats Ruby is all about.  
> I've been doing .NET since beta so I'm kind of stuck in the static typed  
> mindset.
> 
> The parts that I do get:
> 
> I love metaprogramming, I was able to make a port of my .NET AOP  
> framework that took about 3 months to do in .NET in a week in Ruby (w/o  
> ever touching ruby before.. )
> 
> I also understand that its nice with auto promotion of number types when  
> they would overflow in other languages.
> 
> What I don't get:
> 
> How do you deal with ducktyping?  
> How can anyone assume that just because a method exists that the  
> semantics is the same?

\<\<Snip\>\>

> So can someone try to convert me or am I forever lost? 😛  
> --  
> Posted viahttp://www.ruby-forum.com/.

Two blog posts that might help:  
&nbsp;&nbsp;[http://jessenoller.com/2007/05/30/typeducking-on-duck-vs-static-typing/](http://jessenoller.com/2007/05/30/typeducking-on-duck-vs-static-typing/)  
&nbsp;&nbsp;[Go deh!: Duck Typing Done Right Is Wrong!](http://paddy3118.blogspot.com/2008/05/duck-typing-done-right-is-wrong.html)

> **···**
>
> On 16 May, 19:45, Roger Alsing \<roger.als...@precio.se\> wrote:

---

<div class="post-metadata">

**Author:** ![Keith\_Bennett](https://avatars.discourse-cdn.com/v4/letter/k/ebca7d/32.png) [@Keith\_Bennett](https://rubytalk.org/u/Keith_Bennett)\
**Post date:** [16 May 2008 22:55 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/10 "2008-05-16T22:55:04Z")

</div>

Florian, your example is not a fair one; it illustrates an intentional  
violation of the semantics, whereas Roger is referring to an  
accidental one. In fact, it illustrates the lengths to which one must  
go to trigger the problem in Java.

Roger, your question is one that I have shared. I think it's  
mathematically impossible to deny that the less restrictive nature of  
duck typing makes it more likely to encounter an inappropriate  
object. The question, though, is how \*much\* more likely? As in  
premature optimization, do we really know that this will be a  
problem? Or are we incorrectly assuming it?

People with much more experience with Ruby than I (such as Dave)  
report that this is not a problem in practice. I think the minimal  
risk here needs to be balanced with the formidable benefits of coding  
in such a highly productive language as Ruby.

- Keith

---

<div class="post-metadata">

**Author:** ![Florian\_Gilcher](https://avatars.discourse-cdn.com/v4/letter/f/57b2e6/32.png) [@Florian\_Gilcher](https://rubytalk.org/u/Florian_Gilcher)\
**Post date:** [17 May 2008 00:24 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/11 "2008-05-17T00:24:39Z")

</div>

Pragmatic Programming ;).

Roger, just because variables are not typed doesn't mean that you can't  
check for Types. Actually, Rubys type-system is quite strong, it doesn't  
allow casts. You can very easily build objekt properties that check for  
type or a certain set of methods. Something like:

class Test  
&nbsp;&nbsp;&nbsp;&nbsp;attr\_accessor :order

&nbsp;&nbsp;&nbsp;&nbsp;def order=(order)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if order.kind\_of?(Giraffe)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise Exception.new("We package nearly everything, but Giraffes???")  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;end  
end

So Ruby does typing, but on a different level. It assumes that all objects are sane and  
then gives you the possiblity to check all the information that the object propagates and  
use that for reasoning. See it as a service-based approach. Wouldn't be the first time  
a service does not do what the name implies ;).

The numbers problem: Conceptually, there is also no such thing as an "overflowing number",  
in Ruby because Ruby abstracts high enough that you as a Programmer do not have to to  
care about those technical implications. This is a completely different ballpark ;).

Regards,  
Florian Gilcher

> **···**
>
> On May 17, 2008, at 1:02 AM, ara.t.howard wrote:
> 
> > On May 16, 2008, at 12:45 PM, Roger Alsing wrote:
> > 
> > > Ok ok, as I said, I get type promotion.  
> > > But what if you assign a "Giraffe" to a property called "Orders" , isnt  
> > > that just as bad or even worse than overflowing a number?
> > 
> > then you will need a tall box.

---

<div class="post-metadata">

**Author:** ![Todd\_Benson](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@Todd\_Benson](https://rubytalk.org/u/Todd_Benson)\
**Post date:** [16 May 2008 23:49 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/12 "2008-05-16T23:49:11Z")

</div>

I tend to think that using a RDBMS for data integrity with an overlay  
of Ruby is a nice compromise. I'm still anti-unit\_test, but then, I'm  
not a seasoned programmer and am probably missing the good stuff.

With meta: there's a very subtle geeky wet dream underlying the whole  
concept of meta-programming. I'll stick around and see what happens,  
but I'll use it sparingly.

Todd

> **···**
>
> On Fri, May 16, 2008 at 5:55 PM, Keith Bennett \<keithrbennett@gmail.com\> wrote:
> 
> > Florian, your example is not a fair one; it illustrates an intentional  
> > violation of the semantics, whereas Roger is referring to an  
> > accidental one. In fact, it illustrates the lengths to which one must  
> > go to trigger the problem in Java.
> > 
> > Roger, your question is one that I have shared. I think it's  
> > mathematically impossible to deny that the less restrictive nature of  
> > duck typing makes it more likely to encounter an inappropriate  
> > object. The question, though, is how \*much\* more likely? As in  
> > premature optimization, do we really know that this will be a  
> > problem? Or are we incorrectly assuming it?
> > 
> > People with much more experience with Ruby than I (such as Dave)  
> > report that this is not a problem in practice. I think the minimal  
> > risk here needs to be balanced with the formidable benefits of coding  
> > in such a highly productive language as Ruby.
> > 
> > - Keith

---

<div class="post-metadata">

**Author:** ![Florian\_Gilcher](https://avatars.discourse-cdn.com/v4/letter/f/57b2e6/32.png) [@Florian\_Gilcher](https://rubytalk.org/u/Florian_Gilcher)\
**Post date:** [17 May 2008 00:12 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/13 "2008-05-17T00:12:15Z")

</div>

> Florian, your example is not a fair one; it illustrates an intentional  
> violation of the semantics, whereas Roger is referring to an  
> accidental one. In fact, it illustrates the lengths to which one must  
> go to trigger the problem in Java.

Actually, you don't have to go that far :). I know, the example is a  
artificial.

Actually, i did only add the interface for illustration. A more common case  
would be the assumption that methods of subclasses share  
common semantics with methods of superclasses. I had such  
a case some time ago, when a fellow student assumed that a method  
name was not taken and implemented it on a subclass, causing havoc  
in the code calling it :). Granted, this is an indicator that the naming  
was too generic, but the language didn't help a bit.

But the question was:

\>How can anyone assume that just because a method exists that the  
\>semantics is the same?

This problem is present in both Java and Ruby and none of the  
languages helps me much in this. It is much more a question of  
programmers discipline, good naming and knowledge of the  
ecosystem the software lives in :). Thats perhaps why you don't  
experience it as a big problem. Considering that i assume that  
ruby is not the first OOP-Language for many people, they've  
already got a headstart when it comes to this.

But actually, i can produce a real-world sample for an interesting semantic  
changing behaviour that is much harder to reproduce in Java/C# and  
would really be abuse in such languages.

If you know you way around ActiveRecord, calling #find on associated set  
of models (e.g. @some\_person.friends.find) will not call Array#find but  
Friend.find. \_But\_ if you try inspecting the Object, it will happily tell you that  
it is an Array. (and not some subclass ...)

> **···**
>
> On May 17, 2008, at 12:55 AM, Keith Bennett wrote:

---

<div class="post-metadata">

**Author:** ![Roger\_Alsing](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@Roger\_Alsing](https://rubytalk.org/u/Roger_Alsing)\
**Post date:** [17 May 2008 05:48 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/14 "2008-05-17T05:48:36Z")

</div>

> class Test  
> &nbsp;&nbsp;&nbsp;&nbsp;attr\_accessor :order
> 
> &nbsp;&nbsp;&nbsp;&nbsp;def order=(order)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if order.kind\_of?(Giraffe)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise Exception.new("We package nearly everything, but  
> Giraffes???")  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;&nbsp;end  
> end

So is it common practise to do it like this?  
Eg. does active records have this kind of stuff in the generated code  
that comes out of "has\_many" etc?

Anyway, I think I do buy this.  
Preventing the wrong types form beeing used is pretty much the same as  
preventing the use of null in C#.  
It simply become an extra step in parameter validation.

And thanks everyone for the replies 🙂

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![J\_Cooper](https://avatars.discourse-cdn.com/v4/letter/j/3e96dc/32.png) [@J\_Cooper](https://rubytalk.org/u/J_Cooper)\
**Post date:** [17 May 2008 06:43 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/15 "2008-05-17T06:43:37Z")

</div>

Roger Alsing wrote:

> > class Test  
> > &nbsp;&nbsp;&nbsp;&nbsp;attr\_accessor :order
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;def order=(order)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if order.kind\_of?(Giraffe)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise Exception.new("We package nearly everything, but  
> > Giraffes???")  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> > &nbsp;&nbsp;&nbsp;&nbsp;end  
> > end
> 
> So is it common practise to do it like this?

I wouldn't really say it's "common practice" in Ruby to do a bunch of  
kind\_of? parameter checks; I haven't seen it very often, and if it were  
the "desirable" thing for a Rubyist to do, the language would do it for  
you. As you say, this way adds extra steps just to check some stuff that  
only ultimately has the result of increasing the coupling of your code.

Instead, look at it like this: how likely is a Giraffe able to do what  
an Order does? If the Giraffe doesn't quack like an Order, than an  
exception is going to be thrown automatically anyway.

Just program in it, and see how often it ever actually bites you. Start  
with small things, work your way up. Read other people's code from time  
to time. I myself am from a C# background, and probably I really still  
think that way, but I do like Ruby a lot and I find it fun to use even  
though my Ruby code doesn't look as "Ruby" as many of the people's here.

And do keep in mind that Ruby makes some things quite simple that can be  
more of a pain to do in C# -- anything involving string manipulation and  
regular expressions, for example. And the built-in arrays and hashes  
have a ton of functionality and make stuff really succinct (and gets you  
away from having to use long nested List\<Dictionary\<string, Blah\>\>  
stuff, or having to cast all the time with ArrayLists, or whatever). The  
language reads well and makes you jump through minimal hoops; the code  
you write tends to be shorter and thus easier to digest. It has an  
interactive mode that's really neat, and you can even use it to check  
out what methods a given object makes available. The "standard library"  
is rich and has a ton of stuff built in. And there's a lot of  
high-quality, free libraries and tools out there that other people have  
done.

Where C# trumps it, in my opinion, is in having a ridiculously awesome  
IDE integrated with it, and in super easy GUI building capabilities.  
(There are other more obvious differences, like performance vs.  
cross-platform capabilities.) There are of course Ruby IDEs (including  
the SapphireSteel Visual Studio thing or whatever that has Intellisense;  
I'm sure the guy will be happy to plug it) and you can of course build  
GUIs in Ruby, but again, it's not about what a language can DO, it's  
about what it makes easy.

So again, just give it a whirl. Outside of whatever your work uses,  
there's no one forcing you to use one language or another. Try them out,  
keep an open mind, and go with what feels good.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Florian\_Gilcher](https://avatars.discourse-cdn.com/v4/letter/f/57b2e6/32.png) [@Florian\_Gilcher](https://rubytalk.org/u/Florian_Gilcher)\
**Post date:** [17 May 2008 08:49 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/16 "2008-05-17T08:49:50Z")

</div>

Yes, ActiveRecord checks for the type of Associations. I would not call  
it "common practice" to rely on the type, but as ActiveRecord  
maps type Names to Tables, it is desireable to do that.

Regards,  
Florian Gilcher

> **···**
>
> On May 17, 2008, at 7:48 AM, Roger Alsing wrote:
> 
> > > class Test  
> > > &nbsp;&nbsp;&nbsp;attr\_accessor :order
> > > 
> > > &nbsp;&nbsp;&nbsp;def order=(order)  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if order.kind\_of?(Giraffe)  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise Exception.new("We package nearly everything, but  
> > > Giraffes???")  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> > > &nbsp;&nbsp;&nbsp;end  
> > > end
> > 
> > So is it common practise to do it like this?  
> > Eg. does active records have this kind of stuff in the generated code  
> > that comes out of "has\_many" etc?
> > 
> > Anyway, I think I do buy this.  
> > Preventing the wrong types form beeing used is pretty much the same as  
> > preventing the use of null in C#.  
> > It simply become an extra step in parameter validation.
> > 
> > And thanks everyone for the replies 🙂

---

<div class="post-metadata">

**Author:** ![Marc\_Heiler](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@Marc\_Heiler](https://rubytalk.org/u/Marc_Heiler)\
**Post date:** [17 May 2008 10:06 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/17 "2008-05-17T10:06:29Z")

</div>

> I wouldn't really say it's "common practice" in Ruby to do a bunch of  
> kind\_of? parameter checks;

I am not a good ruby coder but the code I saw, and my own code as well,  
rarely uses ".kind\_of?" at all

".is\_a?" is much more common from my point of view to be seen in ruby  
code

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Rick\_DeNatale1](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@Rick\_DeNatale1](https://rubytalk.org/u/Rick_DeNatale1)\
**Post date:** [18 May 2008 14:14 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/18 "2008-05-18T14:14:10Z")

</div>

Good advice.

It brings to mind the experience of learning to ride a bike without  
training wheels. There's even a connection in that learning to ride a  
bicycle is learning to deal with dynamic stability.

Of course some can just jump right in, like my 6-year old next door  
neighbor, who went right from riding a tricycle to a bike without  
benefit of training wheels.

> **···**
>
> On Sat, May 17, 2008 at 2:43 AM, J. Cooper \<nefigah@gmail.com\> wrote:
> 
> > Instead, look at it like this: how likely is a Giraffe able to do what  
> > an Order does? If the Giraffe doesn't quack like an Order, than an  
> > exception is going to be thrown automatically anyway.
> > 
> > Just program in it, and see how often it ever actually bites you. Start  
> > with small things, work your way up.
> 
> --  
> Rick DeNatale
> 
> My blog on Ruby  
> [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![Keith\_Bennett](https://avatars.discourse-cdn.com/v4/letter/k/ebca7d/32.png) [@Keith\_Bennett](https://rubytalk.org/u/Keith_Bennett)\
**Post date:** [17 May 2008 14:30 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/19 "2008-05-17T14:30:02Z")

</div>

An interesting example of an intentional violation of method semantics  
in the Java standard library is the unModifiableXxx() methods in  
java.util.Collections. They wrap a collection and override the  
mutating methods to throw an exception when they are called.

So someone relying on add() to add an object because that's what's  
specified in the interface Javadoc would be quite surprised when an  
implementation of that interface refused to honor the contract and  
threw an exception instead.

- Keith

---

<div class="post-metadata">

**Author:** ![Roger\_Alsing](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@Roger\_Alsing](https://rubytalk.org/u/Roger_Alsing)\
**Post date:** [18 May 2008 16:40 UTC](https://rubytalk.org/t/not-quite-getting-it/46554/20 "2008-05-18T16:40:18Z")

</div>

> > Instead, look at it like this: how likely is a Giraffe able to do what  
> > an Order does? If the Giraffe doesn't quack like an Order, than an  
> > exception is going to be thrown automatically anyway.
> > 
> > Just program in it, and see how often it ever actually bites you. Start  
> > with small things, work your way up.
> 
> Good advice.

This kind of mindset is just asking for things to go wrong..

Lets say that the Giraffe happens to have a few methods that does match  
those of an order, so that it manages to introduce incorrect values that  
populate through your data before the exception is eventually caught.

(ofcourse a Giraffe is an extreme case, but multiple domain objects can  
have attributes that overlap, such as price, name etc)

And once you catch the exception, you have absolutely no clue at all  
what have been affected.

Incorrectness should be caught early before it litters your data, or you  
will have a seriously hard time debugging.

Just because the language is non strict when it comes to types doesnt  
mean you should not care about correctness?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

[Next page](https://rubytalk.org/t/not-quite-getting-it/46554.md?page=2)
