in reply to Re: Help with Metaclasses
in thread Help with Metaclasses

Don't think this is the same thing what the OP is talking about.

To be frank, Perl does not provide the metaclass as provided in Python. Class:Struct is nothing more than a way to define a c-alike struct, which Perl lacks of (and I doubt we really need, with OO there. With OO, even c++ no longer needs struct as c did).

"In C++ genericity is covered by templates. In perl, that sort of thing is far less necessary because of no static typing."

That is again nothing close to Python's metaclass. The template concept in C++, in simply a patch to the language, so that it can provide the powerful STL, to match up with java's utility classes.

In Java, it has whole bunch of utility classes, like Vector, Hashtable..., their elements are all simply declared as Object, which is everything and anything. C++ does not have this Object class, so it came up this template concept, which allows you to define things like LinkedList just once for whatever kind of element, and just resolve it at compilation time.

However it is still not the same as in Java. Once you say something like LinkedList<int>, all the elements in that linked list are now nothing else but int. But in Java, it is not the same case, a Java Hashtable can contain anything, and element 0 can be of class BLAH, when element 1 might be of class YAHOO.

A Perl hash or array has the similar nature as java's hahtable etc., however because of different reasons: in java, it is becasue of the Object base class; in Perl, it is not because of the UNIVERSAL base class, but becasue Perl is not a "strong type" language.

Replies are listed 'Best First'.
Re^3: Help with Metaclasses
by tall_man (Parson) on Oct 19, 2004 at 22:57 UTC
    The template concept in C++, in simply a patch to the language, so that it can provide the powerful STL, to match up with java's utility classes.

    Ahem. Templates were proposed for C++ in 1990, STL was developed in 1993, and Java was publicly announced by Sun in 1995.

    Java's classes like Vector are a type-unsafe, limited set of containers (for example, they can contain Object, but not int). I suspect they were a hack that came about because Java lacked templates. Now Java 5.0 has a version of templated containers at last.

    Back on the subject of perl metaprogramming, it could be done if desired. You can create code templates to be evaled at runtime. The Template toolkits are sometimes used this way. Also Inline::C and friends can generate wrapper code at runtime and call it.