Re: Classes: A small proposal

new topic     » goto parent     » topic index » view thread      » older message » newer message

>I don't really expect Robert to latch onto the dot notation [i.e.:
object.function()], because it's just "syntactic sugar" - it's essentially a
different way of writing something, without adding any new functionality.
But OOP seems like something that would be a good thing to add native to
Euphoria, now that Robert's gearing up to code another major version.

Well I dunno, the fact is, you can't emulate Euphoria in any OOP language,
but you can do the other way around. Like you said before also, it should
live in harmony with normal euphoria code. Be like an extension.
I still believe in the ultimate preproccesing language through. Which is
based upon context. I dunno, it stills sounds a bit radical. It sounds like
most of my suggestions for Euphoria I made in the beginning.
(integer/sequence/atom/etc. is just a choice of interpretation of some data,
why not make the choice ourselves.. was one of my ideas.. more than
logically it wasn't followed blink)

But about OO native to Euphoria or by use of a lib or preproccesor (you
could built something like that inside EE).
All our OOP implementations can only inherit from one other class.
Lets keep it that way. Multiple inheritmens make spagetti code, I can not
understand why this is included in oo. It's such a hack (i know.. the word
'hack' is my new tick) to make up for the restrictions.

>Nice code - even documentation! blink

Oops, I forgot a few routines..

These are also included:

boolean =   compare_class (classx, classy)

Returns -1 if classy was possibly based upon classx, 0 is they are different
or equal, 1 if classx was possible inhereted by classy.

It is not about the values inside the object. Compared are the function
pointers for type checking of each attribute.
'Possibly' because it only means that all attributes types of one class are
all also at the same place in the other class. (the other class only has new
attributes added to them)
If they are equal or different a zero is returned.

boolean = equal_class (classx, classy)

Tells you if they are equal or not. Not their values, but the function
pointers of the attributes, the attribute types thus.

Thus if you want to know if they can be related in a way:

if compare_class (classx, classy) or equal_class (classx, classy) then
    -- They are either related
end if

You can also restore the values in an class.

classx = restore_class (classx, superclass)

This only works if classx is related and equal or more than superclass.
It will copy the values in superclass to classx, only for those attributes
they have in common. (so only the new added attributes at the end are
copied, because there will be no copying when they do not relate)

boolean = try_attrib (class_x, attribute_y, 5)

Will return true if you can assing 5 to attribute_y on class_x, false if you
can't!

I also didn't mention:

Custom types and V-types can be used like this:

my_class[my_attribute]

Methods like this:

my_class = call_func(my_class[my_attribute],{my_class, other_arguments})

Procedures:

call_proc (my_class[my_attribute],{my_class, other_arguments})

Functions: (Do not store their value into the class!! They can not modify
the class, use a Method for that instead!)

returnvalue = call_func (my_class[my_attribute], {my_class,
other_arguments})

You can find routines to acces functions, methods, procedures and values,
but is that really needed ??
I think people have a better understanding what went right/wrong when they
do this themselves.

--[extra documentation]

>By my count, that makes four contributions for Euphoria OOP extentions:
>
>1. Francis Bussiere's (from *way* back when)
>2. Irv's (in Windoz)
>3. My own (in WinMan)
>4. Yours [Ralf's].

Well, the old one by Francis Bussiere doesn't even use routine pointers.
And yours and Irv's are backed in your code.
The reason I wrote this is because I couldn't strap neither your or Irv's
code.
Not to have another flavor (althrough like everybody, I'm convienced my
approuch is the best, I guess its just a personal taste.)

>Everyone but me seems to use type checking on their OOP attributes. I guess
I'll cave and add some to my package, too.

Well, developping NGL I found it was very hard to trace errors back.
Now I use crash_message () a lot, so you really see what went wrong.
A custom attribute type can also use this, by setting the global sequence
error_message. It will be used in the total error message displayed on the
screen.
And I added a oop_trace (1), which instead of generation a type check error
turns tracing on, however it does display the error message on the screen.
And trace is turned off in oop.e so the trace screens displays your code
only.

>> It is what I am using for NGL.
>
>I can hardly wait. Your prior blurb looked very interesting. Will it
support VGA as well?

Well, like I said it is a bridge. All video modes in Euphoria will be
enabled.
But all the code and thinking is about the fact that you can "plug-in" a
device.
You can fastly create a video device for NGL.
In fact only having an routine to open the video mode and one to put a pixel
on the screen is enough.
The rest is then emulated using the pixel routine.
But if you think you can do it faster, you can overwrite any of the extended
drawing commands.
(Command is a definition of a routine iD, ASM-Code or DLL-Link that NGL uses
to make the fastest command list possible)

>[Dot Notation]
>is cool even without it being OOP. I liked it so much, I went ahead and
wrote a pre-processor. It's called Dot, and is on the Euphoria Web page. The
latest version (sent in this morning) can be used in EE in place of PP - not
that I expect anyone to really latch onto it.

Well, if you combined PP & Dot, added color-syntaxing for them and put it on
as default, many people might use. I know I will. Especially the slice looks
a lot more clear.

>As I mentioned, it's not OOP - but you can certainly combine it with an OOP
package.

Yes, append () and slice () can be considered attributes of the class
sequence and thus available to any class
based upon a sequence. (Which class isn't based on seqs??)

Ralf Nieuwenhuijsen
nieuwen at xs4all.nl

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu