Could you give some practical examples ?
BEst,
Nicolas
If you really think about the code, you will see that `(x != x)` only
ever applies for NaN, which is the whole point of this substitution.
In the haXe standard library, the return type of charCodeAt is
Null<Int> (whereas in JS it's Number, if it were defined).
From what I can tell haXe overwrites two builtin functions, which are
substr and charCodeAt. If I count correctly, that is two and that is
commonly considered lesser than "so many" ;)
And slower.
Best,
Nicolas
Regards
Simon
The issue is that the default String.charCodeAt returns NaN when reading
outside of the string, which requires it to be typed as Float if we want
to be able to check it with Math.isNaN, which means you can no longer
use things such as myArray[myString.charCodeAt(0)] (you need to add an
necessary Std.int).
In that particular case, haXe is fixing a broken API.
Best,
Nicolas
It is considered not-okay for any framework in the JavaScript
community to overwrite any basic
prototype (Array, etc. included)
So: Imho. the best way would be to replace the use of the haXe
"standard" method at compile time with a entirely different
methodcall.
"test".charCodeAt(); -> hx.StringShim.charCodeAt("test");
yours
Martin
On Dec 17, 3:34 pm, Niel Drummond <niel.drumm...@grumpytoad.org>
wrote:
> That makes sense, thanks for the explanation.
>
> - Niel
>
> On Sat, Dec 17, 2011 at 7:01 AM, Nicolas Cannasse <ncanna...@motion-twin.com
>
>
>
>
>
>
>
> > wrote:
> > Le 16/12/2011 22:14, Niel Drummond a écrit :
>
> > Can you mention an environment where String.charCodeAt does not exist,
> >> before making a big fuss about it ?
>
> >> - Niel
>
> > The issue is that the default String.charCodeAt returns NaN when reading
> > outside of the string, which requires it to be typed as Float if we want to
> > be able to check it with Math.isNaN, which means you can no longer use
> > things such as myArray[myString.charCodeAt(0)**] (you need to add an
The way it is now, haXe breaks a holy taboo of the JS community. But
realistically speaking, I fail to see an actual problem here. So I can
only repeat Nicolas: Can you give some practical examples, where this
is a problem?
As I have mentioned above, the two calls in question are
String::charCodeAt, which effectively alters the behaviour, and
String::substr, which actually just enforces the standard as far as I
can tell (Chrome will give you the same behaviour if you comment it
out). So as I see it, there is exactly one case, where haXe alters the
behaviour to something unexpected.
The ultimate question is not whether haXe does something "evil", but
whether this really has perceivable effects in practical scenarios.
Short of those, your point is valid, but irrelevant, because at the
current state, haXe makes a small incision at great benefits for haXe
and no known effects for JavaScript code.
@Nicolas: I've just checked (Chrome, FF, IE8), isNaN(undefined) seems
to be true in fact, as is undefined == null, so returning undefined in
charCodeAt might actually make this change unperceivable for JS
developers.
Also, as an alternative, the two "fixes" might be surrounded in #if
!no_js_fix #end, so hardliners could simply decide not to use them.
greetz
back2dos
Ah, interesting. I've made the change.
> Also, as an alternative, the two "fixes" might be surrounded in #if
> !no_js_fix #end, so hardliners could simply decide not to use them.
Yes, I am looking for a solution to do the same with all "injected"
methods.
There's not a lot but still few of them :
- Array.copy/insert/iterator/remove (added)
- String.charCodeAt/substr (modified)
- Function.bind (used by JS code generator)
- Date.now/fromTime/fromString/__class__/__name__ (added)
- Date.toString (modified)
Of course, in that case this would break all accesses either directly
from JS or when the type is Dynamic.
Best,
Nicolas
Le 19/12/2011 12:57, Juraj Kirchheim a écrit :Yes, I am looking for a solution to do the same with all "injected" methods.
There's not a lot but still few of them :
- Array.copy/insert/iterator/remove (added)
- String.charCodeAt/substr (modified)
- Function.bind (used by JS code generator)
- Date.now/fromTime/fromString/__class__/__name__ (added)
- Date.toString (modified)
Of course, in that case this would break all accesses either directly from JS or when the type is Dynamic.
Or what if someone includes a JS library that changes one of the base
String.prototype (et al) methods? Now that library may have broken haXe
runtime (and probably more - see first point).
That's why it's taboo to overwrite native methods in JS.
Aside: I'm actually curious about how all of this runs with "use
strict"; do you guys test with that?
Kevin N.
This seems to be a hypothetical scenario. As before, practical
evidence is called for.
> Or what if someone includes a JS library that changes one of the base
> String.prototype (et al) methods? Now that library may have broken haXe
> runtime (and probably more - see first point).
What's your point? I can break jQuery, by including a JS library, that
changes jQuery's methods. I can break anything and everything. Trying
to make this hard for me will only lead to accidents like Java, where
nothing is breakable, because nothing works to start with.
To quote Flon's Law:
There does not now, nor will there ever exist, a programming
language in which it is the least bit hard to write bad programs.
> That's why it's taboo to overwrite native methods in JS.
I think we all know the reasons why this is a taboo. As pointed out,
there is a lack of practical evidence, that they apply here.
> Aside: I'm actually curious about how all of this runs with "use strict"; do
> you guys test with that?
I seriously doubt haXe output will pass JSLint.
JSLint is intended to be "The JavaScript Code Quality Tool". Code
means "source code" here. From a haXe perspective, JavaScript is not
source code, but machine language, as from a GWT or Dart or
Parenscript or CoffeeScript perspective.
More importantly, JSLint is not part of the standard, but just the
holy grail of the fanatic fraction in the JS community. It has just as
many opponents. Ext, jQuery and many other major libraries do not pass
JSLint, even though they are JavaScript source code libraries.
I only speak for myself, but I don't think haXe should or will bend to
religious beliefs in the JavaScript community, which include the
mandatoryness of passing JSLint or the total taboo of overwriting
native methods.
The haXe community is of course free to do as they like - but haXe will
not likely get broader use in the web-dev community with that principle
in place.
/2cents
Kevin N.
@Nicolas
Just a thought: Why not just change the API documentation of haxes
String.charCodeAt() to: "In JavaScript it returns NaN and in other
Environments null". Every developer accessing that system will then
have to sanitize their code their code with #if js
That would remove the need to "fix" the API, the size of the generated
js would be smaller and it would be clear that this particular API is
different in different systems. As this breaks your "write-once-
deploy-everywhere" mentality you could just offer a
<Standardized>.charCodeAt(str, no) function that actually standardizes
a charCodeAt call.
I beg to differ. It's not "not an issue for me" but "not an actual
issue". That is the whole point.
There's a couple of rules held up by one part of the JavaScript
community, that when followed avoid a number of issues. However this
does not mean, that conversely the issues they are meant to avoid will
actually arise, only because the rules themselves are not followed.
By virtue of Russell's teapot, the burden of proof lies with those
assuming the existence of actual issues.
Jslint is a non-issue as it serves to help remove the problems haxe
addresses through compilation anyway - so there's no major benefit - on
saying that anything that benefits human readability is a plus.
I think making sure we are google closure compilable (which we are
already with a few warnings) has much more value as it provides further
runtime optimisation. clojurescript is treating this as a big
feature/plus point of it's experience, like haxe it's targeting full
tier large apps.
The scripting space is chocablock with good alternatives, for me, haxe
for js should be targeted for better optimisation of large apps (js as
assembler) rather than existing conventions.
R
--
Simplicity is the ultimate sophistication. ~ Leonardo da Vinci
This point has bit evolved in the past years.
Originally I was mostly interesting in getting the JS output to actually
work and be efficient enough. I didn't care much about following X or Y
convention since the JS output is only supposed to read by the web
browser, not by actual users.
But since we got many people asking for improvements of the output -
sometimes for valid reasons, sometimes just for code nazification - I
made several changes :
- the first one was to allow custom JS output by using a haXe macro
clas, which enable power-users to customize the whole JS structure. This
enable to split your code into one js file per-package or per-class, and
to customize the way classes structures are initialization is performed.
I think it really helps people that want to integrate haXe into a larger
JS architecture but doesn't solve your point about
haXe-first-timer-reading-JS-code-output
- then we modified several times the default JS output to makes things
"nicer", such as passing google closure, but also "sanitizing" the code
output by removing all extra parenthesises, etc etc.
The only issues left at that point are :
- the usage of local-immediate-functions such as (function($this){ ....
})(this); in order to transform JS statements into expressions. And this
is planned for a fix,
see http://code.google.com/p/haxe/issues/detail?id=247
- "sandboxed" JS mode to remove all extra methods that this thread is
talking about (see http://code.google.com/p/haxe/issues/detail?id=247).
However for compatibility reasons this should maybe not be activated by
default, which would then not be seen by first-timers.
Any other suggestions on how to sexify haXe JS output are welcome.
Best,
Nicolas
It's still a fun language to play with though. :-)
cheers.
Kevin N.
R
If you do have constructive criticism backed up by hard data, you are
more then welcome to come forward.
However, if argumentum ad populum/verecundiam and reductio ad
ridiculum is the best you have to offer, you should not only
reconsider your position, but also your general discussion culture.
+1. If professionals are those who's favorite word is "professional",
then I think we're well off without them :)
I think it's mostly an IDE thing and while Flash Develop is great from a
programmer's point of view, there are no designer friendly tools that
allow designers to work with haXe. If there was a user-friendly GUI tool
for haXe (like Visual Studio for WPF-related stuff) that is based on a
cross-platform markup language, haXe would surely gain a huge adoption
boost.
Regards
Simon
9) The posture of the haXe community feels resoundingly *young*. Youth is a wonderful thing, and in many ways there is no substitute. But it's not the only thing. Deep experience is also a wonderful thing, and in many ways there is no substitute.
Still, I find your way of approaching this discussion (and especially
your conclusion of it) unfruitful and rather insulting, but the latter
may be just my perception of things.
If you have something to say, then please do, but please take the time
to provide verifiable arguments and also to react to the counter
arguments you are confronted with. I don't think you can expect anyone
to just believe whatever you say, no matter how important you believe
it to be or how strongly you appeal to its self-evidence.
Providing concrete problems, or better yet, suggestions for workable
solutions will get us all much further, then ridiculing a thread and
even the whole haXe language.
To offer criticism intended to be constructive - find ways to assimilate
the preferences, history and knowledge of existing communities (JS in
this case) into the haXe runtime design.
You will get only resistance from the participants in those parallel
communities - the very ones who will be asked to vet the quality of the
haXe runtime (in the JS example again) by so willfully ignoring their
concerns (extending native classes in this case). It may not be a
strictly technical problem, but not every problem is.
The haXe community is of course free to decide to do whatever it wants
(and those decisions are generally on good solid technical ground) - and
they surely will - but it would seem the "we know best about your
platform and community" posture is at odds with the desire to gain wider
use. Whether the decision is the correct technical decision or not isn't
even the issue at that level.
Kevin N.