On 5/16/08, Roger Alsing <
roger.alsing@...> 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? :-P
>
> --
> Posted via
http://www.ruby-forum.com/.
>
>
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