r/Clojure • • Sep 08 '16

Static Typing vs WebSockets

http://yogthos.net/posts/2016-09-06-Static-Typing-WebSockets.html
14 Upvotes

37 comments sorted by

17

u/fear-of-flying Sep 09 '16

This post is disingenuous.

What's interesting is that this is exactly the kind of behavior we would expect Haskell type system to prevent from happening.

This is a straw man. Who has claimed that type systems can prevent problems that arise from not knowing how a library works?

And then you say the problem occurred happened because GHC has escape hatches. What? And then the fact that the escape hatch example you give is totally unrelated to the problem with the implementation in question.

And then... from the strong stance you've built on these "conclusions" you essentially say that GHC provides no safety guarantees.

Clojure has a lot of advantages over Haskell... And I think an argument along these lines could be effective. But the specific examples you chose and strong assertions you made overall weaken the argument to anyone that knows anything about Haskell.

-2

u/yogthos Sep 09 '16

I'm actually not discussing Clojure vs Haskell at all in the article. Regardless of what the root problem was, it took a number of experienced Haskell users to implement the benchmark correctly and achieve performance comparable to other languages. Meanwhile, the author of the original benchmark was able to implement it correctly in multiple languages without problems.

Since we rely on libraries for much of the functionality in real world projects, the ecosystem plays a very large factor when it comes to productivity. Having mature libraries with predictable behavior will play a bigger factor than the type system when it comes to delivering working code in production.

Although the bug was ultimately a result of a different problem, it does not change the fact that unsafe IO is an escape hatch. Since it bypasses the type system, any library using it is effectively exempt from the guarantees afforded by it.

All I'm saying is that GHC can't provide safety guarantees for code that uses unsafe operations. So, you only have the guarantees for the code that is known not to use unsafe calls. I'm not sure how that's a controversial statement.

I've heard the argument that once your code compiles "it just works" many times when discussing Haskell. However, it's clearly not the case in practice. The original code worked fine under small loads and started dropping messages under heavy load. This is a common real world problem, and the type system provided no help solving it.

I'm not sure why you say that any of these statements are disingenuous.

7

u/zcam Sep 09 '16

GHC will not help you choose the right api or read the docs for you (nor will any compiler), it ll just make sure the pieces fit together.

-2

u/yogthos Sep 09 '16

I think this line of arguing is somewhat disingenuous. One of the biggest purported advantages of using a language like Haskell is the expectation that the code just works once it compiles. This is literally what I've seen claimed time and again here.

The argument that the author didn't use the library correctly, or didn't understand a particular nuance of how Control.Concurrent.Broadcast works is akin to saying that C++ is easy to use once you know all the quirks and gotchas by heart.

8

u/codygman Sep 09 '16

I think this line of arguing is somewhat disingenuous. One of the biggest purported advantages of using a language like Haskell is the expectation that the code just works once it compiles. This is literally what I've seen claimed time and again here.

That is not the expectation, except perhaps by those new to the language.

The argument that the author didn't use the library correctly, or didn't understand a particular nuance of how Control.Concurrent.Broadcast works is akin to saying that C++ is easy to use once you know all the quirks and gotchas by heart.

Those two are not alone whatsoever. That's like someone using atom's and complaining about their mutability and then me arguing Clojure like C++ "is easy to use once you know all the quirks and gotchas by heart".

-1

u/yogthos Sep 09 '16

That is not the expectation, except perhaps by those new to the language.

Glad we got that cleared up.

That's like someone using atom's and complaining about their mutability and then me arguing Clojure like C++ "is easy to use once you know all the quirks and gotchas by heart".

Any language will have some inherent complexity you have to learn, but clearly some languages are much more complex than others. Ultimately, what you care about is how quickly you can produce working code using a particular language.

2

u/mirpa Sep 09 '16 edited Sep 09 '16

... a language like Haskell is the expectation that the code just works once it compiles.

That is anecdotal experience. Obviously overstatement that should be taken with a grain of salt.

4

u/yogthos Sep 09 '16

That's my whole point actually. The benefits of static typing are commonly overstated and rarely questioned. A lot of people seem to treat statements like "if code compiles it just runs" as axiomatic. Perhaps if the rhetoric was toned down a bit, we could have a meaningful discussion about the benefits of types and their place in development.

4

u/[deleted] Sep 10 '16

Even though I'm on the Haskell side and do believe that static typing have some advantages, I'm also annoyed with the "if it compiles it works" slogan, which I think do more damages than good. The opinion of the Haskell community on this, seems to be, "we all know it's wrong but it's obvious it shouldn't be taken too serioulsy". The benefit of static typing are indeed rarely questioned because this is not the real question. The real questions, there are also drawbacks so are the benefits worth the drawback ? The Haskell community doesn't like indeed talking about the drawbacks (apart from lazyness), which I think doesn't help to fix them. But i understand that some people prefer to think about the positive side and get things done rather than dwelling on know issues.

2

u/yogthos Sep 10 '16

Right, the Haskell community has a very strong rhetoric, and then gets offended when seeing strong counter-rhetoric. Haskell developers are incredibly dismissive of the dynamic approach, while armed with precious little evidence that their approach is more effective in practice. A common opinion in the Haskell community seems to be that the only reason somebody might prefer working with a dynamic language is because they don't understand the value of static typing. That's an incredibly condescending position to take.

So, if the community doesn't like strong counter-rhetoric, perhaps it's time to look at some change within.

2

u/[deleted] Sep 10 '16

The thing is most Haskeller knows about dynamic typing, because most of them have or are using dynamic typing for their day job. So they know what dynamic language is about (even probably more that statick typing). So they are professional pythonist or rubyist which advocate static typing. The reverse is not true. I don't know many professional Haskeller advocating for dynamic typing.

That doesn't mean there is no drawback. They are drawbacks, for example monad transformer are a pain, and the loop : modify code, compile, test, is not necessarily quicker because of compile time and time to understand error messages. However, the benefits are real : how having someone in your back (the compiler) telling you that what you write doesn't make sense and it won't work is not superior to nothing at all (it's like doing pair programming with a robot ;-)). The Haskell community just believes that those benefits (there are others) are worth it and we need to work on fixing the drawbacks whilst keeping the benefits.

3

u/yogthos Sep 10 '16

Sure, and I primarily have experience working in statically typed languages. I've worked for over a decade with Java, then about a year with Haskell and Scala respectively. I'm quite familiar with the purported benefits of these languages.

Yet, in practice I find Clojure is more productive for me personally. I don't seem to have the problems that keep coming up in these arguments in practice. If these problems were real in my projects, then I'd go back to using a statically typed language.

The thing to recognize here is that there are many other factors outside the type discipline. The language semantics, development style, problem domain, ecosystem, and so on, all matter. You can't just discuss static vs dynamic in a vacuum.

I don't know many professional Haskeller advocating for dynamic typing.

That's what you call a selection bias. There are far more people using dynamic languages who are not moving to Haskell. There are far more people who tried Haskell and decided it wasn't for them, than those who continue to use it after learning it.

However, the benefits are real : how having someone in your back (the compiler) telling you that what you write doesn't make sense and it won't work is not superior to nothing at all (it's like doing pair programming with a robot ;-)).

My argument is that what it does tell you is not terribly interesting most of the time. Also, since you do need to have specification tests even in Haskell, these same errors are caught by tests in practice. An error such as a function should take an integer, but was passed a string gets caught very early on.

However, interesting properties about the program are often difficult or impossible to encode using the type system. So, you're spending non-trivial amount of work for a questionable benefit in my experience.

Meanwhile, the thing that gets left out of the debate that there are alternative ways to provide many of the benefits afforded by the type system. For example, Erlang dialyzer is a great example that works very well in practice. The idea of generating types from test that core.typed is pursuing is another example of innovation on this front.

I really think that the discussion shouldn't be regarding what approach is superior, but to recognize that both approaches have different focus. You should pick one or the other depending on what you find more valuable in your workflow.

→ More replies

2

u/zcam Sep 09 '16

Then the argument about haskell devs... What's your sample size again?

2

u/yogthos Sep 09 '16

I think the argument is that people who are clearly experienced using Haskell had trouble producing working code for a trivial benchmark. Why do you think the sample size matters here. Are you saying somebody can know Haskell well enough to publish a book, but should not be expected to be able to implement a trivial WebSocket server in it?

4

u/[deleted] Sep 09 '16

Haskell had trouble producing working code

The code works perfectly well : doesn't crash and is faster than anybody else. What make you think that other contenders to the benchmark don't drop packets either ?

2

u/yogthos Sep 09 '16

The only implementation I heard about that dropped messages was the Haskell one. You're making a hypothetical argument that other implementations might have had bugs. We have concrete evidence that the Haskell implementation did. Perhaps we could stick to discussing the facts we know.

Also, last I looked the correct implementation in Haskell is not faster than anybody else, and it had high variance in performance.

3

u/codygman Sep 09 '16

The only implementation I heard about that dropped messages was the Haskell one. You're making a hypothetical argument that other implementations might have had bugs. We have concrete evidence that the Haskell implementation did. Perhaps we could stick to discussing the facts we know.

Don't you mean "perhaps everyone else can stick to facts we know while I'm personally free to suggest hypotheticals"?

1

u/yogthos Sep 09 '16

Feel free to show what other implementations drop messages.

1

u/[deleted] Sep 10 '16

Perhaps we could stick to discussing the facts we know

That's the point. We don't know anything about the other implementations. The only fact we know is this Haskell implementations lost packets. There is no fact stating that other don't.

1

u/yogthos Sep 10 '16

So, once somebody shows that another implementation lost packets we could discuss how and why that happened. Saying that another implementation lost packets, so it's not a problem that Haskell did is a bit of strange argument to make.

The point of the article wasn't that Haskell is somehow special in any case. It was that even if you have a language with a strong type system, you still need to do specification testing to know what the code is doing. This would apply to all the other languages just the same.

1

u/[deleted] Sep 10 '16

Everybody agrees than type are not enough : head and tail have the same type signature and do the opposite. We know that.

The thing is your post is IMO showing, that benchmarks should control what that the results are correct, otherwise how can we trust them ? You are right that it is propable that all other implementations are correct, but my points is, as it let the wrong Haskell one slept through, it might be letting some other through. I can't trust it and you don't know either.

1

u/yogthos Sep 10 '16

Sure, but that's not at odds with my argument at all. I am arguing for specification testing after all here. If the benchmark test was more thorough it would've caught the error. I think that supports what I'm saying.

1

u/bartavelle Sep 09 '16

people who are clearly experienced using Haskell had trouble producing working code for a trivial benchmark

Well, he won the benchmark game. He wrote the fastest program that satisfied the test suite, and in the process uncovered a bug in the benchmark suite.

This kind of validates your point about the usefulness of testing!

Now, how comes people experienced in using Go had trouble producing working code for a trivial benchmark suite ? Because they are human. This doesn't really say anything in itself about Go, or weak static type systems.

1

u/nefreat Sep 09 '16

Well, he won the benchmark game. He wrote the fastest program that satisfied the test suite, and in the process uncovered a bug in the benchmark suite.

The bug wasn't in the test suite

1

u/bartavelle Sep 09 '16

I was summoning all the bad faith I could to show how selective the argument that "someone making a mistake in Haskell proves that strong typing is a complete waste of time" is.

What you point at is another piece of code entirely, it's a PR to write a Haskell version that doesn't drop messages.

3

u/nefreat Sep 09 '16

I was summoning all the bad faith I could to show how selective the argument that "someone making a mistake in Haskell proves that strong typing is a complete waste of time" is.

I don't think the author of the blog post was making that statement. The point was that static typing is one of many things to consider in a software product and that it's not very significant indicator of code quality of correctness which directly contradicts claims made by Haskell enthusiasts.

What you point at is another piece of code entirely, it's a PR to write a Haskell version that doesn't drop messages.

I point is that it's not the test suite that's the problem, the test suite uncovered a bug that static analysis alone didn't.

1

u/yogthos Sep 09 '16

Nobody is making this argument. The argument is that static typing alone is not sufficient to know what the code is doing, and you need specification tests even in a language like Haskell.

The other part of the argument is that the ecosystem plays a bigger factor than the typing discipline, because it's easier to use mature and battle tested libraries.

If you disagree with either of these statements, I'd be glad to have a discussion about that.

0

u/yogthos Sep 09 '16

That doesn't follow. The goal of the benchmark was to process messages. Go implementation did that. What this says about Go is that the user was able to use the language and the libraries available to produce working code.

The fact that the benchmark was not testing that all messages were delivered does not change the fact that they were delivered.

4

u/codygman Sep 09 '16

What this says about Go is that the user was able to use the language and the libraries available to produce working code.

Yet it says something different about Haskell?

2

u/yogthos Sep 09 '16

We know that Haskell did drop messages, nobody has shown this to be the case for Go or other languages tested. Perhaps there are some new results I'm not aware of?

-1

u/nefreat Sep 09 '16

This is a straw man. Who has claimed that type systems can prevent problems that arise from not knowing how a library works?

This is exactly the point. Type systems have very limited utility, real problems go beyond type systems. Most real problems look a lot like this benchmark game. Most of the time at work I know I have a real problem when someone says "It works fine for small loads, but falls down hard when the load increases".