Live data from Hacker News

Show HN: js.spec, a JavaScript implementation of clojure.spec

github.com

1–10 of 28 posts

Re: Show HN: js.spec, a JavaScript implementation of clojure.spec

#2
Have you used js.spec or clojure.spec in production? Has it helped you catch bugs that you would have otherwise missed? How does the runtime-only limitation work out in practice?

I know that flow has prevented me from checking in bugs, because I've tried to push up code with e.g. misspelled property names and the pre-push hook stopped me.

Re: Show HN: js.spec, a JavaScript implementation of clojure.spec

#3

Have you used js.spec or clojure.spec in production? Has it helped you catch bugs that you would have otherwise missed? How does the runtime-only limitation work out in practice? I know that flow has prevented me from checking in bugs, because I've tried to push up code with e.g. misspelled property names and the pre-push hook stopped me.

One of the Clojure validation libs predating spec, schema, has saved us from a ton of errors, and works similarly. It also opens up reasoning about data shape- eg, auto-generating test data based on schemas. spec's support for that use case is even better.

EDIT: You can see schema in action in https://github.com/cardforcoin/shale. In fact, the latest build surfaced a bug via schema- https://circleci.com/gh/cardforcoin/shale/379. Next version we're planning to migrate to spec.

Re: Show HN: js.spec, a JavaScript implementation of clojure.spec

#4
I think of dynamic typing in a language as a big pro and a big con at the same time, but it's one of the things that makes a language like JavaScript or closure what it is.

I love typing systems too, there are compelling advantages...and disadvantages.

I guess sometimes what seems strange is attempts to bolt type systems on to fundamentally dynamic languages, like adding two extra wheels to a motorcycle, extra fairing, and then calling it a car.

I don't fault anyone for wanting a car. But if you wanted a car, why not start off with a statically typed language? Why bolt this stuff on really in contravention to what the dynamic languages are trying to be?

Perhaps this is JavaScript fatigue in a new guise? If everything has to be JavaScript (for whatever reason) then having no static typing ever may be hard to live with?

Am I missing something or does the motorcycle with two extra wheels seem destined to be clunkier and less flexible than a proper car?

Re: Show HN: js.spec, a JavaScript implementation of clojure.spec

#5
post #4

I think of dynamic typing in a language as a big pro and a big con at the same time, but it's one of the things that makes a language like JavaScript or closure what it is. I love typing systems too, there are compelling advantages...and disadvantages. I guess sometimes what seems strange is attempts to bolt type systems on to fundamentally dynamic languages, like adding two extra wheels to a motorcycle, extra fairin…

Spec (and more generally, contracts) aren't just about "making up" for the lack of static typing. They can encode a variety of invariants that a type-system can't, and are also useful for parsing (see coercion) and generative testing. Unlike most type systems, they also aren't required across the whole code base.

Re: Show HN: js.spec, a JavaScript implementation of clojure.spec

#6
post #4

I think of dynamic typing in a language as a big pro and a big con at the same time, but it's one of the things that makes a language like JavaScript or closure what it is. I love typing systems too, there are compelling advantages...and disadvantages. I guess sometimes what seems strange is attempts to bolt type systems on to fundamentally dynamic languages, like adding two extra wheels to a motorcycle, extra fairin…

> I think of dynamic typing in a language as a big pro and a big con at the same time, but it's one of the things that makes a language like JavaScript or closure what it is.

Well JavaScript weak type system allows it to be shaped basically however the user want, so to an extent it's a language that make it easy to build something upon, like another languages or adapt any library from any other language.

JavaScript however definitely introduced functional programming to a generation of developers, no question.

But it was designed for extremely sloppy ones too. JS tries hard not to throw a type error.

> I don't fault anyone for wanting a car. But if you wanted a car, why not start off with a statically typed language

When I started programming I thought type declarations were getting in my way ... now I'm using Go which has one of the most rigid type system of all.

When I was using node I was like writing 10 000 lines of code a day ... now I have hard time making sense of what I wrote 3 years ago, let alone understanding someone else's JS codebase.

Re: Show HN: js.spec, a JavaScript implementation of clojure.spec

#7
post #5
post #4

I think of dynamic typing in a language as a big pro and a big con at the same time, but it's one of the things that makes a language like JavaScript or closure what it is. I love typing systems too, there are compelling advantages...and disadvantages. I guess sometimes what seems strange is attempts to bolt type systems on to fundamentally dynamic languages, like adding two extra wheels to a motorcycle, extra fairin…

Spec (and more generally, contracts) aren't just about "making up" for the lack of static typing. They can encode a variety of invariants that a type-system can't, and are also useful for parsing (see coercion) and generative testing. Unlike most type systems, they also aren't required across the whole code base.

It depends on how you implement the gradual typing as well. Through contracts is one way (probably the bad way, since they still apply at runtime) and static analysis with type annotations is another way. There isn't any reason a sufficient static analyzer couldn't be as powerful as an inbuilt static type system.

This is effectively dragging some of the benefits of static typing to dynamic typing. I wonder why you'd pay the cost of dynamic types though, instead of going the other direction. With type inference you don't need to explicitly write types the entire codebase, and you can opt-in to dynamic types in controlled, explicit scenarios.

Re: Show HN: js.spec, a JavaScript implementation of clojure.spec

#8
post #5
post #4

I think of dynamic typing in a language as a big pro and a big con at the same time, but it's one of the things that makes a language like JavaScript or closure what it is. I love typing systems too, there are compelling advantages...and disadvantages. I guess sometimes what seems strange is attempts to bolt type systems on to fundamentally dynamic languages, like adding two extra wheels to a motorcycle, extra fairin…

Spec (and more generally, contracts) aren't just about "making up" for the lack of static typing. They can encode a variety of invariants that a type-system can't, and are also useful for parsing (see coercion) and generative testing. Unlike most type systems, they also aren't required across the whole code base.

[deleted]

Re: Show HN: js.spec, a JavaScript implementation of clojure.spec

#9
post #5
post #4

I think of dynamic typing in a language as a big pro and a big con at the same time, but it's one of the things that makes a language like JavaScript or closure what it is. I love typing systems too, there are compelling advantages...and disadvantages. I guess sometimes what seems strange is attempts to bolt type systems on to fundamentally dynamic languages, like adding two extra wheels to a motorcycle, extra fairin…

Spec (and more generally, contracts) aren't just about "making up" for the lack of static typing. They can encode a variety of invariants that a type-system can't, and are also useful for parsing (see coercion) and generative testing. Unlike most type systems, they also aren't required across the whole code base.

[deleted]

Re: Show HN: js.spec, a JavaScript implementation of clojure.spec

#10
post #5
post #4

I think of dynamic typing in a language as a big pro and a big con at the same time, but it's one of the things that makes a language like JavaScript or closure what it is. I love typing systems too, there are compelling advantages...and disadvantages. I guess sometimes what seems strange is attempts to bolt type systems on to fundamentally dynamic languages, like adding two extra wheels to a motorcycle, extra fairin…

Spec (and more generally, contracts) aren't just about "making up" for the lack of static typing. They can encode a variety of invariants that a type-system can't, and are also useful for parsing (see coercion) and generative testing. Unlike most type systems, they also aren't required across the whole code base.

[deleted]
Post reply on HN