Missing interfaces in Python...

gmilas at gmail.com gmilas at gmail.com
Tue Apr 18 12:02:07 EDT 2006


I am currently working in C# after I spent about 3 years almost only in
python, The way I see thinks is that for me we need interfaces in C# to
allow for flexibility in using OOP because we must only pass defined
and known types at all times so for us to have the flexibility of
passing either a Car or a Bus to the Mechanic when we actually only
need their fixIt method we need to use a common type that will
accommodate the constraint of having the fixIt method. Of course this
could also be implemented using an abstract base class but since in C#
as well as in Java we don't have multiple inheritance it is better to
use an interface for flexibility purpose (for ex. sometime you have to
subclass from MarshalByRefObject in order to use the object in a
distributed system so inheritance is out of the question as a means to
flexibility in that case).

So for good and flexible OOP in C# someone should use interfaces
because it is the only way to achive the flexibility needed but in
python because of duck typing you always get the flexibility without
you doing anything special like trying to come up with a type that
accommodates some common ground of other types, so as someone say here
"To use interfaces in python, just do what you would do in Java, except
don't use interfaces."

So to digress a little, for me the difference is that in C# you are
given safety, documentation (read app. domain definitions) and
track-ability (read refactoring, intelisense) but you have to code for
flexibility while in python you are given flexibility but you have to
code for safety and documentation and as far as for track-ability you
are usually out of luck. Now many people agree that the safety you are
given in C# is usually far from ideal (no app. domain logic safety
given) so usually you have to code for that as well as in python, and
my opinion is that the documentation provided by type definition wile
ok, for best maintainability you have to provide comments anyway about
their app. domain means just like you do in python, so the only think
that is different is that the lack of track-ability in python is
sometime annoying for me now when I'm going back to python after a
little bit of C#, but the annoyance is even bigger when in C# I always
have to think ahead of time how to make sure that my code if flexible
enough to support easy changing.

Gheorghe Milas




More information about the Python-list mailing list