Live data from Hacker News

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

github.com

21–28 of 28 posts

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

#21
post #17
post #14

Earlier quoted context omitted.

Yes you are missing something. We web developers are stuck with javascript in the browser. Any proposed solution would be "bolted on" to javascript.

If it's as simple as "javascript because web" as you suggest, how does that jibe with things like Electron (js desktop apps) and back-end JS without a web facing component? None of those people had to pick JS.

None of them _had_ to pick JS, but many of them prefer it because they already know JS from building web apps.

The projects are different, but there's a lot of crossover in terms of the people behind them.

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

#22
post #19

Earlier quoted context omitted.

Spec isn't a type system - it's an immensely powerful abstraction for describing your data that can be leveraged for validation, coercion, error reporting, and automated test generation. This, I think, is what many of us wish our type systems could do. I think the thing you're missing is that dynamism is not about avoiding types, it's about having the flexibility to define your own type system. Clojure actually has r…

> Immensely powerful abstraction Let's take a look. > Validation Validation typically means that given a set of shapes of data from a large class we should determine whether a certain instance fits within a smaller class. For instance, parsing selects out valid strings amongst all strings. Haskell has a number of libraries like this. Let's use JSON for example. We create instances of the typeclass class FromJSON a wh…

I didn't see him claiming that spec is better than all type systems. Obviously, Haskell has one of the better type systems. Languages like C# and Java are not near as expressive so when he says most type systems, I'd agree...spec offers more expressivity than the type systems in these languages while remaining as an opt-in choice.

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

#23
post #15

Earlier quoted context omitted.

I donno man, the longer I use typed languages the more I hate untyped ones, if only for the IDE help alone. All the newer static languages use type inference anyways so its not that common to need to specify explicitly. Besides, if you want to turn off the type system you can just cast to object or use "any" in the case of typescript. JavaScript's untyped insanity is also the main reason it's around 10x slower than c…

People vote with their feet, and while I'm really sympathetic to everything you're saying about static typing, it's hard to argue that reality is producing a lot of really popular dynamically typed languages. JS being exhibit #1, but also python, ruby, clojure, and on and on. Take a look at how fast javascript mutates, I'd argue that rate of mutation is one of the things you can do in a dynamically typed language. Ja…

I'm in the opposite camp, it feels like js is mutating quickly to try to fix the rediculous problems with the language because people are forced to use it.

You don't see such sweeping changes in other languages that have been around much longer and used more widely than js.

JavaScript just got a package manager, the module system was hacked on a few years ago and still isn't standardized, the build tools change every other year and still largely suck, it still doesn't support multithreading, the object system is super wonky, it doesn't support specific float/integers which seems to break math constantly. None of these things are an issue in any other language I can think of, these features are in language V1.0

I expect developers to jump ship immediately when a replacement without these core problems reaches critical mass.

Google has been looking into this for a while, and Dart was designed with the assumption that JavaScript fundamentally sucks and can't be fixed.

This has happened before... Look what happened the perl when Python started to gain steam. It used to be pretty much the #1 way to write websites, now you would be a fool to use perl over Python on almost anything.

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

#25

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.

> Have you used js.spec or clojure.spec in production?

Not yet, but I have some use cases (mostly validation).

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

#26
post #14
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…

Yes you are missing something. We web developers are stuck with javascript in the browser. Any proposed solution would be "bolted on" to javascript.

WASM will be here soon, and from that point on we can elegantly compile from any language to the browser platform.

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

#27
post #20
post #5

Earlier quoted context omitted.

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.

Parsing and generative testing are well-covered by static types, but I'll give you that contracts can enforcing things static types cannot. That said, static types can enforce things that contracts cannot, too. Furthermore, in my experience I find use of the things that static types can catch and contracts cannot on a nearly hourly basis while I rarely to never use things that contracts can check but static types can…

> static types can enforce things that contracts cannot

Example, please?

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

#28
post #27
post #20

Earlier quoted context omitted.

Parsing and generative testing are well-covered by static types, but I'll give you that contracts can enforcing things static types cannot. That said, static types can enforce things that contracts cannot, too. Furthermore, in my experience I find use of the things that static types can catch and contracts cannot on a nearly hourly basis while I rarely to never use things that contracts can check but static types can…

> static types can enforce things that contracts cannot Example, please?

Sure. Consider the type

    forall a. a
With mild conditions on what the program fragment achieving this type can do I can be certain that this function does not return. It is an error, an infinite loop, or simply does not exist.

No contract can verify this because they inspect the value and thus get stuck by infinite loops.

I don't use that sort of thing often, but here's a simpler one:

    sort :: Ord a => [a] -> [a]
I know that `sort` only uses the ordering properties of the values within the list. It could be generalized to `forall a . (a -> a -> Ordering) -> [a] -> [a]` in which case it would be totally oblivious to the values inside of the list except in that it probably applies that function.

No contract system can examine functions. No contract system can prove universals. Types can do both (in certain, principled ways).

---

Another interesting example is handling something like a channel. In Haskell, we have the type `TChan a` which is a channel carrying values of type `a`. In Clojure, the best we can do for giving a contract to a core.async chan is to say it's a "chan containing something" or even "a dereffable thing returning something". To use a contract here we'd have to check every value that ever pops off the channel.

Contracts check shape, but cannot ensure usage.

Post reply on HN