• andy (unregistered) in reply to JohnO
    JohnO:

    Anonymous:

    An object is indeed defined as an instantiation of a class, but since every class is also an instantiation of a class, every class is also an object.  QED.

    You obviously failed logic, assuming you took it.  Your assumption that every class is also an instantiation of a class is WRONG.  F-.

    At some point in your chain, you have either a class that is purely a construct, call it GOD that is not defnined within your supposedly neat little view of the world.  It could be meta, or meta-meta, or meta-meta-meta, but it's there.


    In UML the meta-meta model (Class, Association, etc) references itself, so that it can instantiate itself to create the meta-model (The classes you define). Next you instantiate your model to get  the objects. See OMG MOF specification for more details about metamodelling.

    There are a number of object modeling concepts that appear at two, three, or even
    four levels in a well populated MOF metadata framework. For example, a class in a
    UML is described by an instance of the class “Class” in the UML metamodel. This
    is in turn described by an instance of the class “Class” in the MOF Model. Finally,
    the class “Class” in the MOF Model is described by itself. This overloading of
    names of concepts often confuses people.

  • (cs) in reply to Uncle Bacon
    Anonymous:
    A while back, a co-worker couldn't get inner queries to work properly. He was trying something like:

    select CustomerID from (SELECT CustomerID FROM Customers)

    • and not having much success. You should have seen the look on his face when I changed it to:

    select CustomerID from (SELECT CustomerID FROM Customers) Please

    • which ran first time. :)


    I enjoyed that one, that's pretty funny  ... I will have to remember that next time some forgets to use an alias and needs help.

  • (cs) in reply to andy
    Anonymous:

    In UML the meta-meta model (Class, Association, etc) references itself, so that it can instantiate itself to create the meta-model (The classes you define). Next you instantiate your model to get  the objects. See OMG MOF specification for more details about metamodelling.

    I'm not sure what your point is. So the meta-meta model is a collection of meta-objects that can instantiate itself and also instantiate objects?  And this ends the debate how?

     

  • (cs) in reply to Richard Nixon

    Not sure what you mean Richard Nixon.  One of us is misunderstanding the other, I think, since it sounds like you're confused between Otto and The Simplifier.  I was kind of replying to both Otto and The Simplifier, which I suppose wasn't obvious from my post.  I would have quoted, but I've kind of given up on quotes on this site.  Sorry about that.

  • (cs) in reply to JohnO

    Does this mean that we were all wrong?  It's not just objects.  It's not just classes and objects.  It's just meta-meta models?

  • Bonds - steroids = me (unregistered) in reply to Anonymous
    Anonymous:
    And yet... you're wrong.  Classes are indeed objects.  No matter how you twist and turn it.  Everything's an object.  Why do you think they call it object-oriented programming and not object-and-class-oriented-programming...

    Allow me to convince you using a Smalltalk example.
    Let's take an instance of a string, namely 'hi'.  now check out 'hi' class.  This gives us the 'class' ByteString.  Now let's see what the class of ByteString is...  It's the ByteString class- class.  And the ByteString class-class is an instance of the MetaClass class, which in turn is an instance of   the MetaClass class-class...  And, believe it or not, this is an instance of... the MetaClass class!


    I hate this convoluted, symantical arguing. The point is that an object is an instantiation of a class, but a class is itself an object, sure. But the class IS NOT THE SAME AS THE OBJECT! You even said it above. ('class' bytestring).

    If you don't think so, check out this:

    http://java.sun.com/docs/books/tutorial/java/concepts/class.html

    Objects versus Classes

    You've probably noticed that the illustrations of objects and classes look very similar. And indeed, the difference between classes and objects is often the source of some confusion. In the real world, it's obvious that classes are not themselves the objects they describe; that is, a blueprint of a bicycle is not a bicycle. However, it's a little more difficult to differentiate classes and objects in software. This is partially because software objects are merely electronic models of real-world objects or abstract concepts in the first place. But it's also because the term object is sometimes used to refer to both classes and instances.

    In illustrations such as the top part of the preceding figure, the class is not shaded because it represents a blueprint of an object rather than the object itself. In comparison, an object is shaded, indicating that the object exists and that you can use it.



    or maybe even this for smalltalk:

    http://linuxgazette.net/issue60/steffler.html
    So the question naturally arises, what is 'Person'?  Thinking in terms of nouns, a Person is a specific class or subset of nouns.  Well, in Smalltalk Person is an object too, but it's a special kind of object that is called a class.  You can think of a class as a blueprint object for making related objects.  When we ask a class to make a new instance of an object, it's called instantiating an object.  Now, coming back to the properties of an object, they are stored in what are called instance variables of the object4.  When we were asking aPerson for their height, they probably responded with what they had stored in their instance variable (we don't know for sure, as we don't know how the person determines their height).


    Notice how it is defined as a 'special' object. That is why there is a distinction made when people are taught about OO. If you just went and said "classes and objects are the same", no one would ever get it. It needs to be made clear that classes and objects are different (or a class is a special object, not the instantion of itself, but the defintion of the instantiated object).


    An object is indeed defined as an instantiation of a class, but since every class is also an instantiation of a class, every class is also an object.  QED.


    I am starting to think that you know just enough to be dangerous. Which object is the class object? if you were to inspect it, what would it be? That is why it is special and different. Get it?


  • (cs) in reply to ammoQ
    ammoQ:
    Mikademus:
    Messing a bit with Alex's post:
    Alex Papadimoulis:

    Public Structure UserInformation
      Shared intUserID As Integer
      Shared strUserID As String
    End Structure

    Isn't trwtf here that VB's compiler doesn't let through the above? In C++ this compiles w/o any complaints:

    class Test
    {
        static int a;
        static int b;
    };

    Yes, it is just a dumb way to reinvent namespaces, but I see not real implementation reason to disallow this kind of constructs.


    AFAIK, VB would compile it if it was a "Class" instead of a "Structure".


    Seriously?! Now that is the real WFT!
  • (cs) in reply to The Simplifier
    Anonymous:


    Is there really any data problem out there that needs more than plain old C?



    According to Turing Completeness, no (http://en.wikipedia.org/wiki/Turing-complete).  However, there are lots of problems that are more easily solved in other languages.  That's why people write new languages, after all.




  • (cs) in reply to ammoQ
    ammoQ:
    Assuming they really just wanted a bunch of global variables "somehow" tied together, what would be the correct way to do ist?

    I think you could do it with Javascript.
  • David Morton (unregistered) in reply to wintermyute
    wintermyute:
    The real WTF here is the phrase "VB-deprived".


    No, he simply mispelled "depraved".
  • (cs) in reply to warispeace
    Anonymous:


    Is there really any data problem out there that needs more than plain old C?


    Just do everything in BrainF***.  It's Turing complete and you only have to learn eight characters.

    Or (to keep theme with the code) try INTERCAL.  It's Turing complete as well as very polite, and if you read INTERCAL code out loud it could pass for poetry at some of the more esoteric coffee shop readings.

    Someday...I will need to code something that is best done in INTERCAL.
  • (cs) in reply to Xargon
    Xargon:
    Anonymous:


    Is there really any data problem out there that needs more than plain old C?


    Just do everything in BrainF***.  It's Turing complete and you only have to learn eight characters.


    Why not enjoy a text adventure?  http://jonripley.com/brainfuck/games/

    Sincerely,

    Gene Wirchenko

  • (cs) in reply to masklinn

    This reply is not a real reply it's a metareply-- a metareply describing the previous real reply, a reply that is a pattern of a reply, a reply factory if you want.

  • (cs) in reply to Uncle Bacon

    Anonymous:
    A while back, a co-worker couldn't get inner queries to work properly. He was trying something like: select CustomerID from (SELECT CustomerID FROM Customers) - and not having much success. You should have seen the look on his face when I changed it to: select CustomerID from (SELECT CustomerID FROM Customers) Please - which ran first time. :)

    That's the funniest thing I've seen all day. I hope I get to do that to someone one day...

  • Just Another WTF (unregistered) in reply to Xargon

    Xargon:
    Anonymous:


    Is there really any data problem out there that needs more than plain old C?


    Just do everything in BrainF***.  It's Turing complete and you only have to learn eight characters.

    Or (to keep theme with the code) try INTERCAL.  It's Turing complete as well as very polite, and if you read INTERCAL code out loud it could pass for poetry at some of the more esoteric coffee shop readings.

    Someday...I will need to code something that is best done in INTERCAL.

    I refuse to program anything major in BrainF*** until they have a .NET version with a form designer...

    Anybody working on Visual BrainF***?

  • (cs) in reply to Just Another WTF
    Anonymous:
    I refuse to program anything major in BrainF*** until they have a .NET version with a form designer...

    Anybody working on Visual BrainF***?

    You're not satisfied with a simple BrainF*** .NET compiler?

    http://bluesorcerer.net/esoteric/bf.html

  • (cs) in reply to Xargon
    Xargon:
    Anonymous:
    I refuse to program anything major in BrainF*** until they have a .NET version with a form designer...

    Anybody working on Visual BrainF***?

    You're not satisfied with a simple BrainF*** .NET compiler?

    http://bluesorcerer.net/esoteric/bf.html



    An IDE can be found here:

    http://www.4mhz.de/bfdev.html

    Unfortunately, it's not .net, but with those 2 tools, it should be easy to create great .net programs!
  • (cs) in reply to ammoQ
    ammoQ:
    It should be mentioned in the "class vs object" discussion that OO languages exist which have no concept of "class", but use "prototype objects" instead - a new "instance" is rather a clone of the "prototype object"; inheritance is done by adding new fields and/or methods to an object etc.

    Indeed. I've written some pretty cool "OO" stuff in JavaScript, which is prototype-based. Methods of the prototype are the equivalent of static in C#.

    [waits to get flamed for using (gasp!) JavaScript...]
  • (cs) in reply to John Smallberries
    John Smallberries:
    ammoQ:
    It should be mentioned in the "class vs object" discussion that OO languages exist which have no concept of "class", but use "prototype objects" instead - a new "instance" is rather a clone of the "prototype object"; inheritance is done by adding new fields and/or methods to an object etc.

    Indeed. I've written some pretty cool "OO" stuff in JavaScript, which is prototype-based. Methods of the prototype are the equivalent of static in C#.

    [waits to get flamed for using (gasp!) JavaScript...]


    Well, there's using JavaScript and there's ABusing JavaScript. For the former, see Doug Crockford's place ( http://www.crockford.com/javascript ). For the latter, well, there's a whole webfull of crap out there, ain't there?
  • Rubber Baron (unregistered) in reply to masklinn
    masklinn:
    Anonymous:
    pjsson:

    According to OO design everything is an object, including program and classes (often called meta objects). Maybe it was you who didn't get it...


    I am not sure what you mean by this, but an object is the instantiation of the class. You can think of everything at runtime as an object (though technically not correct, it won't really harm you much), but the class really is different.


    Nope, a class is an object too, a metaobject to a regular object, an object that is a pattern of an object, an object factory if you want.

    And that's why people invented metaclasses, which are in fact the classes of classes (and you can instantiate a class from a metaclass, and then instantiate a regular object from the class instanciated from the metaclass).

    What pjsson tells you is that in OO design everything is an object, there is no "but" and no "except", it's everything period.

    Now we do understand that Java does not have a clue, and doesn't understand that a class is an object, or a method is an object, etc (this is actually false BTW, you can manipulate java classes and methods as first class objects through java.lang.Class and java.lang.reflect.Method, but it's kind of awkward and I don't think java has metaclasses), but try to check languages such as Smalltalk, Python or Ruby and you'll see all kinds of wonders such as functions and methods being first-class object (e.g you can define one, pass it around, send it another method/function's argument, return one from a function, ...), classes being first-class objects as well, metaclasses (still first-class objects), ...

    A class is not "different", it's an object and an object factory, that's all there is to it.

    A class is a definition, a classification of things, eg: Dog. They are not the objects themselves, the concrete representation of the classification Dog, eg: Rover. You can also have abstract classes, eg Unicorn, that has no concrete representation, it is an abstract class. Object !eqv Class.

  • (cs) in reply to Rubber Baron
    Anonymous:
    A class is a definition, a classification of things, eg: Dog. They are not the objects themselves, the concrete representation of the classification Dog, eg: Rover. You can also have abstract classes, eg Unicorn, that has no concrete representation, it is an abstract class. Object !eqv Class.


    Sorry, but "Unicorn" is a bad example for an abstract class. From an abstract class, you should be able to inherit a non-abstract class. But every instance of a class that inherits from "Unicorn" would also be a "unicorn"...
    "Mammal" might be an abstract class; no animal is a direct instance of "mammal"; but rather an instance of e.g. "dog" instead.
    Anyway, when it comes to analogies with animals, prototype-base OO languages are better suited to closely model the reality.
  • Lars Clausen (unregistered) in reply to cconroy
    cconroy:
    <font size="2">"Don't know why, but..."-type comments are great.  They say, "Hey, there's some kind of problem here, but at least I got it working.  Good luck fixing it the right way after I've been fired/downsized/promoted to management!"
    </font>


    Or they say "Hey, there's a really strange problem here, which my deadline doesn't give me time to fix properly.  This kludge can get the product out there in time so that the company doesn't go under."  For why fixing everything the right way isn't necessarily good, see the Mars project (http://www.computer-dictionary-online.org/Mars.htm?q=Mars) or Worse is Better (http://www.dreamsongs.com/WorseIsBetter.html).

    -Lars
  • MikeA (unregistered) in reply to beest
    Anonymous:
    Anonymous:
    pjsson:
    LuciferSam:

    Maybe it was the way it was taught to me, but OO design didn't seem that hard.  I know people who graduated in my class that didn't know the difference between a class an object and a program.  That frightens me.



    According to OO design everything is an object, including program and classes (often called meta objects). Maybe it was you who didn't get it...


    Just because X is a Y does not mean that there is no difference between X and Y.




    Thanks for pointing that out. Concrete example of the logic being used in above argument:

    A Corvette is a car.
    A Pinto is a car.
    Both Corvettes and Pintos are cars.
    There is no difference between Corvettes and Pintos.
    QED


    Not precisely the same argument.  A better one would be:

    An apple is a fruit.
    There is no difference between apples and fruits.
  • (cs) in reply to MikeA
    Anonymous:
    Anonymous:
    Anonymous:
    pjsson:
    LuciferSam:

    Maybe it was the way it was taught to me, but OO design didn't seem that hard.  I know people who graduated in my class that didn't know the difference between a class an object and a program.  That frightens me.



    According to OO design everything is an object, including program and classes (often called meta objects). Maybe it was you who didn't get it...


    Just because X is a Y does not mean that there is no difference between X and Y.



    Thanks for pointing that out. Concrete example of the logic being used in above argument:

    A Corvette is a car.
    A Pinto is a car.
    Both Corvettes and Pintos are cars.
    There is no difference between Corvettes and Pintos.
    QED



    Not precisely the same argument.  A better one would be:

    An apple is a fruit.
    There is no difference between apples and fruits.

    OO and UML have made the word "IS" even more ambiguous and confusing. I'd like to see UML and OO people handle the following:

    <FONT face=Verdana size=2>Consider the following phrases (from Martin Fowler on classification and Generalization):

    1. Shep is a Border Collie.
    2. A Border Collie is a Dog.
    3. Dogs are animals.
    4. A Border Collie is a Breed.
    5. Dog is a species.</FONT>

    <FONT face=Verdana size=2>1+2 = shep is a dog. Ok
    1+2+3 = Shep is an animal. Ok
    2+3 = A Border Collie is an animal. Ok
    1+4 = Shep is a Breed. Huh?
    2+5 = A Border Collie is a species. Huh?
    1+2+5 = Shep is a Species. Huh?</FONT>

    <FONT face=Verdana size=2>I remember some person proposed eliminating the verb "to be" from the english language because of all the trouble. Sometimes for fun I do that when I make posts. I find that the exercise makes me think more, write less, and write more politely / humbly.

    </FONT>
  • (cs) in reply to Richard Nixon

    Richard Nixon:

    It's a shame Otto doesn't want to cite sources he's going to copy and paste from.

    Citing is unnecessary to those who have mastered the Tao.

     

  • Just Another WTF (unregistered) in reply to ammoQ
    ammoQ:
    Xargon:
    Anonymous:
    I refuse to program anything major in BrainF*** until they have a .NET version with a form designer...

    Anybody working on Visual BrainF***?

    You're not satisfied with a simple BrainF*** .NET compiler?

    http://bluesorcerer.net/esoteric/bf.html



    An IDE can be found here:

    http://www.4mhz.de/bfdev.html

    Unfortunately, it's not .net, but with those 2 tools, it should be easy to create great .net programs!

    I can see the potential here... BFdev is for the Win32 personality of BrainF*** and the as yet undeveloped Visual Studio plugin would be for fully managed BrainF***

  • gdrimes (unregistered) in reply to ammoQ

    The real wtf is that 127 people responded and no one took the time to try it out.

    Perhaps that is because VB programmers don't read thedailywtf. The wtf as stated is barely a wtf itself.

    What really happens, is that VB.NET won't let you define a structure unless at least one of the members is non-shared (non-static).

    However, if one or more members are non-shared, it actually works as it says (as the coder found out from the VB error message). The shared (static) members are indeed shared amongst all objects created and the non-shared members become instance variables for the created object.

    If the original programmer wanted to have the whole structure as shared, (s)he should have declared all the structure members as non-shared and then when using the structure (which is only a definition anyway - like a class) declare it as: "Shared UserInfo As UserInformation". It appears that the 'sharedness' is inherited from the structure definition.

    But the REAL wtf is that C# doesn't have the same restriction as VB.NET and allows a struct to be defined with all static members. Same company, same framework, different results.

  • Fester BesterTester (unregistered) in reply to pjsson

    A "class" doesn't become an "object" until it is instantiated. Until you call a constructor a "class" is simply a blueprint for an "object".

    But maybe I am splitting hairs?

  • (cs) in reply to Fester BesterTester

    Anonymous:
    A "class" doesn't become an "object" until it is instantiated. Until you call a constructor a "class" is simply a blueprint for an "object".

    But maybe I am splitting hairs?

    Don't tell that to a singelton. Or to a class with a private constructor and static members.

  • Nobody (unregistered) in reply to Fester BesterTester

    In Python (and in SmallTalk too, I think), you're wrong...

    If we take this simple class: "class SomeClass(object): pass"

    then isinstance(SomeClass, object) == True

    So, SomeClass is an object.

  • (cs) in reply to Nobody
    Anonymous:
    A "class" doesn't become an "object" until it is instantiated. Until you call a constructor a "class" is simply a blueprint for an "object".

    But maybe I am splitting hairs?

    Nah, you're just wrong. A class is an object in the first place, an object that generate objects (the instances of the class) via the constructor call. But there is no reason for a class not to be an object itself, it can be an instance of the "class" or "type" metaclass for example, which is the class of a class. And this "class" or "type" metaclass is itself of type "class" or "type" (it's it's own type/class), and it inherits from the "object" type/class at the root of the language's object hierarchy.

    Now most languages don't expose the metaclass level, and the ones that do don't always make it easy to work with it (metaclass hacking is kind of a black magic. Ruby makes it quite easy to do though, it's much harder in python for example), and as a result some languages don't even give access to classes and functions/methods as first-class objects (or in a convoluted way, see Java). But they still are.

    Anonymous:
    In Python (and in SmallTalk too, I think), you're wrong...

    If we take this simple class: "class SomeClass(object): pass"

    then isinstance(SomeClass, object) == True

    So, SomeClass is an object.

    In Python, Smalltalk and Ruby at least, I think Common Lisp's CLOS also has classes-objects and metaclasses (which seems reasonable since everything in lisp is data, and code is data, and data is code, and the parentheses will burn your eyes and screw your brain).

    And to go even further than your example:

    >>> class Foo(object):
    	pass
    

    >>> foo = Foo() # instanciation >>> type(foo) <class 'main.Foo'> >>> type(Foo) <type 'type'> # Foo is an instance of 'type', which is the base metaclass >>> Foo.mro # method resolution order of class Foo (<class 'main.Foo'>, <type 'object'>) # The ony parent class of Foo is object >>> type(type) <type 'type'> # type is also a type >>> type.mro (<type 'type'>, <type 'object'>) # The only parent class of type is also type >>> type(object) <type 'type'> # And 'object' is a type BTW >>> object.mro (<type 'object'>,) # but it's the root of the inheritance hierarchy

    Same thing in Ruby

    >> class Foo
    >> end
    => nil
    >> foo = Foo.new # Ruby-style instantiation
    => #<Foo:0x354fb28>
    >> foo.class
    => Foo # That one's obvious
    >> Foo.class
    => Class # The class of a class is Class
    >> Foo.ancestors
    => [Foo, Object, Kernel]
    >> Class.class
    => Class # but the class of the Class metaclass is still Class
    >> Class.ancestors
    => [Class, Module, Object, Kernel]
    >> Object.class
    => Class # An object is of type Class
    >> Object.ancestors
    => [Object, Kernel]
    >> Kernel.class
    => Module
    >> Kernel.ancestors
    => [Kernel]
    >> Module.class
    => Class
    >> Module.ancestors
    => [Module, Object, Kernel]

    As you can see, the basic Ruby object model is a bit more complex than python's, but there is a common characteristic: it's recursive and every type or meta-type is an instance of a unique base metaclass ("Class" in Ruby)

    I barely know smalltalk and don't know the CLOS at all so I can't give you any example for them.

    A class is an object that can somehow create other objects (an object factory), that's all there is to it. That's especially clear in Ruby where instantiation doesn't use any syntactic sugar, merely the call of a public method of the class (that would translate into a public static method of a Java class)

  • (cs) in reply to gdrimes
    Anonymous:
    The real wtf is that 127 people responded and no one took the time to try it out.
    ...
    But the REAL wtf is that C# doesn't have the same restriction as VB.NET

    You're confusing me; what is the really real wtf?

    Anonymous:
    What really happens, is that VB.NET won't let you define a structure unless at least one of the members is non-shared (non-static).

    If the original programmer wanted to have the whole structure as shared, (s)he should have declared all the structure members as non-shared and then when using the structure (which is only a definition anyway - like a class) declare it as: "Shared UserInfo As UserInformation". It appears that the 'sharedness' is inherited from the structure definition.

    That is seriously a huge wtf: that the staticness of members can be modulated by instantiation prefixes. So, two more bizarre things about VB's class handling to my list: (1) you cannot instantiate "structures" with only static members but "class"es are OK (there's no programmatical reason to forbit this (admittably unnecessary) practice, and the distinction between structures and classes seems arbitrary); and (2) if "structures" are like classes then being allowed to change the staticness of members by instantiation prefixes would violate the original composition architecture.

  • (cs)

    As for this whole <var>intUserID</var> vs. <var>strUserID</var> debate, did no one else notice that he's already got two string variables there for the user name/ID?


    Alex Papadimoulis:

    Public Structure UserInformation
    Shared intUserID As Integer Shared strUserID As String
    Shared
    Username As String Shared Realname As String Shared Token As String 'Don't know why we need this, but won't compile without it Public PleaseCompile As Boolean
    End Structure



    I'd agree with whoever guess that the two UserID variables are just for convenience.
  • (cs) in reply to BACON

    Hey, where'd my bold text go?  My whole point is ruined by formatting!

    I'd meant to highlight "Shared strUserID As String" and "Shared Username As String".

    Wow, I should post more.  This comment system really is worthy on the incessant complaining.  I'm just kind of sad that it didn't mangle the quote in my previous post so I could give the obligatory "Hey, what happened?"...

  • (cs) in reply to BACON
    BACON:
    Hey, where'd my bold text go?  My whole point is ruined by formatting!

    I'd meant to highlight "Shared strUserID As String" and "Shared Username As String".



    On my browser, I can see the bold text. In thise case, the real wtf&tm; is not the forum software, but your browser.
  • (cs) in reply to ammoQ

    Well, no.  My second post wasn't self-referential.  The (lack of) bold text I was referring to was actually in my initial post where I quoted Alex.  I meant to embolden those two variable declarations but that didn't seem to show up in what actually got posted.

    Though I'm not inclined to blame Firefox for the forum's woes, this all seems to stem from my not being able to switch between the "Design" and "HTML" tabs on the comment form after a while.  The tabs and the actual content of the textbox got out of sync, and it looks like all the changes I made after that point were lost (such as changing the word "guess" to "guessed").  So, I really don't know if that's Firefox's fault or not, but...well, which seems more plausible: the forum being buggy or the browser being buggy?  If I were using IE maybe I'd see your point...

  • (cs) in reply to masklinn
    masklinn:
    Anonymous:
    A "class" doesn't become an "object" until it is instantiated. Until you call a constructor a "class" is simply a blueprint for an "object".

    But maybe I am splitting hairs?

    Nah, you're just wrong. A class is an object in the first place, an object that generate objects (the instances of the class) via the constructor call. But there is no reason for a class not to be an object itself, it can be an instance of the "class" or "type" metaclass for example, which is the class of a class. And this "class" or "type" metaclass is itself of type "class" or "type" (it's it's own type/class), and it inherits from the "object" type/class at the root of the language's object hierarchy.

    Now most languages don't expose the metaclass level, and the ones that do don't always make it easy to work with it (metaclass hacking is kind of a black magic. Ruby makes it quite easy to do though, it's much harder in python for example), and as a result some languages don't even give access to classes and functions/methods as first-class objects (or in a convoluted way, see Java). But they still are.

    Anonymous:
    In Python (and in SmallTalk too, I think), you're wrong... If we take this simple class: "class SomeClass(object): pass" then isinstance(SomeClass, object) == True So, SomeClass is an object.

    In Python, Smalltalk and Ruby at least, I think Common Lisp's CLOS also has classes-objects and metaclasses (which seems reasonable since everything in lisp is data, and code is data, and data is code, and the parentheses will burn your eyes and screw your brain).

    And to go even further than your example:

    >>> class Foo(object):
    	pass
    

    >>> foo = Foo() # instanciation >>> type(foo) <CLASS ?main.Foo?> >>> type(Foo) <TYPE ?type?> # Foo is an instance of 'type', which is the base metaclass >>> Foo.mro # method resolution order of class Foo (<CLASS ?main.Foo?>, <TYPE ?object?>) # The ony parent class of Foo is object >>> type(type) <TYPE ?type?> # type is also a type >>> type.mro (<TYPE ?type?>, <TYPE ?object?>) # The only parent class of type is also type >>> type(object) <TYPE ?type?> # And 'object' is a type BTW >>> object.mro (<TYPE ?object?>,) # but it's the root of the inheritance hierarchy

    Same thing in Ruby

    >> class Foo
    >> end
    => nil
    >> foo = Foo.new # Ruby-style instantiation
    => #<?XML:NAMESPACE PREFIX = Foo /><Foo:0x354fb28>
    >> foo.class
    => Foo # That one's obvious
    >> Foo.class
    => Class # The class of a class is Class
    >> Foo.ancestors
    => [Foo, Object, Kernel]
    >> Class.class
    => Class # but the class of the Class metaclass is still Class
    >> Class.ancestors
    => [Class, Module, Object, Kernel]
    >> Object.class
    => Class # An object is of type Class
    >> Object.ancestors
    => [Object, Kernel]
    >> Kernel.class
    => Module
    >> Kernel.ancestors
    => [Kernel]
    >> Module.class
    => Class
    >> Module.ancestors
    => [Module, Object, Kernel]

    As you can see, the basic Ruby object model is a bit more complex than python's, but there is a common characteristic: it's recursive and every type or meta-type is an instance of a unique base metaclass ("Class" in Ruby)

    I barely know smalltalk and don't know the CLOS at all so I can't give you any example for them.

    A class is an object that can somehow create other objects (an object factory), that's all there is to it. That's especially clear in Ruby where instantiation doesn't use any syntactic sugar, merely the call of a public method of the class (that would translate into a public static method of a Java class)

     

    Please remember that OO is all smoke and mirrors.  Objects and classes are just things that are designed to make it easier for us to write maintainable programs.  Is there a real difference between the concept of a class truely being a meta-object and the concept of the language simply simulating that meta-object for the benefit of the person at the keyboard?  If you think about it, then the difference comes down to "how was the complier built".  If it was built in C, then it's all pretend.  If it was written in SmallTalk, then it was intended that way.  Since for nearly all modern languages the compiler is built in the actual language, it is what it is.

    Example:  I write some code in MicroChip PIC assembler.  It has about 35 instructions, no floating point operations - single byte integer math only.  While writing in assembler, I work under a lot of restrictions and my mindset is to keep things very simple.  I write in assembler to keep code small and to deliver a solution that works fast on a very cheap part.  While writing for the same system in C, suddenly I can call functions, do floating point math, use string variables.  Nothing has really changed, the language and compiler simply make a lot of magic happen for me.  It doesn't matter which of these environments I consider "true", truth is in the language spec.

    More food for thought:  In most languages, a virtual function is implemented as a simple jump function that jumps to the current implementation.  If that is overloaded in a child class, the jump function is replaced with a jump to the child implementation and any calls to the base class functionality call the old jump address.  That is highly non-object oriented, but that is how things have to get done.  Processors don't support objects or inheritance and if they did, it would be at a high level and would need a concrete implementation that was procedural.</Foo:0x354fb28>

  • President Leechman (unregistered) in reply to masklinn
    masklinn:
    What pjsson tells you is that in OO design everything is an object, there is no "but" and no "except", it's everything period.
    So the most OO language is ECMAscript?
  • President Leechman (unregistered) in reply to John Smallberries
    John Smallberries:
    Indeed. I've written some pretty cool "OO" stuff in JavaScript, which is prototype-based. Methods of the prototype are the equivalent of static in C#.
    I'd hug you but I'm covered in leeches from my last evil scheme that went awry.
  • (cs) in reply to President Leechman
    Anonymous:
    masklinn:
    What pjsson tells you is that in OO design everything is an object, there is no "but" and no "except", it's everything period.
    So the most OO language is ECMAscript?

    Even though it's lacking in many areas, and the prototype-based object model is extremely cumbersome and annoying to work with, ECMAScript is an extremely OO language indeed (and the prototype-based OO makes the classes fully open in a Ruby fashion, allowing the user/programmer to modify the various built-in types such as Array or String by extending them through new methods).

    On the other hand, I'm not sure you could point at a language and say "this is the most OO" (what arguments would you use in the first place, besides "everything is an object with no exception period" which many languages feature atm), and even if you could it would probably be Smalltalk.

  • M (unregistered) in reply to wintermyute

    wintermyute:
    The real WTF here is the phrase "VB-deprived".

    You are absolutley right, should say "blessed" instead of "VB-deprived".

  • (cs) in reply to tmountjr

    Hmm. A guy in the third-year of our CompSci degree course wrote some Pascal code which went a bit like this:

    /* Read input file to count the letters and words. Stop when . is read. */

    program Assignment(input,output)

    int lettercount, wordcount;
        char ch;
        boolean done;

    begin
    lettercount = 0;
    wordcount=0;
    done=false;

    repeat
        read(ch);
        if (ch== ' ') then
            wordcount = wordcount +1;

        lettercount = lettercount + 1;
    until done;
    end.

    He came to ask for help because it wasn't stopping when he typed .

     

  • Merlin (unregistered) in reply to Trevor Raynsford
    Trevor Raynsford:

    Hmm. A guy in the third-year of our CompSci degree course wrote some Pascal code which went a bit like this:

    (snip...)

    He came to ask for help because it wasn't stopping when he typed .



    Third-year? Are you sure it wasn't a three-year-old instead? ;-)

Leave a comment on “Please Compile”

Log In or post as a guest

Replying to comment #:

« Return to Article