Tuesday, September 08, 2009

Duck Typing

So, in Python there's this concept of Duck Typing. First time I read about it (shortly after getting into Python,) I passed it off as a curiosity. No idea how to take advantage of the concept.

So now I'm taking a Java class (mostly because the Uni doesn't offer Python classes.)
import university

class Python:
    pass

university.CompSci.add(Python)
No not that kind of class!

Well, apparently in Java when you have a function that could just as easily work on int arrays as String arrays as float arrays, you need one copy of that function for each type. Which means in certain situations you have two otherwise identical functions (and I mean character-for-character identical, as in Ctrl-C, Ctrl-V identical, aside from the function signature.

So I'm just staring at this pair of functions now, and I really ought to be wrapping up the assignment, but I can't shake the feeling that this is wrong.

No comments:

Post a Comment