P
Peter Maas
Roy said:Python is a very dynamic language. Java is a very static language.
What is the difference between "static" and "very static"? Is Java
more static than Fortran I?
Peter Maas, Aachen
Roy said:Python is a very dynamic language. Java is a very static language.
Rene said:(e-mail address removed):
The problem with that of course, is that there's much more to being a duck
than being called 'duck'.
public interface JarFile {
void explode();
}
public interface NuclearBomb {
void explode();
}
http://www.beust.com/weblog/archives/000269.html
Peter Maas said:He probably means that with interfaces one could test compliance
with the interface as a whole instead of testing each member and
each signature as a single piece.
Given that FORTRAN will happily upconvert numeric types as needed inWhat is the difference between "static" and "very static"? Is Java
more static than Fortran I?![]()
Roy Smith said:All interfaces (as implemented by Java) prove is that your class has a
bunch of methods with the right names and signatures. It doesn't
prove that those methods do the right things. It's like having a
I'm coming from a Java background, so please don't stone me...
I see that Python is missing "interfaces". The concept of an interface
is a key to good programming design in Java, but I've read that they
aren't really necessary in Python. I am wondering what technique I can
use in Python to get the same benefits to a program design that I would
get with interfaces in Java.
For example, if I want to have a program with a Car object, and a Bus
object. I want both of these objects to present a common group of
methods that can be used by Mechanic objects, but slightly different
methods that can be used by Driver objects.
In Java I would accomplish this by defining an IFixable interface that
would be implemented by both the Car and Bus objects. Mechanic objects
would work with any object implementing this interface.
How would I approach this problem in Python? I think I would use an
abstract class instead of an interface for IFixable, since Python
supports multiple inheritance, but I'm not sure this is correct.
Thanks for any suggestions.
Scott Huey
You won't find many deep class hierarchies and extensive frameworks.
This has the advantage that a classification you have done once at
the beginning of your project in the design phase is not considered
to be carved in stone.
Everyone is getting off track here.
Java has interfaces because it doesn't support multiple inheritance.
Python supports MI, so you don't need to use the seperate concept of an
interface.
The general wisdom is that Abstract Base Classes aren't pythonic
though.
Rene said:Kay Schluehr:
Zope comes to mind.
Zope 3 comes to mind.
bruno said:Yeps. Now Zope is a world in itself, and is not really pythonic IMHO.
There's a _tiny_ bit more -- accidental clashes of methodnames are more
likely to be avoided. I.e.,
interface ILottery {
void draw();
};
interface IGunslinger {
void draw();
};
interface IPainter {
void draw();
};
A class asserting, e.g., "implements IPainter", doesn't thereby risk
being accidentally misused where an IGunslinger is required (OTOH,
implementing >1 of these IS a bother, but that's sort of inevitable).
I'm coming from a Java background, so please don't stone me...
I see that Python is missing "interfaces". The concept of an interface
is a key to good programming design in Java, but I've read that they
aren't really necessary in Python. I am wondering what technique I can
use in Python to get the same benefits to a program design that I would
get with interfaces in Java.
For example, if I want to have a program with a Car object, and a Bus
object. I want both of these objects to present a common group of
methods that can be used by Mechanic objects, but slightly different
methods that can be used by Driver objects.
In Java I would accomplish this by defining an IFixable interface that
would be implemented by both the Car and Bus objects. Mechanic objects
would work with any object implementing this interface.
How would I approach this problem in Python? I think I would use an
abstract class instead of an interface for IFixable, since Python
supports multiple inheritance, but I'm not sure this is correct.
Thanks for any suggestions.
Roy Smith said:I suppose, but all you've really done is move the problem to a different
namespace. Which IPainter did you have in mind? The one that has to do
with people who apply oils to canvas, or the one that has to do with ropes
that are used to tie up rowboats?
Alex Martelli said:In Java's excellent naming convention for modules, there's no ambiguity:
I specifically requested it.aleax.artists.IPainter, or else specifically
requested com.panix.roy.boating.IPainter -- nothing stops any language
with a structured namespace for modules from using that convention.
Ben said:It seems to me that a lot of python projects reimplement interfaces or
adaption of some kind once they reach a certain size (Zope, PEAK, eggs,
TurboGears, etc), which implies that they really do have some benefits,
particularly in documentation.
PEAK is an interesting counterexample, particularly since Philip Eby
tends to be "ahead of the curve":
I see various answers that Python doesn't need interfaces. OTOH, there are
responses that some large Python apps have implemented them (e.g., zope).
Does anyone have an explanation of why these large systems felt they needed
to implement interfaces?
I see various answers that Python doesn't need interfaces. OTOH, there are
responses that some large Python apps have implemented them (e.g., zope).
Does anyone have an explanation of why these large systems felt they needed
to implement interfaces?
Rene Pijlman said:Alex Martelli:
I never noticed PEAK before. Is it well worth studying?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.