Hi, everyone! As I'm working on AngelScript 2.0 I'm finding it necessary to take certain decisions, some are easier than others. Right now I've come upon one that is not so easy to take on my own. With AS 2.0 every object is stored by reference (sort of like a smart-pointer). Thus if you assign an object variable to another both variables will hold references to the same object. My doubt is what I should do with the operators for objects. Alternative 1 will have operators for assigning and comparing object references, but will not allow overloading of operators to make it easier to use objects in expressions. Advantages: Simpler language hence smaller library, and easier interface. Disadvantages: Clumsier to write code with many operations on objects. Function calls instead of operators.
// Declare object variable
obj a = new obj();
// assign reference
b = a;
// copy object value
b.Copy(a);
// comparison of the reference
a == b;
// Add two objects
a.Add(b);
// Compare the value of the objects
a.Compare(b);
Alternative 2 will have special operators for assigning and comparing references, and will allow overloading of operators for normal objects. Advantages: Cleaner syntax where objects are included in expressions. Disadvantages: More complex language, and more complex library and interface.
// Declare object variable
obj a := new obj();
// assign reference
b := a;
// copy object value
b = a;
// comparison of the reference
a === b;
// Add two objects
a + b;
// Compare the value of the objects
a == b;
I also have a third alternative. Which would allow the application to register primitive objects. Primitive objects are classes that only hold primitive values, i.e. it doesn't need a destructor or special assignment operators to manage resources. These primitive object could be stored by value instead of by reference, just like normal primitives like int, float, etc. The library could allow operator overloading only for this type of object. It would then be easy to write special datatypes like Vector3, Point2D, that allows use of operators in expressions. Other objects that need the special management are passed around by reference and don't allow overloaded operators. Advantages: Allows the creation of new primitive types in the language, while still allowing the use of references. The language will still be easy to use. Disadvantages: More complex library. Let me hear what you think. And if you have suggestions for other alternatives I'm also interested in hearing those. Personally I'm leaning towards alternative 2.