Why is it bad practice to check the type of a value at runtime? I’m new
to Ruby, but I thought that I had read that it is dynamically, strongly
typed, meaning that variables do not have types but values do. I would
think that it would be common to check types at run time.
I would think that checking types of values would be part and parcel of
good object-oriented programming. Doesn’t OO insist that classes are
more than the sum of their methods? Does duck-typing contradict this?
Does it expect us to treat the following classes as
assignment-compatible?
class DatabaseConnection
def open()
#…
end
def close()
#…
end
Returns true if the connection has been opened.
def check()
# …
end
end
class BankAccount
def open()
#…
end
def close()
#…
end
Returns a Check object with a new check number.
Fails if open has not been called.
def check()
#…
end
end
The contracts of these classes are totally different.