Static typing? #1852

Closed
ghost opened this Issue Nov 10, 2011 · 11 comments

Projects

None yet

9 participants

@ghost
ghost commented Nov 10, 2011

Would it be a good idea to introduce static typing in CS?

Eg.

string greet = (Coder me, number|string age, string name) -> "Hi. I am a #{me.getTitle()}. My name is #{name} and I am #{age} years old"

This could solve some issues we have with JS:

  • Provide a way for IDEs to autocomplete. So when I type "me." it will give me all the instance methods for Coder. This is impossible atm.
  • Good for documentation and clean code.
  • No need for manual checking code.
  • Less bugs.

Thoughts?

UPDATE:

Found this one that seems to be very popular: http://disnetdev.com/contracts.coffee/

Any thoughts on implementing it into the core of CS?

@paulmillr

Obviously, static typing cannot be done, because javascript is a dynamic language. Contracts.coffee is an implementation of design-by-contract and its predicates are checked in runtime.

There were some issues in coffee-script bugtracker and they was closed (#52, #116, #1833).

1 year-after edit: sorry folks, I knew a little about typing at this point. Yes it’s possible to make typed coffee.

@TrevorBurnham
Collaborator

What Paul said. Type-checking is way beyond the intended scope of CoffeeScript. If you want a statically-typed language that compiles to JS, look at Contracts.coffee or Google Dart.

@steida
steida commented Sep 13, 2012

https://github.com/Steida/este uses Google Closure with CoffeeScript syntax, so static typing with compilation is possible.

@dimack
dimack commented Oct 24, 2012

Obviously, static typing cannot be done, because javascript is a dynamic language

Really? http://typescriptlang.org/

@Soviut
Soviut commented Oct 24, 2012

Later versions of ECMAScript have optional typing using the i:int format, ActionScript and UnityScript are two derivations that use it. However, CoffeeScript is a pre-processor, not a Javascript compiler! So while it could accept the typing syntax that later ECMAScript versions support, it wouldn't in any way enforce this static typing. It validates its own syntax and converts it to JavaScript, it doesn't prevent you from writing bad code!

@olanod
olanod commented Jul 15, 2013

is it completely discarded? it would be a great option if CS could compile to something like asm.js or JS with closure annotations.

@vendethiel
Collaborator

There's been discussions about this already. We don't have more informations than JS JITs

@steida
steida commented Jul 15, 2013

If Michael Ficarra ever finish CoffeeScript Redux, I will use it for EsteScript. CoffeeScript with type annotations for Google Closure Compiler. But annotations based static typing is good enough for now.

@TobiaszCudnik

Ive did a workaround for this particular usecase, reusing typescript's static typing via external d.ts files, which are merged into the source during compilation.

Its called CompiledCoffee. Enjoy.

@vendethiel vendethiel added the wontfix label Nov 3, 2014
@taoeffect

Have you folks seen TypedCoffeeScript by @TobiaszCudnik?

@taoeffect

(Maybe?) there's also the possibility of using Flow with CoffeeScript?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment