Coffeescript sucks
-
Derp.tap = (o, fn) -> fn(o); o
Derp.merge = (xs...) -> if xs?.length > 0 Derp.tap {}, (m) -> m[k] = v for k, v of x for x in xs
I don't understand people who think this abomination makes Javascript better.
-
I have no idea what's going on there...
I did one major project in CoffeeScript but we wrote it like normal C++/Java/C# code and simply used it to hide a lot of JavaScript ugliness. It seemed to work well but never went into production because me and my team were laid off when the project was around 95% completed.
-
Looks like LINQ for JS
-
I don't know how you'd do that, the compiler complains when you do anything that makes CS look sane (semi colons, squiggly brackets, using language keywords like function, etc).
-
TypeScript is better. much better.
I have no idea what's going on there...
looks like a bastard child of javascript and PERL to me.
-
Okay, maybe it was more like Python then...been a couple years now.
-
I know, though really even vanilla JS is better than this. When it first came out I started playing with it and started to enjoy using it, only problem is nobody uses it around here.
Thankfully, the whole project isn't like this. Why any of it needs to be so blatantly obtuse is beyond me but it was written by a guy who disappeared without notice.
-
That's more likely, but you can already write JS like that (no Coffeescript compilation required).
-
Why any of it needs to be so blatantly obtuse is beyond me but it was written by a guy who disappeared without notice.
you answered your own question there... it was a maintainability bomb. ;-)
-
I just don't understand what's going on with the [i]we hate {}s[/i] brigade. Curly brace languages for the win. Go curly or go home.
-
Curly brace languages for the win. Go curly or go home.
here's my opinion on curly braces. either design the language so they are never a syntactic element (python, it's a good language and no curly braces) or design it so they are ALWAYS required syntactic elements.
none of this crap optional braces around control structures.
that's just crap and will get you a metaphorical ding around the ears if you do it around me!
-
either design the language so they are never a syntactic element (python, it's a good language and no curly braces) or design it so they are ALWAYS required syntactic elements.
Agreed—but prefer "always". Wow, PERL got something right</t>...
-
If you're going to use a "JavaScript but better" language, you'd be much better-off with TypeScript. It wasn't designed by dumbshits.
-
Agreed—but prefer "always". Wow, PERL got something right...
i'd also prefer always, but i'll take consistency if that's what's on offer.
-
If you're going to use a "JavaScript but better" language, you'd be much better-off with TypeScript. It wasn't designed by dumbshits.
What does Anders Hejlsberg know about software?
-
TBH it is a rubyists interpretation of JavaScript and it prefers terseness.
The example up there while a little terse isn't that bad.
-
I have no idea what's going on there...
Derp.tap = function(o, fn) { fn(o); return o; }; Derp.merge = function() { var retval = {}, args=arguments; var x, k, v; for(x = 0; x < args.length; x++) { for(k in args[x]) { Derp.tap(retval, function(rv) { rv[k] = args[k]; }); } return retval; };
Filed under: Because everyone loves calling varargs "splats", nullable types "existential", and lambdas "functions, and every other way to declare them is WRONG!", we need a new tag cloud to attack, Discourse plugin request: Make it delete two characters when backspacing once, and automatically add the appropriate tag
-
I hate CoffeeScript.
On the other hand, I love TypeScript.
Edit:
@blakeyrat said:If you're going to use a "JavaScript but better" language, you'd be much better-off with TypeScript. It wasn't designed by dumbshits.
What he said.
-
I know what it is, I just think it's an absolutely horrible way to express it. No matter how you cut it ("rubyists interpretation"), it's the wrong way to do it.
-
i'll take consistency if that's what's on offer.
If consistency isn't on offer, then somebody somewhere is Doing it Wrong. [spoiler]@CodingHorrorBot, save me the bother...[/spoiler].
-
@tar Is Doing It Wrong™
-
What does Anders Hejlsberg know about software?
You're trying to do some kind of Appeal to Authority, but I don't know who the fuck that is and so it's not working. (And no, I do not care who it is.)
-
What does Anders Hejlsberg know about software?
You're trying to do some kind of Appeal to Authority, but I don't know who the fuck that is and so it's not working. (And no, I do not care who it is.)He's the dude who invented C#, isn't he?
-
Hey Blakey, did that woosh left a mark. At least learn who made what you praise so much.
Oh! And if by "invented" you meant copy/paste Java then yes, he did it.
-
He also works on TypeScript. I think the woosh was so loud I'm deaf in one ear...
-
Karma is a bitch that will bite your ass as soon as you discredit someone.
-
Oh! And if by "invented" you meant copy/paste Java then yes, he did it.
Every day I am thankful that that is false.
-
Never mind his work on Delphi and Turbo Pascal...sheesh.
-
At least learn who made what you praise so much
Why, so you can be an elitist douche about it to other people on internet discussion boards?
-
Why, so you can be an elitist douche about it to other people on internet discussion boards?
Do we have a whoosh number 2 here?
-
I know who he is, I just don't care. Tech doesn't need celebrities. The guy is good at his job, that should be enough. No need for cheerleading the guy for doing what he's paid to do.
-
Another whoosh!
I wish I had a storm cellar.
-
Oh! And if by "invented" you meant copy/paste Java then yes, he did it.
OK, when did each language introduce attributes? Lambdas? Generics? Delegates? Nullable value types? Dynamic variable typing? Object initializers? Using blocks? Multidimensional arrays?Java still has aspects over C# and bug integer math is only in .Net 4.5, but they certainly have squandered their seven year head start. Aside from garbage collection and reflection, almost every feature in modern C# wasn't done in Java first.
-
-
And the common library is older than .Net (at least in spirit) and was better right from day 1.
-
OK, when did each language introduce ... Generics? ...
I certainly don't really want to support the "C# is a copy of Java" position; I'd take the former in a heart beat. But Java got generics in Java 5, released Sept 2004; if memory and brief investigations hold, C# took until .Net 2.0, which was Jan 2006.
-
Which language has generics that actually compile?
-
I certainly don't really want to support the "C# is a copy of Java" position; I'd take the former in a heart beat.
Even if you did take the position of C# is a copy of Java, it is such a massive improvement that whether it was or not a copy is irrelevant.
-
While the example by @aapis is extremely terse, it isn't too hard to decipher after spending a minute or so on the coffeescript homepage.
Coffeescript is how a rubyist wishes to write JavaScript and thus the terseness. The syntax seems okay to me, however I am not sure how I would feel writing a large codebase with it.
-
Coffeescript is like Scala, in that it looks decent when used in moderation, but then the advocates go terseness crazy and I'm like "have fun, assholes, I'm going home".
Although, a ruby wannabe hipster-friendly language is still better than writing the plain javascript like a hipster idiot (example: anything from the bootstrap js).
-
That is my feeling as well. The place that I am leaving after xmas has that in spades.
I had to monkey patch the type-ahead plugin in bootstrap 2 ... lets say it isn't the easiest thing to read.
-
I think I understood most of that immediately. That makes me feel good.
-
Goddamn. Looking at this shit makes me happy that I work in Java and C++ and Oracle SQL.
-
While the example by @aapis is extremely terse, it isn't too hard to decipher after spending a minute or so on the coffeescript homepage.
The problem with high levels of terseness is that it quite easily gets excessively subtle. The problem is that this makes reading the code later much harder; making things more verbose (though not ridiculously so, of course) makes after-the-fact debugging and maintenance much easier. If you're not programming to support future maintenance, you're a jerk of a code-monkey.
-
I think if you look at some of the examples on the home page, they seem to have the right level of terseness ... but they are examples. You can take anything to far, how many times have we seen naming like IAbstractControllerFactoryForTextBasedColumnGeneration?
-
You can take anything to far, how many times have we seen naming like IAbstractControllerFactoryForTextBasedColumnGeneration?
The only general rules that work truly well all the time are those that relate to good taste. Of course, such rules aren't entirely codified; they're hard to enforce automatically or convey to a starter code-monkey. Yet nothing (at the semantic level) that is easy to enforce is always right, especially for complicated situations.
-
I like TypeScript. I don't use it (it took a couple years for me to use jQuery, and only d3 of all the random JS libraries has really gotten my attention, though I will grudgingly admit that processing is pretty awesome--possibly I have a strange dislike of canvas elements, but that's probably because I have an aversion to raster graphics in general), but if I did use a "Javascript but better", it would be TypeScript.
So...
-
```js
Derp.tap = function(o, fn) { fn(o); return o; };Derp.merge = function() {
var retval = {}, args=arguments;
var x, k, v;
for(x = 0; x < args.length; x++) {
for(k in args[x]) {
Derp.tap(retval, function(rv) {
rv[k] = args[k];
});
}
return retval;
};A few alternatives for your discussion: ```js function arrayify(obj){ return Array.prototype.slice.call(obj); } var obj1 = { a: 'a1', b: 'b1', c: 'c1' }, obj2 = { a: 'a2', c: 'c2', d: 'd2' }, obj3 = { b: 'b3', c: 'c3', d: 'd3', e: 'e3' }, obj4 = { e: 'e4', f: 'f4' }; Derp = {}; // First contender! Almost like yours but without the tap() crap Derp.merge = function merge() { var retval = {}, args=arguments; var i, x, k; for(i = 0; i < args.length; ++i){ x = args[i]; for(k in x) { retval[k] = x[k]; } }; return retval; }; console.log( Derp.merge(obj1, obj2, obj3, obj4) ); // Second contender! Derp.merge2 = function merge2(){ function copyProps(dst, src) { Object.keys(src).forEach(function copyProp(k){ dst[k] = src[k]; }); return dst; }; return arrayify(arguments).reduce(copyProps, {}); }; console.log( Derp.merge2(obj1, obj2, obj3, obj4) ); // Third contender! Derp.merge3 = function merge3() { var retval = {}, args = arrayify(arguments); args.forEach(function copyProps(x){ Object.keys(x).forEach(function copyProp(k){ retval[k] = x[k]; }); }); return retval; }; console.log( Derp.merge3(obj1, obj2, obj3, obj4) ); // Fourth contender! Derp.merge4 = function merge4(o1, o2) { var retval = {}, args=arrayify(arguments); var x, k; while((x = args.shift())){ for(k in x) retval[k] = x[k]; }; return retval; }; console.log( Derp.merge4(obj1, obj2, obj3, obj4) );
Discourse plugin request: Make it delete two characters when backspacing once, and automatically add the appropriate tag
Filed under: FUCKING DISCOURSE WHY DO YOU DELETE TWO EMPTY LINES WHEN I QUOTE A CODE BLOCK?; FUCKING DISCOURSE WHY DO I NEED TO LEAVE TWO EMPTY LINES BETWEEN THE START OF A QUOTE AND A CODE BLOCK?; FUCKING DISCOURSE WHY AREN'T YOU HIGHLIGHTING SYNTAX LIKE IN THE PREVIEW?; Complete disregard forhasOwnProperty
; Your variablev
is unused; Name your functions
-
Filed Under: Complete disregard for
That's intentional; first, the "compiled" CoffeeScript ignoreshasOwnProperty
hasOwnProperty
too, and second, adding mixins toObject.prototype
is considered really bad behavior anyway, both because it breaksfor...in
and because it breaks guarantees forasm.js
optimization.@Zecc said:Filed under: Your variable v is unused
My bad. Was trying to replicate the CoffeeScript as closely as possible and accidentally optimized it away. Oh well.@Zecc said:Filed under: Name your functions
Who in their right mind would callDerp.merge4.name
, especially in a pre-Harmony era?
-
hmm....
This is what i've been using for deep object merges in sockbot... perhaps it's time i upgrade?
function mergeInner(a, b) { var name; for (name in b) { if (b.hasOwnProperty(name)) { if (typeof b[name] === 'object' && !Array.isArray(b[name])) { var c = a[name] || {}; a[name] = mergeInner(c, b[name]); } else { a[name] = b[name]; } } } return a; } function merge() { var args = Array.prototype.slice.apply(arguments), res = {}, obj = args.shift(); while (obj) { mergeInner(res, obj); obj = args.shift(); } return res; }
EDIT: why you syntax highlight in preview but not when posted?
EDIT: now you syntax highlight‽ @CodingHorrorBot