Hacker Newsnew | past | comments | ask | show | jobs | submit | jaysoo's commentslogin

Updated the post with timing numbers.

I want to note that the numbers can be deceiving though because they use different mechanisms to record elapsed time.

When I ran the same task though Unix `time` I got numbers that were much closer, although still in Gulp's favour.


I myself enjoy using CoffeeScript, but I understand it might not be for everyone.

It's always good to look at the pro/cons before choosing a language, so I think discussions like this is good.

That being said, some of the problems this article points out can be addressed by going back to more JS style.

e.g. Not relying on implicit parentheses/commas/braces

I like the "Fancy" for loop because it's closer to what I do in Python (yes I know they are not exactly the same). Same thing with the "Tricky" if statements.

Also the redefinition shortcuts provided in CoffeeScript is pretty much what I do in plain JS anyway.

e.g.

JS: foo = foo || 'bar';

CS:

  foo or= 'bar'


CS 1.3.1:

"Conditional assignment of previously undefined variables a or= b is now considered a syntax error."


Yeah I know. It was just a quick example.

It's useful for something like:

  f = (options) ->
    options.foo or= 'bar'
    # ...


Is it really that strange?

Those statements are basically (as per ECMA-262 11.9.3):

0 === Number('0') 0 === Number('') '0' === ''


If this was socialism then either the government or the public would own Bell/Rogers/Telus.

This is also not free-market capitalism. I'm not sure what you would call it.


This is called Oligopoly http://en.wikipedia.org/wiki/Oligopoly in half-assed capitalism. Note that this can be worse than monopoly because few competitors can essentially create informal cartels.


Yup. What frequently happens is that companies in an Oligopoly are able to collude to raise the barriers of entry, keeping out new competitors: sometimes with "help" of government regulations, sometimes because of lack of government regulation. As long as there are only a couple of them (< 4 controlling > 80 percent of the industry), they can keep prices artificially higher than they need to be.

When there's no actual competition and little threat of new competitors entering the market, their incentive to innovate or become more efficient is diminished. Consumers end up paying too much for mediocre goods/services.


If there is an Oligopoly, then how has this occurred? What entity is there providing the conditions for the Oligopoly to exist and persist? If there were not government interference via the CRTC we would have open competition. But we don't because the CRTC is there. And they have the power to make sure that no real competition can take hold. Where does this lead us? Straight back to corporatism (the government and corporations are in bed together) - Let's not use the term capitalism anywhere in this context.


"Regulation of natural monopolies." Wikipedia goes into it better than I can: http://en.wikipedia.org/wiki/Natural_monopoly#Regulation


Corporatism.


Regulatory capture?


Tyranny? ;)


The big deal here is that instead of offering competitive plans the big ISPs are _decreasing_ the level of service and _increasing_ the prices of plans.

Also, Bell/Rogers/Telus have the advantage of offering bundles if you use them for cable/satellite+cell phone+Internet, whereas a lot of smaller ISPs would not able to do such things. This screams anti-competition.

FYI, I don't mind paying per usage as long a the rates are reasonable. How about charging us $10-15 for connection fees, and then $0.25/GB of transfer?


>The big deal here is that instead of offering competitive plans the big ISPs are _decreasing_ the level of service and _increasing_ the prices of plans.

Are they? I have the fastest plan from Telus and over the years they have upped the speed without upping the price, several times.

>Also, Bell/Rogers/Telus have the advantage of offering bundles if you use them for cable/satellite+cell phone+Internet, whereas a lot of smaller ISPs would not able to do such things. This screams anti-competition.

agreed, to a point. However all of the little guys I am aware of offer some kind of an Internet/phone bundle

There are several wireless Internet providers here in Alberta and I'm watching them with interest. They've built their own network run along natural gas lines or old railway tracks (where it's easy to obtain right of way rights) and are beholden to nobody (other than their backbone providers). If the big three go crazy with fees, I think these tiny wireless providers are poised to jump in and beat them down.


Not exactly the same signature, but can handle arbitrary number of calls.

var say = (function() {

    var savedArgs = [];

    return (function recurse () {

        if (arguments.length) {

            for (var i=0, arg; arg=arguments[i]; i++) {

                savedArgs.push(arg);

            }

            return recurse;

        } else {

            alert(savedArgs.join(' '));

            savedArgs = [];

        }

    });
})();

// e.g. say('Hello')('World')('!!')();

// --> alerts "Hello World !!"


The goal could be CSRF instead of actually reading the cookies. If there's a SessionID cookie for example, you can use JS to GET/POST the request to the server without needing to know the value of SessioID because the browser will send it as part of the request anyway.

The HTTP Response Splitting vulnerability can have many implications, XSS and CSRF attacks are just some examples.


Ah, right. Thanks!


> #13 In any code block, store local references to out-of-scope variables.

That doesn't even make sense. The for-loop block doesn't create a new scope, so it's perfectly valid to refer to the variable `a`. Plus, even if you create a new scope, you can still refer to `a` due to closure.


We are talking about performance optimization here; which means 'what will work faster' over conventional approaches. Every time the scripting engine doesn't find a variable in the local scope, it starts searching for it upwards until it reaches global namespace. And this, my friend, costs CPU cycles. Now consider this out-of-scope variable being used in a loop. Closure is a power JavaScript has given us to use it wisely; and not to misuse.


In the case of closure, yes you will take a small performance hit. But the example given is still invalid because the only scope present is the function-scope (for-loop doesn't create new scope).

For example, if you ran the code below in FireBug you'll get the same results (minor variance aside).

function foo() { var a = 0; for (var i=0, j=a; i<10000000; i++) { var x = j+i; } }

function bar() { var a = 0; for (var i=0; i<10000000; i++) { var x = a+i; } }

(function() { var start = new Date().getTime(), end; foo(); end = new Date().getTime(); console.log(end-start); })();

(function() { var start = new Date().getTime(), end; bar(); end = new Date().getTime(); console.log(end-start); })();


for-loop does create a scope. In fact, every statement block is a scope in itself.

In your examples, just change the value of variable 'a' to 100 or 1000 and you will see the difference.


Blocks in JavaScript do not create scopes. This is different from many other languages (like Java or C).

In fact, Crockford has mentioned this as well: http://javascript.crockford.com/code.html

"JavaScript does not have block scope, so defining variables in blocks can confuse programmers who are experienced with other C family languages."

Which is why this code works:

(function() {

    for (var i=0; i<100; i++);

    alert(i);
})();

Notice the variable `i` is accessible from outside the for-loop.


That's correct. Thanks a lot. Updated the blog with the correct example (using function). I was testing on Chrome and even your examples showed better results with value of variable 'a' to 1000, although slightly. Firefox shows no difference.

Another thing, JavaScript 1.7 has introduced block level scopes.. you can achieve that by using the 'let' keyword instead of 'var' to declare a variable. Although most browsers don't support it yet.


No problem. It's one of those things developers don't realize when coming from C-style languages. :)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: