Minimal JS Hello World

381 views
Skip to first unread message

Nicolas Cannasse

unread,
Jun 4, 2012, 11:16:56 AM6/4/12
to haxe...@googlegroups.com
Hi,

With the latests patches (r4771+), the JS output for a
trace("Hello World") simple class is now the following :

-----
var $_;
var Test = function() { }
Test.main = function() {
console.log("Hello World");
}
Test.main();
-----

(don't forget compile with --dead-code-elimination !)

This required quite important changes in the JS code generator, some
testing might be require to ensure that we didn't break anything !

Best,
Nicolas

fintan boyle

unread,
Jun 4, 2012, 11:23:41 AM6/4/12
to haxe...@googlegroups.com
I was hopeful that maybe hello world in haxe js would be <50 lines by the end of the summer!  I have to revise my expectations :-)

brilliant

Mihail Ivanchev

unread,
Jun 4, 2012, 11:25:40 AM6/4/12
to haxe...@googlegroups.com
That's awful lot of code, it takes 3 minutes to parse in the webkit browser of Android 2.3.5. Back to the drawing board!

Philippe Elsass

unread,
Jun 4, 2012, 11:31:53 AM6/4/12
to haxe...@googlegroups.com

I suppose you're back to 200 lines as soon as you use reflection.
And with one iterator?

Nicolas Cannasse

unread,
Jun 4, 2012, 11:41:03 AM6/4/12
to haxe...@googlegroups.com
Le 04/06/2012 17:31, Philippe Elsass a �crit :
> I suppose you're back to 200 lines as soon as you use reflection.
> And with one iterator?

You're welcome to make your own tests ;)

As for iterator it depends, most of the for...in should not add any
overhead.

Best,
Nicolas

clemos

unread,
Jun 4, 2012, 11:43:34 AM6/4/12
to haxe...@googlegroups.com
Hi Nicolas,

I've updated try-haxe:
http://try-haxe.aaaliasing.net/

It seems to break when you only use externs.
(js is not defined...)
which breaks my example :p

Cheers
Clément

On Mon, Jun 4, 2012 at 5:16 PM, Nicolas Cannasse
<ncan...@motion-twin.com> wrote:

Franco Ponticelli

unread,
Jun 4, 2012, 11:49:33 AM6/4/12
to haxe...@googlegroups.com
@Nicolas: Amazing!

clemos

unread,
Jun 4, 2012, 12:00:19 PM6/4/12
to haxe...@googlegroups.com
PS:
On a slightly un-related topic, reading this change:
http://code.google.com/p/haxe/source/detail?r=4769
I was planning to file a issue about that,
but I would rather expect the opposite, @:runtime becoming the default
behaviour...
inline members would always have their runtime counterpart (to go
along well with Reflect by default, for instance)
these could eventually be removed by --dead-code-elimination
and kept using @:keep.

What do you think ?

Cheers,
Clément

Nicolas Cannasse

unread,
Jun 4, 2012, 12:10:16 PM6/4/12
to haxe...@googlegroups.com
Le 04/06/2012 17:43, clemos a �crit :
> Hi Nicolas,
>
> I've updated try-haxe:
> http://try-haxe.aaaliasing.net/
>
> It seems to break when you only use externs.
> (js is not defined...)
> which breaks my example :p

Fixed in r4773, thanks for the report ;)

Best,
Nicolas

Nicolas Cannasse

unread,
Jun 4, 2012, 12:12:03 PM6/4/12
to haxe...@googlegroups.com
Le 04/06/2012 18:00, clemos a �crit :
> PS:
> On a slightly un-related topic, reading this change:
> http://code.google.com/p/haxe/source/detail?r=4769
> I was planning to file a issue about that,
> but I would rather expect the opposite, @:runtime becoming the default
> behaviour...
> inline members would always have their runtime counterpart (to go
> along well with Reflect by default, for instance)
> these could eventually be removed by --dead-code-elimination
> and kept using @:keep.
>
> What do you think ?

@:runtime require explicit support in the backend. For instance in genJS
we will replace all potential accesses to .iterator by $iterator() call
that will add a runtime type check for Array.

I'm not sure we want to generalize such tricks.

Best,
Nicolas

clemos

unread,
Jun 4, 2012, 12:21:40 PM6/4/12
to haxe...@googlegroups.com
On Mon, Jun 4, 2012 at 6:12 PM, Nicolas Cannasse
<ncan...@motion-twin.com> wrote:
Mh I didn't read it was about extern methods, so I think I don't
really get what @:runtime is about...

Still, about "normal" inline methods,
I just tested, and it appears that (in JS at least) inline methods are
created just like normal methods.
That's a good behaviour, but as these method are very likely to be
unused, I'd expect them to be removed when using DCE.

Do you want me to file a report for that ?

BTW I updated try-haxe to latest SVN.

Regards,
Clément

clemos

unread,
Jun 4, 2012, 12:27:29 PM6/4/12
to haxe...@googlegroups.com
On Mon, Jun 4, 2012 at 6:10 PM, Nicolas Cannasse
<ncan...@motion-twin.com> wrote:
> Le 04/06/2012 17:43, clemos a écrit :
>
>> Hi Nicolas,
>>
>> I've updated try-haxe:
>> http://try-haxe.aaaliasing.net/
>>
>> It seems to break when you only use externs.
>> (js is not defined...)
>> which breaks my example :p
>
>
> Fixed in r4773, thanks for the report ;)

Thanks,
Same thing for js.SWFObject...
I didn't test with other externs yet, but...
are we supposed to add this @:initPackage everywhere ?
:S

Regards,
Clément

Nicolas Cannasse

unread,
Jun 4, 2012, 12:44:13 PM6/4/12
to haxe...@googlegroups.com
Le 04/06/2012 18:21, clemos a �crit :
> On Mon, Jun 4, 2012 at 6:12 PM, Nicolas Cannasse
> <ncan...@motion-twin.com> wrote:
>> Le 04/06/2012 18:00, clemos a �crit :
>>
>>> PS:
>>> On a slightly un-related topic, reading this change:
>>> http://code.google.com/p/haxe/source/detail?r=4769
>>> I was planning to file a issue about that,
>>> but I would rather expect the opposite, @:runtime becoming the default
>>> behaviour...
>>> inline members would always have their runtime counterpart (to go
>>> along well with Reflect by default, for instance)
>>> these could eventually be removed by --dead-code-elimination
>>> and kept using @:keep.
>>>
>>> What do you think ?
>>
>>
>> @:runtime require explicit support in the backend. For instance in genJS we
>> will replace all potential accesses to .iterator by $iterator() call that
>> will add a runtime type check for Array.
>>
>> I'm not sure we want to generalize such tricks.
>
> Mh I didn't read it was about extern methods, so I think I don't
> really get what @:runtime is about...

Yes, it's only to prevent printing an error saying that the method is
actually not present at runtime.

> Still, about "normal" inline methods,
> I just tested, and it appears that (in JS at least) inline methods are
> created just like normal methods.
> That's a good behaviour, but as these method are very likely to be
> unused, I'd expect them to be removed when using DCE.
>
> Do you want me to file a report for that ?

Oh I thought it was done already, it's now fixed in r4776

Best,
Nicolas

Nicolas Cannasse

unread,
Jun 4, 2012, 12:46:29 PM6/4/12
to haxe...@googlegroups.com
Le 04/06/2012 18:27, clemos a �crit :
> On Mon, Jun 4, 2012 at 6:10 PM, Nicolas Cannasse
> <ncan...@motion-twin.com> wrote:
>> Le 04/06/2012 17:43, clemos a �crit :
>>
>>> Hi Nicolas,
>>>
>>> I've updated try-haxe:
>>> http://try-haxe.aaaliasing.net/
>>>
>>> It seems to break when you only use externs.
>>> (js is not defined...)
>>> which breaks my example :p
>>
>>
>> Fixed in r4773, thanks for the report ;)
>
> Thanks,
> Same thing for js.SWFObject...
> I didn't test with other externs yet, but...
> are we supposed to add this @:initPackage everywhere ?
> :S

Well, the "js" package was always created by js.Boot before, and it's no
longer the case :)

Fixed for both remaining cases.

Best,
Nicolas



clemos

unread,
Jun 4, 2012, 12:54:44 PM6/4/12
to haxe...@googlegroups.com
I updated to latest SVN,
now the example is only 11 lines :)
http://try-haxe.aaaliasing.net/
I've also cleaned a bit the presentation since it appears the word is
already spread... :S
https://plus.google.com/113704686911055424796/posts/hFsL4bpTmzK

Cheers,
Clément

On Mon, Jun 4, 2012 at 6:44 PM, Nicolas Cannasse
<ncan...@motion-twin.com> wrote:

Franco Ponticelli

unread,
Jun 4, 2012, 12:56:35 PM6/4/12
to haxe...@googlegroups.com
@clemos, quick feature request: put the build status also below the code output ... I like to see the generated code (and errors) without having to switch back to the normal output. Thank you for the effort ... eager to see how it evolves!

clemos

unread,
Jun 4, 2012, 1:44:31 PM6/4/12
to haxe...@googlegroups.com
Hi,

I did it and added some info...

Regards,
Clément

Nicolas Cannasse

unread,
Jun 4, 2012, 1:45:47 PM6/4/12
to haxe...@googlegroups.com
Le 04/06/2012 18:54, clemos a �crit :
> I updated to latest SVN,
> now the example is only 11 lines :)
> http://try-haxe.aaaliasing.net/
> I've also cleaned a bit the presentation since it appears the word is
> already spread... :S
> https://plus.google.com/113704686911055424796/posts/hFsL4bpTmzK

Just got rid of var $_ in r4780 ;)

Best,
Nicolas

Joshua Granick

unread,
Jun 4, 2012, 1:46:00 PM6/4/12
to haxe...@googlegroups.com
Nice!

Good work :)


On Mon, 04 Jun 2012 10:45:47 -0700, Nicolas Cannasse
<ncan...@motion-twin.com> wrote:

Franco Ponticelli

unread,
Jun 4, 2012, 1:51:01 PM6/4/12
to haxe...@googlegroups.com
Thank you very much, appreciated! ... another suggestion: add SHIFT+ENTER (or any other combo) to CodeMirror to trigger the Run action. It is very useful to avoid switching from keyboard to mouse ;)

clemos

unread,
Jun 4, 2012, 1:55:49 PM6/4/12
to haxe...@googlegroups.com
Disclaimer:
I'm (still...) not trying to compete with FlashDevelop
;)

Regards,
Clément

On Mon, Jun 4, 2012 at 7:51 PM, Franco Ponticelli

Franco Ponticelli

unread,
Jun 4, 2012, 1:56:33 PM6/4/12
to haxe...@googlegroups.com
I know ... just throwing ideas ... feel free to ignore such suggestions ;)

Andreas Mokros

unread,
Jun 4, 2012, 2:36:30 PM6/4/12
to haxe...@googlegroups.com
Hi.

On Mon, 04 Jun 2012 19:45:47 +0200
Nicolas Cannasse <ncan...@motion-twin.com> wrote:
> Just got rid of var $_ in r4780 ;)

Really great work, folks!
But Reflect.field gets not included...

@Nicolas: Did you see the bug, when compiling haxelib?

--
Mockey

Hudson Ansley

unread,
Jun 4, 2012, 2:41:09 PM6/4/12
to haxe...@googlegroups.com
Wow, this is really impressive now getting that hello-world example
down to 10 lines (will be after Nicolas' last fix ;-)
and the js code is much less confusing this way also...
Regards,
Hudson

ps - just to make sure it was not going to bloat with something
slightly more complicated, this 11 line code only grows to 20

class Test {
  public static function main(){
    var str;
    var bodyHtml = "";
    var praise = ["amazing", "great", "time-saving", "coding joy"];
    for (str in praise) {
      bodyHtml += "Haxe is "+str+" :)<br>";
    }
  new js.JQuery("body").html(bodyHtml);
  }
}

Philippe Elsass

unread,
Jun 4, 2012, 4:49:10 PM6/4/12
to haxe...@googlegroups.com
Looks like there's a bug in the metas generation.

When using Std.is(v,T) I see in the code: 
Test.__name__ = true;

instead of the usual:
Test.__name__ = ["Test"];


BTW I see trace() is nicely compiled as console.log(), but there isn't a sanity check for browsers not having a console - if it's undefined a do-nothing fallback should be created.

  }
}




--
Philippe

Nicolas Cannasse

unread,
Jun 4, 2012, 6:04:43 PM6/4/12
to haxe...@googlegroups.com
Le 04/06/2012 22:49, Philippe Elsass a �crit :
> Looks like there's a bug in the metas generation.
>
> When using Std.is(v,T) I see in the code:
> Test.__name__ = true;
>
> instead of the usual:
> Test.__name__ = ["Test"];

Yes it's normal. There are cases when we need to know if it's a Class
(has __name__), without needing the full name.

> BTW I see trace() is nicely compiled as console.log(), but there isn't a
> sanity check for browsers not having a console - if it's undefined a
> do-nothing fallback should be created.

As soon as you use haxe.Log.trace (for example by rebinding it) it will
use it instead of console.log

Best,
Nicolas

Nicolas Cannasse

unread,
Jun 4, 2012, 6:05:37 PM6/4/12
to haxe...@googlegroups.com
Le 04/06/2012 20:36, Andreas Mokros a �crit :
> Hi.
>
> On Mon, 04 Jun 2012 19:45:47 +0200
> Nicolas Cannasse<ncan...@motion-twin.com> wrote:
>> Just got rid of var $_ in r4780 ;)
>
> Really great work, folks!
> But Reflect.field gets not included...

? uh ?

> @Nicolas: Did you see the bug, when compiling haxelib?

Yes, looks quite tricky, tomorrow maybe.

Best,
Nicolas
Reply all
Reply to author
Forward
0 new messages