-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Roger A. 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™) 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 G.
Twitter: twitter.com/cynicalryan
Blog: 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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkgt3pwACgkQbtAgaoJTgL+kfQCfWxaHIIUz65IWBAnzfuJar9vH
pk0AnjFjlIbpgW6F11fblZgMHmf0tOJg
=8an1
-----END PGP SIGNATURE-----