PDA

View Full Version : fireworks and fuses


mikka
05-19-2007, 07:16 AM
Compared to usual object-oriented languages, there are some simplifications in Alice that pose certain restrictions on the expressiveness of the language.

One restriction is, that arguments of methods can only be of simple type, not objects.

There are some simple mechanisms, to extend the expressiveness while keeping the language simple and safe.

The concept of “delegates” (found in C# and Delphi) allows to connect objects indirectly on the event level.
Delegate objects combine one receiver object and one of its methods.
The delegate (type) declares the signature (argument list) of the method.

An object S can declare a variable as a (“multi-cast”) “event” for a delegate type D.
A single event variable can hold an arbitrary number of delegate objects.
The language provides basic operations to add or remove a delegate object to / from the event variable.

Object S can trigger the event by calling the event variable with the required arguments. This has the effect that all the delegate objects that are in the event variable are executed, i.e. the method is called on the receiver object with the arguments of the event call.

[The notion “delegate” is not very meaningful for kids, because it is kind-of tech-speak. A word with could be used to describe the mechanism with an impressive picture would be “bomb” (or “firework”). The event variable could then be called the “trigger” (or “fuse”).]

What do you think? Would some "firework" bring more power and excitement to Alice programming?

DickBaldwin
05-19-2007, 12:18 PM
You wrote:

"Compared to usual object-oriented languages, there are some simplifications in Alice that pose certain restrictions on the expressiveness of the language.

One restriction is, that arguments of methods can only be of simple type, not objects."

====================

The second statement above is incorrect. You can pass parameters as type Object as well as about a dozen other abstract types to methods.

The restriction is that when you pass a parameter as type Object, you cannot cast the parameter to a subclass of the type Object in order to gain access to methods, functions, and properties belonging to a subclass.

Dick Baldwin

DrJim
05-19-2007, 08:50 PM
Won’t try to get into a discussion of “objects,” “classes” etc. in Alice vs. the “ususal” object oriented languages – will leave the “fireworks” to others. :D

I will note that you can effectively pass a sub-object with a method call – it has to be passed as a combination of an object name and a string as per the attached and the method has to use the “<object>’s part named <string>” function block (see attached).

This does appear to be a fairly robust approach - as long as the full name for the part exists, there seems to be no restriction on what object or sub-object “owns” the method. It can also be quite useful, although the lack of restrictions and the multiple naming conventions used for objects in the Alice Gallery can make using it a bit tricy.

(An earlier set of e-mails discussed the “<object>’s variable named <variable name>” block which seems similar. However, to me at least, that construct is not particularly useful. I'd like to know if anyone else has figured out an effective way to use that. :confused: )