News for hackers. Stuff that matters.
Re:How I built a fast JavaScript framework by evmar on Wednesday March 07, 2018 @11:26AM (#16537442)
I am often frustrated in this ecosystem by how people build things without any clear conceptual model, and then they document them by saying "it is so fast, it just works like magic". It is impossible to compare two approaches because there are no facts available to compare them on.

Like for this one from a peek at the source code it appears to try to parse JavaScript at runtime using regexes (https://github.com/radi-js/radi/blob/master/src/index.js#L4) which is great for demoware and not at all something I'd want to use in production, but that is not mentioned anywhere in the site or blog post.

I don't mean to just dump on this project in particular, which could just be a fun toy side project for the author, because this problem is endemic. (But then why go to all the effort to make all the marketing materials for it without actually writing any docs?)

Re:How I built a fast JavaScript framework by Froyoh on Wednesday March 07, 2018 @12:47PM (#16538177)
Looks like the regex is only used to strip comments?
Re:How I built a fast JavaScript framework by pygy_ on Wednesday March 07, 2018 @01:42PM (#16538677)
https://github.com/radi-js/radi/blob/eace84e9b74c944b233f631...

It parses the source code of the view function at run time, matching parentheses, but ignoring whether those are present in strings or regexes. Likewise, the comment stripper will turn

    "/*whoops*/" 
into the empty string...

In other words, the parser is buggy :-/

Re:How I built a fast JavaScript framework by lhorie on Thursday March 08, 2018 @12:06PM (#16545735)
Having taken a closer look, it looks like the problems go even deeper than that: it rewrites `l()` calls in functions through a regex/replace on `fn.toString()`. This is similar to the mechanism that broke shorthand Angular.js DI in production. So code can break if it goes through some bundler than renames the `l` variable, or if a minifier does it, etc.

I'd imagine closures also break.

Re:How I built a fast JavaScript framework by pygy_ on Thursday March 08, 2018 @12:20PM (#16545877)
Closures will break, yes. It looks like it is intended to react to mutations to the properties of `this`...

I hadn't thought of minification, yes it pretty bad :-/...

It looks like the author is smart but has little JS experience (`var last = temp.splice(-1)[0]` where `temp.pop()` would do tells me that it may be one of his first JS project).

Re:How I built a fast JavaScript framework by evmar on Wednesday March 07, 2018 @01:08PM (#16538388)
The line I linked to, sure. But under what conceptual model would a framework need logic to strip comments (an aspect of source text) at runtime? Follow it to its conclusion.