Saturday, July 29, 2006

Mynx 'in' operator or .isKindOf like Java's instanceof

One design consideration in Mynx is for an instanceof for Java, or is for C#, an operator or method that checks whether an instance of an object is a type or kind of class. But, Java' s instanceof operator checks only if an object is an instance of a class...such as:

Java:

if(myObject instanceof String)
{

}


C#:

if(myObject is String)
{

}


but in Mynx the operator 'in' determines like instanceof, but also allows object instance to object instance, like:


if(myObject in String) //check if myObject instance of a String class

end if;


or


if(myObject in obj) //check if myObject same reference/pointer to obj

end if


The design question is to allow the 'in' operator to check among instance objects are type-class compatible, and if it is more efficient to simply use a method instead of an operator. This is more flexible than Java's instanceof operator, but through the object hierarchy can create a method that is inherited like "isEqual" but "isKindOf" method. The virtual class (Mynx has no interfaces) VObject would have the form:


virtual class VObject as Void is

     Bool isEqual(VObject);
     Bool isKindOf(VObject);
 
     overload constant == as isEqual;

end class;



The major difference between "isEqual" and "isKindOf" is that equality is the same object reference or two objects of the same class in the same state, whereas kind of means objects are type-compatible or have a common ancestor or super-class in the class hierarchy. Also, the equality check "==" operator is overloadable, whereas the "in" operator cannot be overloaded.

Using an operator has the advantage of syntactic neatness...something Java's syntax in comparison to say C++ or C# is no match in expressivity because of lack of operator overloading. The drawback does not apply to the "in" operator -- determining at compile-time which operator is associated with a method of the class and translating for the method call.

Labels: , ,

Wednesday, July 26, 2006

Language Author Beard Pattern

The "Language Author Beard Pattern" is best re-stated as "Language Creator/Designer Beard Pattern" a very amusing notion that programming language designers who have a beard (does stubble or a 5 o'clock shadow count??) have more successful programming language. The article is an amusing read to say the least.

Since I'm usually clean shaven (except when I get in my creative funk and forget to shave, or am just downright lazy and skip a day without the razor) by the language author beard pattern Mynx will not be as successful. Oh, and the magic 8-ball told me so too...but that won't stop me having come this far and being driven by other motives beyond the vague notion of programming language "success" (which is? -- having a certain threshold of programmers/developers writing in it, number of different compilers, count of code examples? what is the metric for "success" of a programming language?)

I outline my motives for Mynx in the Mynx Book. One that is unstated is to have fun, if creating a programming language like writing a book or poem is fun...intellectual fun to create and bring something unknown into reality.

Programming languages are like poems and poetry, they are the means of expressing the ubiquitous...for me it is the poem of poetry that is my expression like Picasso, van Gogh, Henry Moore, or Mapplethorpe (gasp!).

Labels: ,

Thursday, July 20, 2006

Mynx Constructor Design Semantic Considerations

For Mynx I'm working out the semantics regarding class elements, and one has me going in two directions -- the constructor.

Mynx has 3-basic parameter passing modes (all by reference):

1. in - non-null passed, object reference immutable
2. out - nullable possible to pass, object reference can change
3. var - non-null passed, object reference can change
4. series - non-null, passed, object reference immutable

Note that all objects are not primitives, even the basic types are objects.

For a constructor, my thinking is the semantic constraint that only in parameters are passed to create and initialize an object instance.

Example toy class in Mynx, toy.mynx  :


    class Toy is
 
       public construct(in String str, in Char chr) is
          !! do something here !!
       end construct;

       public construct(out Bool bl) is
           bl = Bool.True;
       end construct;
 
    end class;


The idea is to avoid any parameter changes within the constructor, its sole purpose is to create and initialize an object instance -- changing or creating a new instance within and altering a passed argument is semantically incorrect. But...is it?
Another point is a constructor is to initialize a new instance, passing an object out would be returning a value, something a constructor does not do.

Consider the Mynx code fragment:

    Bool flag to null;
    Toy ty to null; //declare a toy instance but null reference

    ty as Toy("hello","c"); //pass in literals -- semantically ok

    ty is null;

    ty as Toy(flag); //pass boolean -- semantically ok??


The first constructor invocation passed literals, which are immutable, and the parameter mode are both in-parameters, so semantically valid. The second construtor invocation a Bool object for a boolean flag is passed into the constructor, so a boolean value is returned -- semantically valid or invalid??

This semantic concern is reminiscent of Pascal's ability to pass procedures or functions as parameters which created a semantic loop-hole...although I'm leaning towards semantically strict, but want to give a developer some "wiggle room".

One other possibility is to use a factory method that explicitly returns values as parameters, and/or an "initialize" method to allow returning parameters that are created or changed -- but the constructor cannot implicitly do it.

Note: I've decided to go with 'in' style const immutable parameters that cannot be changed, a constructor should take parameters and create (or duh, construct...) a new class instance. Looking at C++, the copy constructor takes an immutable instance of the same class and creates a copy of it, but the passed parameter is not changed. So C++ copy constructor semantics are in line with Mynx constructor.

Labels: , ,

Monday, July 17, 2006

Mynx Programming Language Design and Development Blog--First Post

Hello!

I'm William Gilreath, a software engineer/computer scientist and I've created an object-oriented programming language called "Mynx" with its own website. But I'm in the process of formalizing the semantics of the language...what is valid Mynx source code and what is not. To that end, I'm going to put my design thoughts and ideas in a blog, hopefully to encourage interest, participation, and share with other programming language connoisseurs.

Get a taste of Mynx by downloading and perusing the programming language manual as a PDF. Cheers!

Labels: ,

Website Spy Software