Hacker News new | past | comments | ask | show | jobs | submit login

Not sure what the weird hostility is all about, but... I think what they meant is that CoffeeScript doesn't support explicit variable declarations, instead implicitly defining variables when they are first referenced. That makes it hard to add explicit type declarations, because you've got nowhere to declare them.



Yes that's exactly the point I was making.

Adding types atop something like that would be particularly difficult though not impossible. The hardest part is doing something that maintains the magic of picking the proper scope to define a var at without adding "var" declarations.


Sorry, no weird hostility, just an observation. The weirdness comes more from the way how you guys think about creating a typed language. What the heck would a CS compiler with static type checking have to do with var statements apart from generating them in the final JS as it does now already?


Well, in TypeScript you attach the type declaration to the variable declaration:

    let foo: number;
It's true that you could add the type declaration to the first assignment of the variable, as in:

    foo: number = 42
...but that's kind of awkward, because CoffeeScript only has an assignment expression and not a variable declaration statement. You can hack the two together but it's going to make things confusing and complex for the compiler to implement. What happens if you do this:

    foo = 42
    ... 30 lines later ...
    foo: string = "hello"
They're both just assignment expressions, but now they can carry extra metadata about the variable that's being assigned, so there's all sorts of cases you have to consider.

Anyways, I was just trying to clarify what the comment you replied to meant. IMO, the real problem is that TypeScript's type system is incredibly powerful, and a huge portion of the compiler is devoted to static checking for it.

Even if the CoffeeScript compiler could support types, it makes very little sense to spend the effort when TypeScript already exists. The syntactic difference between the two languages is too small. I could see an option for CoffeeScript to target TypeScript as a transpilation output, but then you'd lose the tooling (tslint) built for TypeScript.

And again, why? If you want types, write TypeScript. That's what it's there for.


If you don't have var statements then you lose the number one place to specify the type of the variable.

It's not about making whatever inferences you can from the code, it's about giving the compiler/typechecker the detail it needs to make more accurate inferences.




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

Search: