Am I missing something with Python not having interfaces?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bruno Desthuilliers

    #16
    Re: Am I missing something with Python not having interfaces?

    jmDesktop a écrit :
    (snip)
    On the dynamic typing,
    isn't that the same sort of thing that lots of scripting languages
    do?
    This is not restricted to scripting languages - that is, unless you'd
    call Smalltalk, Erlang or common lisp "scripting languages".

    Also and FWIW, static typing in C is mostly here to help the compiler
    optimizing, and it's very common to use void pointers and typecast to
    get some genericity (cf the sort() function in C stdlib). And you have
    the same pattern in Java with "generic" containers storing only "object"
    instances, then you have to cast your objects back to the appropriate
    type (which may fails, leading to a runtime error).
    VBScript doesn't require you to define your variables,
    You mean "to declare the type of your variables" ? Neither OCaml nor
    Haskell require this, and they are both statically and strongly typed.
    but I
    don't really want to use it for anything
    Neither do I, but not because of dynamic typing. By experience, dynamic
    typing works just fine for most applications. And by experience too,
    static typing doesn't magically make your code bullet-proof.
    (used to use it a lot in
    Classic ASP.) I believe everyone that Python is great, but some of it
    doesn't make sense to me as to why.
    Quite a lot of Java stopped making sens to me since I learned some other
    languages. And most of the "OO" (hem) complexity, patterns madness etc
    you'll typically find in Java code only exists because of the language's
    arbitrary restrictions and lack of expressivity.

    Learn Python, learn Ruby or (preferably) Smalltalk, learn common lisp or
    (preferably) Scheme, learn OCaml or (preferably) Haskell, learn Erlang,
    and you'll find out that there's much more in programming and languages
    than can be dreamt of in Java's philosophy !-)

    Comment

    • Bjoern Schliessmann

      #17
      Re: Am I missing something with Python not having interfaces?

      jmDesktop wrote:
      Studying OOP and noticed that Python does not have Interfaces.
      By "OOP", you mean "Java", right? 8)
      Is that correct? Is my schooling for nought on these OOP concepts
      if I use Python. Am I losing something if I don't use
      the "typical" oop constructs found in other languages (Java, C#
      come to mind.)
      AFAIK, Interfaces weren't "typical" before Java. CMIIW.

      BTW, Zope has interfaces. Not sure if it's exactly the same.

      Regards,


      Björn

      --
      BOFH excuse #424:

      operation failed because: there is no message for this error (#1014)

      Comment

      • bruno.desthuilliers@gmail.com

        #18
        Re: Am I missing something with Python not having interfaces?

        On 7 mai, 18:05, Bjoern Schliessmann <usenet-
        mail-0306.20.chr0n.. .@spamgourmet.c omwrote:
        jmDesktop wrote:
        Studying OOP and noticed that Python does not have Interfaces.
        >
        By "OOP", you mean "Java", right? 8)
        >
        Is that correct? Is my schooling for nought on these OOP concepts
        if I use Python. Am I losing something if I don't use
        the "typical" oop constructs found in other languages (Java, C#
        come to mind.)
        >
        AFAIK, Interfaces weren't "typical" before Java. CMIIW.
        >
        BTW, Zope has interfaces. Not sure if it's exactly the same.
        >
        It isn't.

        Comment

        • Daniel Marcel Eichler

          #19
          Re: Am I missing something with Python not having interfaces?

          Am Dienstag 06 Mai 2008 16:07:01 schrieb Mike Driscoll:
          If so, then it looks like an Interface is a generic class with method
          stubs. You can do that with Python just as easily by creating empty
          methods with just the "pass" keyword.
          Well, no. It's a litte different. Interfaces force to implement methods.
          Simple inheritance with method-stubs can't garantee that a specific
          method is reimplementat in a sub-class. Interfaces work at
          compile-time, while method-stubs raise at their first call, so in worst
          case, never (when the developer is available).
          Since it's just a construct to implement polymorphism, I don't think
          you'll lose anything. However, Python does not require you to re-
          implement every method of the class it is inheriting from.
          That's the point. Interfaces garantee that a duck is a duck, an not only
          a chicken that quack.
          You can just override those that you want and leave the others alone.
          Not always desirable. But often enough ;)

          Comment

          • Luis Zarrabeitia

            #20
            Re: Am I missing something with Python not having interfaces?

            On Wednesday 07 May 2008 03:19:30 pm Daniel Marcel Eichler wrote:
            Am Dienstag 06 Mai 2008 16:07:01 schrieb Mike Driscoll:
            >
            Well, no. It's a litte different. Interfaces force to implement methods.
            Simple inheritance with method-stubs can't garantee that a specific
            method is reimplementat in a sub-class. Interfaces work at
            compile-time, while method-stubs raise at their first call, so in worst
            case, never (when the developer is available).
            <Pseudo-java code>
            class MyClass implements MyInterfaceWith PassMethod {
            function Pass() {
            }
            }
            </pseudo-java code>

            There you have it, interfaces are not enough to ensure that the implementors
            actually implement the methods. They are useful for warning at compile time
            if there is a missing method, but nothing more. I believe you could achievea
            very similar warning in python using some kind of Interface metaclass (too
            lazy right now to hack a proof of concept, but it looks doable).

            I actually like the Interface concept... as portrayed by zope.Interfaces and
            pyprotocols (not the same thing, but I like them), and the ABCs (these, not
            so much). But Java interfaces are barely a replacement for multiple
            inheritance+abs tract methods.
            That's the point. Interfaces garantee that a duck is a duck, an not only
            a chicken that quack.
            Not really. (See the NotImplementedE xceptions in .NET 1.1 and window forms,
            and/or their TabbedControl/TabPage background color attribute. Can't find
            them now, as I don't have .NET anymore, but I consider that an example of why
            the static typing are... overrated)

            --
            Luis Zarrabeitia (aka Kyrie)
            Fac. de Matemática y Computación, UH.

            Comment

            • bruno.desthuilliers@gmail.com

              #21
              Re: Am I missing something with Python not having interfaces?

              On 7 mai, 21:19, Daniel Marcel Eichler <onsen-n...@gmx.netwro te:
              Am Dienstag 06 Mai 2008 16:07:01 schrieb Mike Driscoll:
              >
              If so, then it looks like an Interface is a generic class with method
              stubs. You can do that with Python just as easily by creating empty
              methods with just the "pass" keyword.
              >
              Well, no. It's a litte different. Interfaces force to implement methods.
              Simple inheritance with method-stubs can't garantee that a specific
              method is reimplementat in a sub-class.
              And Java's "Interface" wart can't garantee that a specific method is
              *appropriately* implemented. One often sees do-nothing methods in Java
              code - useless boilerplate code that's only here to satisfy the
              compiler. It's just like Java's "checked exception" mechanism : one
              very often sees do-nothing catch-all try/catch blocks in Java - which
              is way worse than just letting the exception propagate. I find all
              this totally pointless, because there's just no way for a compiler to
              check if your code is logically correct.
              Interfaces work at
              compile-time, while method-stubs raise at their first call, so in worst
              case, never.
              And then ? If it's never called, why bother implementing it ?

              Here again, I don't see the point of compile-time checking.
              RuntimeError is a well-known Java exception, so the fact is that Java
              forces you into either rigid designs or overly complex workarounds
              (best knowns as "design patterns"), without even being able to
              garantee anything wrt/ correctness nor even safety. Not that static
              typing by itself is necessarily bad - as usual, there's a balance
              between somewhat conflicting goals -, but Java's type system
              definitivly is (bad).

              (snip)
              That's the point. Interfaces garantee that a duck is a duck, an not only
              a chicken that quack.
              Who cares if it's a chicken as long as it quacks when you ask her to ?
              Now *This* is the whole point of chicken^Mduck typing, isn't it ?-)

              Comment

              • Daniel Marcel Eichler

                #22
                Re: Am I missing something with Python not having interfaces?

                Am Mittwoch 07 Mai 2008 22:39:30 schrieb Luis Zarrabeitia:
                There you have it, interfaces are not enough to ensure that the
                implementors actually implement the methods. They are useful for
                warning at compile time if there is a missing method, but nothing
                more.
                It's not the fault of the enviroment, if the coder is to stupid to use
                it the right way.
                I believe you could achieve a very similar warning in python
                using some kind of Interface metaclass (too lazy right now to hack a
                proof of concept, but it looks doable).
                Of course. And unlike Javas interfaces, it ensure a more dynamic
                coding-style, without great tools which check all the time for correct
                behaviour.

                Comment

                • Daniel Marcel Eichler

                  #23
                  Re: Am I missing something with Python not having interfaces?

                  Am Donnerstag 08 Mai 2008 00:12:26 schrieb
                  bruno.desthuill iers@gmail.com:
                  very often sees do-nothing catch-all try/catch blocks in Java - which
                  is way worse than just letting the exception propagate. I find all
                  this totally pointless, because there's just no way for a compiler to
                  check if your code is logically correct.
                  But it's enough if the called method exists and returns the correct
                  type. At least it prevents a crash.
                  Interfaces work at
                  compile-time, while method-stubs raise at their first call, so in
                  worst case, never.
                  And then ? If it's never called, why bother implementing it ?
                  You never can't say when it's called at least, that's the point.
                  That's the point. Interfaces garantee that a duck is a duck, an not
                  only a chicken that quack.
                  Who cares if it's a chicken as long as it quacks when you ask her to
                  ? Now *This* is the whole point of chicken^Mduck typing, isn't it ?-)
                  Ducks can also swim and fly. And if you need a really duck, but have
                  onyl a chicken while the coder was to bored to make one...

                  Of course, in the practical world that all doesn't matter. But in the
                  theoretical world of the big coding farms, called business, that's one
                  cornerstone of success, in the tinking of managers and so.

                  Comment

                  • J. Clifford Dyer

                    #24
                    Re: Am I missing something with Python not having interfaces?

                    On Thu, 2008-05-08 at 09:12 +0200, Daniel Marcel Eichler wrote:
                    Am Mittwoch 07 Mai 2008 21:48:56 schrieben Sie:
                    >
                    That's the point. Interfaces garantee that a duck is a duck, an not
                    only a chicken that quack.
                    Which, in spite of your rhetorical flourish, is the exact opposite of
                    duck typing. Duck typing means that if you're looking for quacking
                    behavior, and you find a quacking chicken, it's close enough.
                    >
                    I didn't said that interfaces are a kind of duck-typing. In fact it was
                    the exact opposite.
                    >
                    Sometimes you need that kind of rigor, and you can get it as easily
                    as
                    >
                    And sometimes you need more. So what?
                    >
                    More rigor than Zope's interfaces offer? That's new information to me.
                    Perhaps you should stop being argumentative for a moment, and explain
                    exactly what it is you're looking for and why Zope interfaces don't fit
                    the bill.



                    Comment

                    • J. Cliff Dyer

                      #25
                      Re: Am I missing something with Python not having interfaces?

                      On Thu, 2008-05-08 at 13:25 -0400, J. Cliff Dyer wrote:
                      On Thu, 2008-05-08 at 19:11 +0200, Daniel Marcel Eichler wrote:
                      Am Donnerstag 08 Mai 2008 13:02:52 schrieb J. Clifford Dyer:
                      I didn't said that interfaces are a kind of duck-typing. In fact it
                      was the exact opposite.

                      Sometimes you need that kind of rigor, and you can get it as
                      easily as

                      And sometimes you need more. So what?
                      >
                      More rigor than Zope's interfaces offer?
                      Did i say that? I only explained why interfaces are not 'simple method
                      stubs'.
                      >
                      Um. Yes. I said "sometimes you need that kind of rigor," and proceeded
                      to explain how zope interfaces offer it. (which you snipped from your
                      quotation), and you said "sometimes you need more." If you were
                      actually responding to what I said, then "sometimes you need more" must
                      mean more than zope interfaces.
                      >
                      That's new information to
                      me. Perhaps you should stop being argumentative for a moment, and
                      explain exactly what it is you're looking for and why Zope interfaces
                      don't fit the bill.
                      Perhaps you should read more accurate. It's not my thread and i'm not
                      looking for anything here.
                      >
                      Then what were you trying to say?
                      >
                      --
                      Oook,
                      J. Cliff Dyer
                      Carolina Digital Library and Archives
                      UNC Chapel Hill

                      Comment

                      • Bruno Desthuilliers

                        #26
                        Re: Am I missing something with Python not having interfaces?

                        Daniel Marcel Eichler a écrit :
                        Am Donnerstag 08 Mai 2008 00:12:26 schrieb
                        bruno.desthuill iers@gmail.com:
                        >
                        >very often sees do-nothing catch-all try/catch blocks in Java - which
                        >is way worse than just letting the exception propagate. I find all
                        >this totally pointless, because there's just no way for a compiler to
                        >check if your code is logically correct.
                        >
                        But it's enough if the called method exists and returns the correct
                        type. At least it prevents a crash.
                        Then providing an appropriate default in the base class is enough too.
                        >>Interfaces work at
                        >>compile-time, while method-stubs raise at their first call, so in
                        >>worst case, never.
                        >And then ? If it's never called, why bother implementing it ?
                        >
                        You never can't say when it's called at least, that's the point.
                        Either the method is actually called somewhere and you'll now it pretty
                        soon, or it isn't and you don't care.
                        >>That's the point. Interfaces garantee that a duck is a duck, an not
                        >>only a chicken that quack.
                        >Who cares if it's a chicken as long as it quacks when you ask her to
                        >? Now *This* is the whole point of chicken^Mduck typing, isn't it ?-)
                        >
                        Ducks can also swim and fly. And if you need a really duck,
                        If you're code expects something that quacks, swims and flies, anything
                        that quacks, swims and flies is ok. You just don't care if it's a duck
                        or a flying whale with a quacking device tied to it.
                        but have
                        onyl a chicken while the coder was to bored to make one...
                        Then the coder have a nice traceback, and it's not *your* problem - as
                        long as the expectations are clearly documented, it's the user's (ie:
                        coder) duty to provide something that fullfil the expectations.
                        Of course, in the practical world that all doesn't matter. But in the
                        theoretical world of the big coding farms, called business, that's one
                        cornerstone of success, in the tinking of managers and so.
                        Sorry, I live in a very practical world - and we're by no mean running
                        out of business here...

                        Comment

                        • Daniel Marcel Eichler

                          #27
                          Re: Am I missing something with Python not having interfaces?

                          Am Freitag 09 Mai 2008 10:19:45 schrieb Bruno Desthuilliers:
                          very often sees do-nothing catch-all try/catch blocks in Java -
                          which is way worse than just letting the exception propagate. I
                          find all this totally pointless, because there's just no way for a
                          compiler to check if your code is logically correct.
                          But it's enough if the called method exists and returns the correct
                          type. At least it prevents a crash.
                          >
                          Then providing an appropriate default in the base class is enough
                          too.
                          Only working *if* there is a base-class, and not only convention for
                          should-have-methods.
                          >That's the point. Interfaces garantee that a duck is a duck, an
                          >not only a chicken that quack.
                          >
                          Who cares if it's a chicken as long as it quacks when you ask her
                          to ? Now *This* is the whole point of chicken^Mduck typing, isn't
                          it ?-)
                          Ducks can also swim and fly. And if you need a really duck,
                          >
                          If you're code expects something that quacks, swims and flies,
                          anything that quacks, swims and flies is ok. You just don't care if
                          it's a duck or a flying whale with a quacking device tied to it.
                          Not the point.
                          Of course, in the practical world that all doesn't matter. But in
                          the theoretical world of the big coding farms, called business,
                          that's one cornerstone of success, in the tinking of managers and
                          so.
                          >
                          Sorry, I live in a very practical world - and we're by no mean
                          running out of business here...
                          Like i said.

                          Comment

                          • Rhamphoryncus

                            #28
                            Re: Am I missing something with Python not having interfaces?

                            On May 9, 1:53 pm, Daniel Marcel Eichler <onsen-n...@gmx.netwro te:
                            Am Freitag 09 Mai 2008 10:19:45 schrieb Bruno Desthuilliers:
                            >
                            >very often sees do-nothing catch-all try/catch blocks in Java -
                            >which is way worse than just letting the exception propagate. I
                            >find all this totally pointless, because there's just no way for a
                            >compiler to check if your code is logically correct.
                            >
                            But it's enough if the called method exists and returns the correct
                            type. At least it prevents a crash.
                            The application has already failed. You'd prefer it silently do the
                            wrong thing than get an explicit error message and stop?

                            >>That's the point. Interfaces garantee that a duck is a duck, an
                            >>not only a chicken that quack.
                            >
                            >Who cares if it's a chicken as long as it quacks when you ask her
                            >to ? Now *This* is the whole point of chicken^Mduck typing, isn't
                            >it ?-)
                            >
                            Ducks can also swim and fly. And if you need a really duck,
                            >
                            If you're code expects something that quacks, swims and flies,
                            anything that quacks, swims and flies is ok. You just don't care if
                            it's a duck or a flying whale with a quacking device tied to it.
                            >
                            Not the point.
                            It really is. They're only going to give you something they expect to
                            work. They might occasionally make a mistake and give you garbage,
                            but it's not worth the effort of trying to catch it early.

                            Comment

                            • Pete Forman

                              #29
                              Re: Am I missing something with Python not having interfaces?

                              I would suggest that using an interface at compile time is not the
                              only approach. Unit tests can be run on classes to check that they do
                              indeed quack.
                              --
                              Pete Forman -./\.- Disclaimer: This post is originated
                              WesternGeco -./\.- by myself and does not represent
                              pete.forman@wes terngeco.com -./\.- the opinion of Schlumberger or
                              http://petef.22web.net -./\.- WesternGeco.

                              Comment

                              Working...