Feedback on Future Language Features: Optional Structure Fields

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Feedback on Future Language Features: Optional Structure Fields

John A. De Goes

  Below is my feedback on future language features, taken from: http://haxe.org/com/features

2. Optional structure fields. The proposal is to allow optional  
structure fields. e.g.:

        function foo( init : { ?x : Int, y : Int } ) {
                ...
        }

This is an excellent idea. Currently I must pass 'null' in many places  
because some data is optional.

This proposal would greatly simplify such code, and also enable new  
kinds of APIs -- for example, a jQuery-like API that does type-
checking on CSS properties:

jQuery('#foo').css(
     {
         backgroundImage: "foo.jpg"
     }
)

Currently it's possible to make a similar API using Dynamic, but the  
result is not type safe.

Summary: Excellent feature that is well overdue and will eliminate  
boilerplate code and enable more type safe APIs.

Regards,

John

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Feedback on Future Language Features: RTTI

John A. De Goes

Below is my feedback on future language features, taken from: http://haxe.org/com/features

4. Runtime typing information. The proposal is to allow anyone to  
specify the keyword 'rtti' when defining a class or enum, to embed run-
time typing information. e.g.:

        rtti enum E {
                ....

        }

In my opinion, RTTI needs revamping with a proper object-oriented  
design. I would also favor the C++ way, which is to either globally  
enable RTTI or globally disable RTTI (preferably automatically -- if  
no RTTI feature is used, then no overhead is necessary).

In summary, my opinion is that this proposal is a hack and that we  
should not add a new keyword into the language to support it. Can we  
imagine the 'rtti' keyword existing in Haxe 5 years from now??? It's  
better not to encourage code to depend on a hack.

Regards,

John

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Feedback on Future Language Features: RTTI

gershon
From the same page:
"It should also be possible to replace the current XML format by some native format by using directly haXe data structures to construct the RTTI informations."

Could these structures be used with the reflection api?
so that a call to Reflect.fields() could return all those values...

i'm looking to do something similar to:

var functions = [];
for(f in Reflect.fields(o))
 if(Reflect.isFunction(f))  {
  var a = [];
  for(a in Reflect.fields(f))
  a.push(Reflect.field(f, a));
  functions.push({
    function: f,
    arguments: a
   });
  }

for(f in functions)
  Reflect.callMethod(o, f.function, f.arguments);

but of course Reflect.fields() only returns fields that have been set with reflection, nothing from compile time, which rtti has...


On Wed, Sep 9, 2009 at 6:52 PM, John A. De Goes <[hidden email]> wrote:

Below is my feedback on future language features, taken from: http://haxe.org/com/features

4. Runtime typing information. The proposal is to allow anyone to specify the keyword 'rtti' when defining a class or enum, to embed run-time typing information. e.g.:

       rtti enum E {
               ....

       }

In my opinion, RTTI needs revamping with a proper object-oriented design. I would also favor the C++ way, which is to either globally enable RTTI or globally disable RTTI (preferably automatically -- if no RTTI feature is used, then no overhead is necessary).

In summary, my opinion is that this proposal is a hack and that we should not add a new keyword into the language to support it. Can we imagine the 'rtti' keyword existing in Haxe 5 years from now??? It's better not to encourage code to depend on a hack.

Regards,

John
--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org