J
Jeff Cohen
I'm new to Ruby - actually new to dynamically typed languages in
general. I'm from more of a C++ and C# (strongly-typed and
statically-typed) background.
One thing I'm trying to wrap my brain around is the lack of explicit
interface definitions. In C# we use interfaces so that client code can
program against an abstract interface, and then you can give that client
any concrete implementation of that interface as needed. Interfaces
provide a level of abstraction/indirection that increase reusability and
testability.
Now, in Ruby, I like the "walk like a duck" approach. Actually, it's
similar to C++ templates which are very powerful.
But there are two things that I worry about as I forge ahead in my new
Ruby lifestyle:
1. In C# I can write code that can query an object for the interfaces it
implements to find out what I can do with it. (Rarely used but
sometimes a lifesaver). In Ruby I guess I have to use .methods to find
out what methods it implements?
2. In C# I can insure that a function is given an object that implements
a certain interface. If I don't, it's a compile-time error and I know
it before I ship it. In Ruby, I won't know if I accidentally pass in
the wrong object until runtime. I might not catch it before I ship the
code.
Can anyone provide some enlightenment?
Thanks!
Jeff
general. I'm from more of a C++ and C# (strongly-typed and
statically-typed) background.
One thing I'm trying to wrap my brain around is the lack of explicit
interface definitions. In C# we use interfaces so that client code can
program against an abstract interface, and then you can give that client
any concrete implementation of that interface as needed. Interfaces
provide a level of abstraction/indirection that increase reusability and
testability.
Now, in Ruby, I like the "walk like a duck" approach. Actually, it's
similar to C++ templates which are very powerful.
But there are two things that I worry about as I forge ahead in my new
Ruby lifestyle:
1. In C# I can write code that can query an object for the interfaces it
implements to find out what I can do with it. (Rarely used but
sometimes a lifesaver). In Ruby I guess I have to use .methods to find
out what methods it implements?
2. In C# I can insure that a function is given an object that implements
a certain interface. If I don't, it's a compile-time error and I know
it before I ship it. In Ruby, I won't know if I accidentally pass in
the wrong object until runtime. I might not catch it before I ship the
code.
Can anyone provide some enlightenment?
Thanks!
Jeff