Live data from Hacker News

Contracts For CoffeeScript

disnetdev.com

11–20 of 36 posts

Re: Contracts For CoffeeScript

#12
post #5

Earlier quoted context omitted.

Not quite. isEven = (x) -> x % 2 is 0 f :: (!isOdd) -> !isEven f = (x) -> ...

Not hardly. The runtime can detect that a function invocation violates a post-condition only after all of that function's side-effects have been run.

I believe jashkenas' example defines both a pre-condition and a post-condition, specifying that f accepts only odd numbers and returns only even numbers ('!' here is the operator for new contract, rather than logical negation). If f is called with anything other than an odd number, an error will be thrown right away, before the body of the function is run.

Re: Contracts For CoffeeScript

#13
ok, figured out that it takes care of the existing prototype operator (::) in lexing [1],[2]. It seems little annoying but guess I'll get the hang of it.

[1] https://github.com/disnet/contracts.coffee/blob/master/src/l...

[2] https://github.com/disnet/contracts.coffee/blob/master/src/l...

Re: Contracts For CoffeeScript

#14

This is great, it's like Google's compiler library[0] but with run-time checking! Coffee script is still very hard to debug, this should help avoid about 80% of the mistakes I normally make when coding. [0] http://code.google.com/closure/compiler/

You're thinking of the Closure Compiler and its annotations, not the Closure Library.

Re: Contracts For CoffeeScript

#15
How does it integrate with the `coffee` executable? Does coffeescript have a compiler plugin system, or are you patching the compiler? Will this cause me problems when I try to update my coffeescript compiler?

Re: Contracts For CoffeeScript

#16

This is great, it's like Google's compiler library[0] but with run-time checking! Coffee script is still very hard to debug, this should help avoid about 80% of the mistakes I normally make when coding. [0] http://code.google.com/closure/compiler/

You're thinking of the Closure Compiler and its annotations, not the Closure Library.

Ah you're right, edited

Re: Contracts For CoffeeScript

#17
post #7

Earlier quoted context omitted.

What's your point?

That while this looks like a good extension to CoffeeScript, it's unfortunate that Haskell's type syntax was appropriated when the relationship between contracts and types is tenuous at best. There are good uses for static type checkers and design by contract, but neither one is a good substitute for the other.

So you're upset about the syntax? Seems like an odd complaint.

Re: Contracts For CoffeeScript

#18
I ♥ where it's going! "Nhaa, I won't use a statically typed language.. I prefer javascript with coffeescript syntax. But, I'll use contracts and tests to make it robust." Hands down, it's great and I'll definitely use it.

Also +1 to be able to define your own type.

Re: Contracts For CoffeeScript

#19
post #15

How does it integrate with the `coffee` executable? Does coffeescript have a compiler plugin system, or are you patching the compiler? Will this cause me problems when I try to update my coffeescript compiler?

It's a fork of CoffeeScript so it replaces your "coffee" executable. If you don't want to overwrite your normal CoffeeScript compiler just run the contracts.coffee "coffee" executable from its own directory.

I mention this briefly towards the end of the quick start section of the doc: http://disnetdev.com/contracts.coffee/#quickstart

Re: Contracts For CoffeeScript

#20
post #7

Earlier quoted context omitted.

What's your point?

That while this looks like a good extension to CoffeeScript, it's unfortunate that Haskell's type syntax was appropriated when the relationship between contracts and types is tenuous at best. There are good uses for static type checkers and design by contract, but neither one is a good substitute for the other.

I'm not sure that the relationship between types and contracts is all that tenuous.

They both work to enforce program invariants and there's a large overlap in the invariants they can express. Usually contracts are checked dynamically (as in contracts.coffee) but this is not a hard requirement (for example .net's code contracts can be statically checked [1]).

http://msdn.microsoft.com/en-us/devlabs/dd491992

Post reply on HN