News for hackers. Stuff that matters.
Re:Goodbye CoffeeScript, Hello TypeScript by mreiland on Tuesday October 20, 2015 @01:38PM (#10420562)
I'll never understand why people don't just use javascript.
Re:Goodbye CoffeeScript, Hello TypeScript by bcherry on Tuesday October 20, 2015 @02:04PM (#10420732)
I kinda agree - Coffeescript in particular seems like putting extra weight/overhead into the process for very little other than cosmetic gains over JavaScript. Whatever problems JS may have - I don't really feel that CoffeeScript addresses them. It addresses the fake problems (IMO).

TypeScript and related make a lot of sense for very large projects/teams because static type checking can be VERY useful, and the lack of a statically typed language choice for in-browser programming is a large weakness of the web ecosystem. So TypeScript is a tremendous advantage to have in the toolkit, and a much saner approach than older heavy-weight options like GWT.

Re:Goodbye CoffeeScript, Hello TypeScript by the_rosentotter on Tuesday October 20, 2015 @04:02PM (#10421453)
GWT still has a major advantage in that you write the server in the same language as the client (Java). Indeed they are the same code base and can share code, classes, etc. I have yet to see an alternative with such a strong server side component to it.
Re:Goodbye CoffeeScript, Hello TypeScript by matm on Tuesday October 20, 2015 @01:44PM (#10420604)
Because it's really hard to build, test and maintain a non-trivial application in a dynamically-typed language like JavaScript.

I think it's telling that a lot of companies with the most mature products (Facebook, Dropbox, Asana) eventually resort to optional static typing in their products, whether that means extending their runtimes (e.g. Hack) or using a transpiler like TypeScript.

Re:Goodbye CoffeeScript, Hello TypeScript by zurn on Tuesday October 20, 2015 @03:00PM (#10421052)
The implicit conversions and "we'll just randomly give you undefined to propagate ondwards" stuff is a much bigger source of bugs in JS than dynamic typing. Picky dynamically typed languages like Erlang or Python will pretty reliably produce an error/exception at the scene of the crime. (More so than C/C++!)

(Also I don't think optional static typing has gotten off the ground in Python land, or adopted in production at Dropbox?)

Re:Goodbye CoffeeScript, Hello TypeScript by z1mm32m4n on Tuesday October 20, 2015 @04:16PM (#10421528)
Dropbox Paper is written almost entirely in TypeScript.
Re:Goodbye CoffeeScript, Hello TypeScript by pekk on Tuesday October 20, 2015 @03:50PM (#10421364)
What is it telling? It might just be telling that everyone is doing what you're doing here, and looking at each other to see what they should do. Another name for this is "fashion."
Re:Goodbye CoffeeScript, Hello TypeScript by aikah on Tuesday October 20, 2015 @01:55PM (#10420663)
Well ,because Typescript makes a huge codebase easier to read and maintain (though ES6 is a huge improvement, no question)

I used to use Coffee Script, which I still like, but ES6 clearly made Coffee Script less relevant. Typescript value is clearly in the type annotations and the support for ES6 ...

Another problem with Coffee Script is the fact that it evolves way to slowly and it is unlikely to support most of ES6 features because its core maintainers are clearly not interested in adding significant features. In fact that the main issue for me. Both Backbone and Underscore suffer from the same issues.

Re:Goodbye CoffeeScript, Hello TypeScript by tallerholler on Tuesday October 20, 2015 @04:35PM (#10421638)
> ES6 clearly made Coffee Script less relevant

I see that a lot and find it highly subjective. I don't find es6 useful at all and will stick with coffeescript for the foreseeable future but that also has to do with my reasons for using it.

Re:Goodbye CoffeeScript, Hello TypeScript by abritinthebay on Tuesday October 20, 2015 @02:00PM (#10420703)
In this case: because they want type enforcement. This removes a category of errors that - in a complex app - can be really annoying.

Better - it removes that ability for deliberate bad behavior by devs.

That said - I prefer JavaScript + Flow as thats a much more native solution which means you don't need to learn a pseudo language first.

Re:Goodbye CoffeeScript, Hello TypeScript by WorldMaker on Tuesday October 20, 2015 @02:33PM (#10420882)
Typescript isn't exactly a pseudo-language. It looks just like JavaScript with Flow annotations. In fact, Typescript is intended to be JavaScript + Type Annotations, so it's just as "native" as JavaScript + Flow annotations, with the addition of some Babel-style ES6 transpiling as well. The only difference is the explicit build process versus running the transforms in browser, and I've seen projects use the Typescript compiler (itself written in JS) as their in-browser transpiler (SystemJS supports it as a first-class transpiler option alongside Babel and Traceur, even).
Re:Goodbye CoffeeScript, Hello TypeScript by abritinthebay on Tuesday October 20, 2015 @05:55PM (#10422080)
> It looks just like JavaScript with Flow annotations.

It looks close to that, yes. However Flow can be also implemented via comments to native JS so... TS can't do that.

In which case...

> it's just as "native" as JavaScript + Flow annotations

is wrong. TypeScript requires a transpilation step. Flow doesn't. It can do, but it's not required.

I may have been a little harsh with the "pseudo-language" but I'm not sure what else to call something that is designed to be transpiled into the right language. It's not higher-level, it's sort of... a companion language I guess.

Re:Goodbye CoffeeScript, Hello TypeScript by kuschku on Wednesday October 21, 2015 @03:10PM (#10427817)
You can write TS and put the type definitions into a separate file, so you don’t need a transpilation step. I am using this at the moment.
Re:Goodbye CoffeeScript, Hello TypeScript by acjohnson55 on Tuesday October 20, 2015 @01:53PM (#10420654)
This comment would be more useful if you made an actual argument. But to imply that you can't comprehend any possible gain for using another language that overcomes the downsides (which you don't specify) isn't constructive.
Re:Goodbye CoffeeScript, Hello TypeScript by amorphid on Tuesday October 20, 2015 @03:14PM (#10421127)
I like pure JS over CoffeeScript (and other something-to-JS solutions) because:

- Writing JS gives me a better feel for how the language actually works

- I like the line number in the JS I'm debugging to equal the line in my source code

- There's less magic to understand & deal with

- CoffeeScript automatically returns the last line of a function, and I don't always like that

Re:Goodbye CoffeeScript, Hello TypeScript by klibertp on Tuesday October 20, 2015 @05:32PM (#10421958)
> - Writing JS gives me a better feel for how the language actually works

Only because you know it better...

> - I like the line number in the JS I'm debugging to equal the line in my source code

Source maps.

> - There's less magic to understand & deal with

https://medium.com/@c2c/nodejs-a-quick-optimization-advice-7...

> - CoffeeScript automatically returns the last line of a function, and I don't always like that

Use explicit return then.

Re:Goodbye CoffeeScript, Hello TypeScript by mreiland on Tuesday October 20, 2015 @06:29PM (#10422278)
Well when you pretend that Coffeescript is just another language (like Java, or C#?), then it does become difficult to understand my statement.

Fortunately, most everyone else seems to understand what Coffeescript is, and thus they were able to grok my meaning.

Re:Goodbye CoffeeScript, Hello TypeScript by 0xcolton on Tuesday October 20, 2015 @02:21PM (#10420820)
I have the same feeling. When I was a less experienced programmer, I found coffeescript to be a great tool for helping me to write 'better-looking' code while avoiding the 'bad parts' of javascript. Later, I decided to focus my expertise on javascript, learning its imperfections and beauties. Reading through parts of the sourcecode for Node.js and the popular Express.js library, I became more comfortable writing pure javascript. It now seems to me like a much more practical solution to just learn javascript and stop trying to write in a different language than the one used by the runtime
Re:Goodbye CoffeeScript, Hello TypeScript by chc on Tuesday October 20, 2015 @03:45PM (#10421335)
I don't know very many people who write server-side code in C or ASM, so "stop trying to write in a different language than the one used by the runtime" doesn't seem to be a very popular rule outside of the JS world either.
Re:Goodbye CoffeeScript, Hello TypeScript by Animats on Tuesday October 20, 2015 @01:40PM (#10420572)
But then you wouldn't have a complicated build process to run, allowing free time for web surfing.
Re:Goodbye CoffeeScript, Hello TypeScript by rblatz on Tuesday October 20, 2015 @01:43PM (#10420598)
Because the tooling you get when you start using a statically typed language is superior. In a massive JS application things become a lot easier to refactor when you start using Typescript.
Re:Goodbye CoffeeScript, Hello TypeScript by ex_ex_nihilo on Tuesday October 20, 2015 @01:54PM (#10420660)
Javascript is a typed language.
Re:Goodbye CoffeeScript, Hello TypeScript by alextgordon on Tuesday October 20, 2015 @02:01PM (#10420709)
and that type is the string.

    > 3 == "3"
    true
    > 3 * "3"
    9
Re:Goodbye CoffeeScript, Hello TypeScript by ex_ex_nihilo on Tuesday October 20, 2015 @02:12PM (#10420777)
In the above case, Javascript is coercing the strings to numbers.

=== does no type coercion. You can also coerce types manually. JS is not statically typed, but it is typed.

Re:Goodbye CoffeeScript, Hello TypeScript by alextgordon on Tuesday October 20, 2015 @02:55PM (#10421027)
I defer to Wikipedia's definition:

> A language is typed if the specification of _every_ operation defines types of data to which the operation is applicable, with the implication that it is not applicable to other types.

For a language to be typed, both the data must have a type and the operations must have a type specification.

    > "a" * "b"
    NaN
In a dynamically typed language, that specification is enforced at runtime.

    > true / false
    Infinity
In a statically typed language, that specification is enforced by a compiler.

    > setInterval(function(){ console.log("hi") }, "later")
    > hi
    > hi
    > hi
    > hi
    ...
As far as I can tell, JavaScript doesn't concern itself with any of that. It's not typed.
Re:Goodbye CoffeeScript, Hello TypeScript by ex_ex_nihilo on Tuesday October 20, 2015 @04:47PM (#10421709)
You are a bit confused. The == operator specifically does implicit type conversion. You want to use === to avoid implicit coercion. And you always have the option to explicitly coerce type, as I explain below.

Javascript's type coercion leads to some wacky things like

> [] == []

> false

But it's actually all perfectly consistent once you understand what the compiler is doing with type (and JavaScript is compiled, not interpreted). == is an operator that will always try to coerce its operands to numbers, but the way it gets there can be circuitous.

You can specify type in JavaScript and avoid implicit coercion, you can use type constructors (generally worse) or certain unary operators. Ex:

> var foo = "12"

> var bar = +foo - 5; //+ explicitly converts foo to a number

Re:Goodbye CoffeeScript, Hello TypeScript by Hupriene on Tuesday October 20, 2015 @03:41PM (#10421301)
See step 10 and onward of: http://www.ecma-international.org/ecma-262/6.0/index.html#se... (for example)

Javascript is typed, it just makes a lot of crazy decisions about what operations an operator does.

Re:Goodbye CoffeeScript, Hello TypeScript by rblatz on Tuesday October 20, 2015 @02:04PM (#10420735)
Sorry, I meant statically typed, I always misuse that bit of terminology when talking about JavaScript, thanks for correcting me.
Re:Goodbye CoffeeScript, Hello TypeScript by drumdance on Tuesday October 20, 2015 @03:05PM (#10421079)
Compiler error catching is a big bonus for me.
Re:Goodbye CoffeeScript, Hello TypeScript by venomsnake on Tuesday October 20, 2015 @02:12PM (#10420774)
Too weakly typed (pre ES6) for big codebases.
Re:Goodbye CoffeeScript, Hello TypeScript by pixie_ on Tuesday October 20, 2015 @02:58PM (#10421045)
ES6 doesn't have static typing either.
Re:Goodbye CoffeeScript, Hello TypeScript by dkarapetyan on Tuesday October 20, 2015 @01:43PM (#10420592)
People did but now that there are better languages that transpile to it and are just as readable and using plain javascript is kinda silly. TypeScript is a superset of javascript so if you're not using it you better have a really good technical reason.