Live data from Hacker News

Wherein Javascript borrows a language feature from Arc

twoguysarguing.wordpress.com

1–10 of 22 posts

Re: Wherein Javascript borrows a language feature from Arc

#2
You should probably assign an object to the underscore, otherwise any argument which is undefined will match:

    js> var _
    js> _ == undefined
    true
Just doing "var _ = {}" should be sufficient.

edit: however, this conflicts with Underscore.js (http://documentcloud.github.com/underscore/), but if you put an "if (typeof _ === "undefined")" around the assignment you should be ok

Re: Wherein Javascript borrows a language feature from Arc

#3
> geolocator.getLatLng("Forest Park, St. Louis, MO", function(center) {

> displayMapAt(center, 14);

> });

To my eyes, that solution is just fine. I don't think I'll ever be swayed to believe that adding on layers of indirection to JavaScript code for the sake of "syntactic goodness" is rationally motivated by leading to more practical power for actually solving problems.

Re: Wherein Javascript borrows a language feature from Arc

#4

> geolocator.getLatLng("Forest Park, St. Louis, MO", function(center) { > displayMapAt(center, 14); > }); To my eyes, that solution is just fine. I don't think I'll ever be swayed to believe that adding on layers of indirection to JavaScript code for the sake of "syntactic goodness" is rationally motivated by leading to more practical power for actually solving problems.

agree - imagine inheriting this code and then having to figure out what the underscore is doing. ugh.

Sometimes brevity isn't the right solution.

Re: Wherein Javascript borrows a language feature from Arc

#5

You should probably assign an object to the underscore, otherwise any argument which is undefined will match: js> var _ js> _ == undefined true Just doing "var _ = {}" should be sufficient. edit: however, this conflicts with Underscore.js ( http://documentcloud.github.com/underscore/ ), but if you put an "if (typeof _ === "undefined")" around the assignment you should be ok

I actually did a === check for just that reason, since if you define _ = {}, then passing in a real object that is {} will also return true for _ == {}

Re: Wherein Javascript borrows a language feature from Arc

#8

> geolocator.getLatLng("Forest Park, St. Louis, MO", function(center) { > displayMapAt(center, 14); > }); To my eyes, that solution is just fine. I don't think I'll ever be swayed to believe that adding on layers of indirection to JavaScript code for the sake of "syntactic goodness" is rationally motivated by leading to more practical power for actually solving problems.

Agreed. If you're writing something in a web browser, use sane JavaScript. Every time I have done something "fancy" with a language, there has been a large hidden cost later on, be that complicated debugging sessions, new hire training, or unintended side effects. Terrible syntax/rewriting hacks in Rails are probably what convinced me that I do not like ruby. If you truly care about programmer efficiency, you probably want to look into cross compilers like Objective-J or parenscript.

Re: Wherein Javascript borrows a language feature from Arc

#9
post #5

You should probably assign an object to the underscore, otherwise any argument which is undefined will match: js> var _ js> _ == undefined true Just doing "var _ = {}" should be sufficient. edit: however, this conflicts with Underscore.js ( http://documentcloud.github.com/underscore/ ), but if you put an "if (typeof _ === "undefined")" around the assignment you should be ok

I actually did a === check for just that reason, since if you define _ = {}, then passing in a real object that is {} will also return true for _ == {}

Nope:

    js> a = {}
    [object Object]
    js> b = {}
    [object Object]
    js> a == b
    false
== only casts between certain primitive types, it doesn't do a deep comparison:

    js> x = null
    null
    js> y = undefined
    js> x == y
    true
    js> x === y
    false
Also undefined comparisons are still true with ===:

    js> var _
    js> _ === undefined
    true

But you're right, === should be the default choice, and only use == if you have a good reason.

Re: Wherein Javascript borrows a language feature from Arc

#10

You should probably assign an object to the underscore, otherwise any argument which is undefined will match: js> var _ js> _ == undefined true Just doing "var _ = {}" should be sufficient. edit: however, this conflicts with Underscore.js ( http://documentcloud.github.com/underscore/ ), but if you put an "if (typeof _ === "undefined")" around the assignment you should be ok

It also conflicts with gettext libraries. The name '_' should be considered reserved for that purpose.
Post reply on HN