octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OOP and load/save


From: Judd Storrs
Subject: Re: OOP and load/save
Date: Fri, 24 Apr 2009 12:43:25 -0400

On Thu, Apr 23, 2009 at 1:44 PM, Robert T. Short <address@hidden> wrote:
Dumb structs is a little unfair.  Now mind you, not all that far off, but a bit harsh.  There are lots of limitations, but I have done some very nice things.  The biggest problem is having lots of little m-files around that are all three-liners, but every change to the basic structure requires modifying a bunch of little files.

When I said 'dumb' I didn't mean it as a criticism. What I meant to convey is that I don't think structs and classes are really different at all. The mental model I've developed over the years working with matlab and IDL structs and OOP is that Matlab structs and classes are essentially exactly the same thing. The differences boil down to how the interpreter dispatches functions and what restrictions are placed on member access. A struct-flavored object has no access member restrictions and defers all function calls. A class-flavored object has a protected layout, restricts member access in certain scopes, and can hijack function search if it's the first arguement in a call. From that perspective it seems unnatural to treat objects and structs as two different animals because and object is a struct and a struct is an object. That's all I meant.

In IDL (interactive data language), the situation is similar except there is also a third flavor. Structures in IDL can be either "anonymous" or "named". The interpreter keeps track of "named" structures the same way Matlab keeps track of "class" structures. Anonymous structures are what matlab's structures are -- you can add and remove components whenever you want. Named structures are a hybrid -- once the first named struct is created you cannot change the number, names or types of its members without clearing the interpreter's memory (Matlab doesn't enforce type--I just checked). In IDL classes are built over named structures.


--judd


reply via email to

[Prev in Thread] Current Thread [Next in Thread]