Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Apparently, constructors aren't inherited in Java. Yeah, I had to check several references before believing that.

    You should spend more time working with staticly typed languages. It would be a "very bad thing" for a staticly typed language to inherit a constructor (you'd have a nasty case of memory corruption). If you think that is odd, you should take C++ for a spin. Member functions are not virutal by default. Or better yet, try writing OO-C sometime (no, not with glib. Take the time to actually setup the data structures required to implement virtual functions yourself). It'll give you a much better appriciaition for the power and flexibility provided by dynamic languages. In fact, here's a short example of an OO-C "class", including a simple virtual function implementation...

    typedef struct _MyClass MyClass ;

    struct MyClass_vtbl
    {
      void (*MyClass__dtor)(MyClass*) dtor ;
    } ;

    struct _MyClass
    {
      struct MyClass_dtor* mp_vtbl ;
      int m_memberVar ;
    } ;

    void MyClass__dtor_body(MyClass* self) ;
    #define MyClass_dtor(self) (((self)->mp_vtbl->dtor)(self))
    There you have the *minimum* quantity of declaration for a tiny class with a single virtual member function. We haven't even got around to actually *implementing* the function, yet. When you start throwing in things like interitance, and making sure you get clean, warning-free compiles even with C++ compilers, look out.

    Add to that the strict method signature checking, the requirement that constructors have the same name as the class, and you could find yourself (as in the first example in this article) declaring several constructors that meticulously gather arguments and call super() with them.

    This is "normal" for the vast majority of programmers. In fact, pretty much anyone with a CS degree will spend the vast majority of their undregraduate years working with staticly typed languages. To them, the fact that Perl allows (and encourages) the inheritance of constructors is a bizzare thing. I 100% agree that for the vast majority of programming tasks, raw speed and/or memory efficiency is such a non-issue that it makes a lot of sense to take advantage of the expressive power provided by dynamic languages. However, there are still a large number of tasks that really need to sit closer to the hardware so that developers can squeeze more performance (e.g., video encoding, decoding, device drivers, many embedded systems). This is why I think Inline::C is so damned cool. It allows people to easily write performance critical portions of applications in C, but make use of the expressive power of Perl for the remaining 90%. Gosling forbid a language should reduce busywork.

    This I agree with. Java has all of the performance overhead of a dynamic language, and virtually none of the benefit.
    • It would be a "very bad thing" for a staticly typed language to inherit a constructor (you'd have a nasty case of memory corruption).

      Is this because of memory allocation or method dispatch or something else I'm missing? I realize that allocation in C++ is tricky, but that's so rarely a concern in Java...

      • Part of the problem with constructors in staticly typed languages is that the compiler determines the size, and offset of every member at compile time. Think C structs. One of the reasons why you have to #inlude headers is so that the compiler can properly calculate the size of any structs you may be using.

        The compiler keeps track of a base address and offset of class members (e.g., the struct/class starts at address 0xDEADBEEF and the m_udder member has an offset of 6 bytes). In static languages, the comp