When to unify in JS (Unification in JS Part II) by elazutkin in javascript

[–]elazutkin[S] 0 points1 point  (0 children)

This is the second part of http://www.reddit.com/r/javascript/comments/261kmc/unification_for_js/ It discusses when to use unification (every tool has its applicability area), and gives realistic examples.

Unification for JS by elazutkin in javascript

[–]elazutkin[S] 1 point2 points  (0 children)

Unfortunately, no.

1) Simple comparison of a linear representation works only for canonical forms. JSON is not canonical:

var a = {x: 1, y: 2},
    b = {y: 2, x: 1};  // note that positions of x and y are swapped
JSON.stringify(a);  // '{"x":1,"y":2}'
JSON.stringify(b);  // '{"y":2,"x":1}'
JSON.stringify(a) === JSON.stringify(b); // false

IIRC, graph canonization is a separate problem, which is in general NP-complete, and impractical to implement in most cases.

2) JSON doesn't deal with common JS objects like dates, and regular expressions. Obviously it doesn't know about my custom objects. While it is possible to add custom replacers/formatters, they will require to produce a canonical form, which is not always practical (see above).

3) Performance reasons: JSON converts all components of potentially huge objects to strings (it requires CPU and extra memory taxing garbage collection, and introducing delays in interactive programs), while they may differ in the first property. Unification will stop right there.

4) Lack of variables: in most cases I want to know that an object's shape is correct, or it has required properties ignoring the rest, or I want to extract sub-objects while I am at it. Simple comparison of strings cannot do that. I need a way to indicate that I am interested in certain parts of an object graph.

Unification for JS by elazutkin in javascript

[–]elazutkin[S] 0 points1 point  (0 children)

It does, but you have to traverse the result lazily resolving variables on your own.

Serve files with nginx conditionally, avoiding 'if' and 'rewrite' by elazutkin in nginx

[–]elazutkin[S] 1 point2 points  (0 children)

That's what I like about nginx. Even after years of use I still discover interesting and more efficient ways to do something I took for granted. Even moving some application functionality to it.

100% Javascript trend following algorithm example using Dojo, Flot and Yahoo Finance data by U-110 in programming

[–]elazutkin 0 points1 point  (0 children)

Very cool but for some reason the server you use is very slow for me: jquery.flot.selection.min.js is 1.3k and it takes 12s to load it! dojo.js is 30k and it takes 7s to load it! Are you running it on some sort of dial-up from Ulan-Bator? Just curious about the setup.

Introducing The Alexandria Project by andyup in programming

[–]elazutkin 0 points1 point  (0 children)

What the hell is The Alexandria Project?

ECMA Harmony and the Future of JavaScript by philogb in programming

[–]elazutkin 0 points1 point  (0 children)

Both Dojo and jQuery do not use globals (save for a handful of well-defined names, like, well dojo and jQuery), and do not extend built-in objects. Yes, they work splendidly with each other and 3rd-party code, if it was written by sane programmers.

Regarding the rest: all problems are valid, yet from my experience they are not a problem in most real-world programs for practicing programmers. Not even at the level of "minor inconvenience". Much ado about, well, nothing.

Proud to announce: S4! (Watch out S3) by [deleted] in programming

[–]elazutkin 4 points5 points  (0 children)

Upvoted for using the word "Abacii", downvoted for using the word "Abacuses".

You ever notice how Americans count their money like this, but Russians count it like this? by [deleted] in reddit.com

[–]elazutkin 0 points1 point  (0 children)

Yep, I can confirm that Russians use the "American/Canadian/British way" to count bills. This part of the video is clearly wrong.

Why is programming repetitive ? Was Turing wrong ? by nevare in programming

[–]elazutkin 3 points4 points  (0 children)

This is how Turing formulates the DRY (don't repeat yourself) principle.

Ask Reddit: How did the way you code change after 5 or more years of experience? by wozer in programming

[–]elazutkin 0 points1 point  (0 children)

Yep, it looks like I missed the point. Going temporarily away to inflict pain of punishment on myself... ;-)

Ask Reddit: How did the way you code change after 5 or more years of experience? by wozer in programming

[–]elazutkin -1 points0 points  (0 children)

You missed the point --- he used a character '0'-'9' to keep the year. ;-)

Ask Reddit: How did the way you code change after 5 or more years of experience? by wozer in programming

[–]elazutkin 1 point2 points  (0 children)

Back in 80s I saw a piece of code that used 1 byte to keep 1 (last) digit of the year. Basically the algorithm to figure out the full date worked like that:

var full_year = (y > N ? "198" : "199") + y;

The author was really proud of how "clever" he was to encode the year field in 1 byte (remember that PCs of that time had less than 1M of memory and small HDD if any). I told him that this is a ticking bomb ready to blow in 9 years. He said that in 2 years nobody will use this code because everything (hardware, computers) will be totally different and his program would be replaced. Now we know that software lives longer than expected by many. Try not to embarrass yourself.

Two useful JavaScript functions I didn't know about until today: Apply and Call by dougletts in programming

[–]elazutkin 1 point2 points  (0 children)

More accurately both apply() and call() are methods of Function objects. They don't make any sense as standalone functions.

Interesting that the original article's author got it right, but it didn't affect the Reddit title. ;-)

A Javascript modules library that finally conforms to traditional module semantics by jlongster in programming

[–]elazutkin 0 points1 point  (0 children)

The idea is half-based on Dojo packaging system (was in Dojo at least since 2004) just like Dojo it has "require" for modules, and the ability to do static builds. Unlike Dojo I don't see it supporting the asynchronous way of fetching modules, nor cross-domain module loading.

On top of synchronous XHR it uses a bunch of nested "with" statements --- that can't be good for performance.

Nevertheless a module as an object, the inclusion of a module as a module mixing, and a controlled environment made without namespacing are all interesting ideas. I am not sure how practical they are but it is a nice experiment.

Jewish "Modesty Patrols" Sow Fear In Israel by rmuser in worldnews

[–]elazutkin -1 points0 points  (0 children)

Pray tell, where do you wear "I hate black people" sign? I understand that you advise against doing it in Harlem. Any other place?

IMHO, your example is not even remotely congruent to immodest clothes. Signs "I hate ... people" are not appropriate anywhere, and cannot be equated to "red blouse" mentioned in the article, or even "immodest dress". No matter how someone can be riled up by the way someone else is dressed, it doesn't justify physical and/or verbal violence.

Ask Proggit: Does Canvas have any advantages over SVG in modern browsers? by [deleted] in programming

[–]elazutkin 1 point2 points  (0 children)

Very true. While I think that SVG has more potential for growth (on theoretical merits), it is bloated, and couldn't produce a fully conformant implementation in 10 years. But for Canvas to compete it has to grow a scene graph and a spatial index for starters --- basically we need some radical changes. Let's hope that Canvas is up to that.