1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Coffee script...

Discussion in 'JavaScript' started by FrontEndDev, Feb 6, 2016.

  1. #1
    I'm looking into learning coffee script. I've heard it's way faster then regular JavaScript and is becoming the norm for developers. Any experience with this? Also do you have a preferred method of learning it? I.e. favorite book or website?
     
    FrontEndDev, Feb 6, 2016 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #2
    Any time anyone tells you another layer of abstraction ATOP AN INTERPRETED LANGUAGE is going to be "faster", they're full of shit!

    "Coffee Script" is a needlessly cryptic preprocessor that "compiles" to javaScript... Since all it does is produce JavaScript, how the blazes would it be any "faster"?!?

    The only thing that might apply is that it lets you TYPE less code... in theory; but if you look at the train wreck it typically outputs and the broken methodologies used by the people writing code with it, I suspect that much like CSS preprocessors or asshattery like frameworks (see the mouth-breathing dumbass bullshit known as jQuery), the people who claim to see a legitimate advantage to using it generally don't know enough abou the underlying language to be flapping their gums on the topic.

    CoffeeScript would ALMOST have made sense to fill a few gaps in what JS can do a decade ago; but with ECMAScript 262-5 being mostly real-world deployable and polyfills available for older browsers if need be, stuff like CoffeeScript is just going to age like a latte in the sun.

    You can tell it's bull from the code on their own site; while sure it might be easier to type this cryptic mess:

    cubes = (math.cube num for num in list)
    Code (markup):
    What their ALLEGED "compiler" is vomiting up:

    cubes = (function() {
      var i, len, results;
      results = [];
      for (i = 0, len = list.length; i < len; i++) {
        num = list[i];
        results.push(math.cube(num));
      }
      return results;
    })();
    Code (markup):
    Has a good deal wrong with it.... like wasteful declarations. Even classic Scripttardery that should have been:

    cubes = [];
    for (var i = 0, len = list.length; i < len; i++) cubes.push(math.cube(list[i]));
    Code (markup):
    Though depending on how often you call that, the anonymous function instead of a real function or method could become painfully slow and grossly inefficient VERY quickly. If you're going to make your own custom "math" object (a sloppy practice confusing to the existing Math -- damn I hate case sensitive languages) put the function you might use more than once on it.

    Of course, using MODERN scripting and since cubes is available to store the result....

    cubes = []; 
    list.forEach(function(e) { cubes.push(math.cube(e)); });
    Code (markup):
    With a polyfill for Array.prototype.forEach on older browsers. Any modern browser should support it.
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

    Which is why if their "compiler" was worth a flying purple fish, it would be outputting THIS:

    var
    	cubes = [],
    	list = [1, 2, 3, 4, 5],
    	math = {
    		root : Math.sqrt,
    		square : function(x) { return x * x; },
    		cube : function(x) { return Math.pow(x, 3); }
    	},
    	number = 42,
    	opposite = true;
      
    function race() {
    	return print(
    		arguments[0],
    		2 <= arguments.length ?
    		arguments.slice(arguments, 1) :
    		[]
    	);
    }
      
    if (opposite) number = -42;
    
    if (typeof elvis !== "undefined" && elvis !== null) {
      alert("I knew it!");
    }
    
    list.forEach(function(e) { cubes.push(math.cube(e)); });
    Code (markup):
    The only reason nonsense like this gets made is the people behind it not knowing enough about the underlying language to recognize their own BS, and the only reason it catches on is the people who become fans being even more ignorant than those who created it.

    As evidenced by the fact that apparently they seem to think what JavaScript needs is LOOSER typecasting. Herpa... freaking... derp!

    As I've said of a lot of things, if you know the underlying language (JavaScript in this case) at ALL, and this isn't setting off your bullshit alarm? Check the batteries.
     
    Last edited: Feb 9, 2016
    deathshadow, Feb 9, 2016 IP