r/programming • • Oct 26 '17

Clojure vs. The Static Typing World (x-post r/morningcupofcoding)

http://www.lispcast.com/clojure-and-types
59 Upvotes

114 comments sorted by

48

u/Veuxdo Oct 26 '17

Except, over time, you add a fourth and a fifth. Pretty soon, you've got seven or eight of them. Good thing you have a type system to keep track of all of that. And don't get me started about merge conflicts when two branches want to modify the ADT at the same time. That's a digression.

Two things. First, if you ever write a function that started with two parameters and ended up with eight, then you fucked up somewhere. Next time, decompose your functions.

Second, with how does not having a static type system help you keep track of parameters and merge conflicts?

38

u/devraj7 Oct 27 '17

Second, with how does not having a static type system help you keep track of parameters and merge conflicts?

Nice catch. This is the key point, here: advocates of dynamically typed languages often have the impression that because the code looks more naked, it's easier to read and therefore more productive.

What they fail to see is that this nakedness is your safety going out the window in much the same way that not putting on your seat belt will let you get on the road faster but more exposed.

This time you saved by not "fighting the compiler" by providing type annotations requested by the compiler? It means your program has fewer guarantees to be correct.

The time you saved during merges because you don't have to resolve type merge conflicts? It means the two code bases you merged might have been correct but the result might not.

This nice code you now have because you no longer catch exceptions or because you removed error checks? It's nice to read but it will crash in unforeseen ways in users' hands.

15

u/nimblerabit Oct 27 '17

I doubt anyone fails to see that the safety is gone, that's the entire premise of dynamically typed languages isn't it? The argument is that the productivity gained outweighs that downside (whether that's true or not seems to be difficult to prove one way or the other).

20

u/gnuvince Oct 27 '17 edited Oct 27 '17

The argument is that the productivity gained outweighs that downside

That's the part that I don't get. When I code in OCaml and Rust, I use the type system as a tool to guide me as I'm designing and writing my initial code; when I code in Erlang, I would like to have a type system to guide me like that, but I must face the task alone, without much help from the machine. (Erlang has a tool called dialyzer which is... okayish.) I find that I move more quickly when I have the type checker at my side.

-6

u/Radmonger Oct 27 '17

It's not the time saved while coding, it's the time saved by not having to learn to code that way.

14

u/staticassert Oct 27 '17

It's not that hard lol

3

u/sinesSkyDry Oct 27 '17

it seems that with dynamic typing, the difference between it's evangelists and it's haters is not recognizable at least with an onlinepost.

1

u/ForgetTheHammer Oct 28 '17

Types don't guarantee business level correctness (blc), which his the only kind I get paid for.

I'm not saying types don't help with blc but I would like the pl community to not conflate the two.

Clojures repl driven development with fp, immutability and easy property based testing give me a great degree of confidence and productivivity.

2

u/devraj7 Oct 28 '17

Types don't guarantee business level correctness (blc), which his the only kind I get paid for.

I never said they did. I said type annotations increase the level of correctness of your code.

Like many others, you are stating these things as if they are mutually exclusive, but they are not. Use tests. Use FP. Use immutability. Use easy property testing. Use type annotations.

Use them all.

Ignore one of them and your code is likely to be more buggy.

1

u/ForgetTheHammer Oct 28 '17

I think clojure has a very flexible stance towards these types of trade offs. In terms of time spent vs correctness. Most studies I have seen have suggested that clojure fairs very well on the low bug count score.

14

u/[deleted] Oct 27 '17

Two things. First, if you ever write a function that started with two parameters and ended up with eight, then you fucked up somewhere.

This is circular logic, however. You've "fucked up" if you have 8 arguments, because 8 arguments are hard to track.

Well, it follows, then, that if they're not hard to track, then 8 arguments doesn't mean you've "fucked up".

It's interesting that nobody is counting number of arguments in Objective-C and Swift, where all arguments are both statically typed and explicitly named, making reading, writing and refactoring quite trivial.

A language is supposed to help you express a problem as you want to express it. If you keep hitting artificial limits, such as "oh no, I have more than 3 arguments, so I can't make the heads or tails of this" then the language is the one that's "fucked up".

1

u/[deleted] Nov 03 '17

c# has an entire language feature dedicated to helping you track arguments

8

u/devlambda Oct 27 '17 edited Oct 27 '17

Second, with how does not having a static type system help you keep track of parameters and merge conflicts?

The problem here is that this is miscast as a static vs. dynamic typing thing, whereas it's actually about ADTs vs. type hierarchies + multimethods (derive/defmulti/defmethod in Clojure parlance). You can do either with both dynamic and static typing.

First, if you ever write a function that started with two parameters and ended up with eight, then you fucked up somewhere. Next time, decompose your functions.

He's not talking about functions, but the variant branches of an ADT. These are essentially records without a type name (and, if positional, without field names, too) and can thus evolve in pretty much the same way that regular records can.

31

u/gotothere Oct 27 '17

Types as concretions. Rich talked about types, such as Java classes and Haskell ADTs, as concretions, not abstractions.

A Person class isn't abstract and noone really pretends that it is. Haskell gives you abstractions like

  • semigroup - an associative binary operation: eg. strings with append, or lists with contatenation

  • monoid - a semigroup with an 'empty' constructor: eg. strings with "" or lists with []

  • functor - a context with things inside it, and a way of transforming those contained things: eg. map across elements in a list, or map across the single element in a Maybe

An abstraction would ignore the particulars and let you store any information about a person. And while you're at it, it might as well let you store information about anything.

This is exactly what the above abstractions provide, and the first 2 can even be represented in java!

And Haskell has that for ADTs. But can Haskell merge two ADTs together as an associative operation, like we can with maps? Can Haskell select a subset of the keys? Can Haskell iterate through the key-value pairs?

Yes.

  • If it is a semigroup we can append them

  • if they're a monoid we can construct an empty one as well

  • if they're a functor we can transform each item in them

And with all of those we don't specify the concrete type, we just specify the constraint that it is a monoid/functor/etc. A function written with a functor constraint operates over all possible functors, not just the particular concrete type you're interested in.

When you're writing an algorithm in clojure which relies on append being an associative binary operation, you're writing a function which is constrained on semigroup - whether you are allowed to make that explicit or not.

1

u/ForgetTheHammer Oct 28 '17

| A function written with a functor constraint operates over all possible functors, not just the particular concrete type you're interested in.

I think I need a lot of context to understand this. There naive question is what happens if the functions operation is invalid across the functor?

2

u/Potato44 Oct 30 '17

The short answer is that is impossible.

The function gets applied to the contents(e.g. string, int, etc) of the functor(e.g list, maybe, continuation, etc) rather then the functor itself. Being a functor means the 'container' type has a mapping operation(fmap) that applies the supplied function to all the contained values. So because the function applies to the contents rather than the functor itself it can't be incompatible with the functor(But it can be incompatible with the contents, which is a type error).

1

u/killerstorm Oct 27 '17

A Person class isn't abstract and noone really pretends that it is.

I disagree. A class (or interface) is often an abstraction, as it allows changing implementation without violating constraints.

45

u/mixedCase_ Oct 26 '17

I'm reminded of my friend's company. They do medical record software. The standards for medical records have hundreds of types.

In a system like that, you can't write correct types for every kind of entity. You'd never finish before the new spec came out.

Therefore I am to assume the logic that deals with it will never silently break then. What a relief.

If your application is nothing but a dumb pipe then you can choose to have untyped data in languages with powerful type systems. You're not forced to encode all the logic in types, you just have the ability to do it. Because if you're actually processing the data in your application then good types are much closer to a guarantee that the code you wrote does what you want.

And no, guy who always pops up in Clojure/dynamic typing threads, spec files are not a replacement for a type system.

-6

u/yogthos Oct 27 '17

Once you provide empirical evidence supporting the notion that a static type system has significant impact on software quality, we'll talk about needing to provide a replacement for it.

8

u/satsuper Oct 27 '17

3

u/yogthos Oct 27 '17

I think it shows results specific to JavaScript, while broader studies and experiements fail to show correlation between static typing and code quality.

4

u/satsuper Oct 27 '17

I agree it is JS specific and I suspect I probably need to give some other dynamically typed languages a proper look before I can get a broader understanding on this.

Thanks for the links, will give them a read.

5

u/yogthos Oct 27 '17

I think dynamic typing is a lot more problematic in imperative/OO languages. One problem is that the data is mutable, and you pass things around by reference. Even if you knew the shape of the data originally, there's no way to tell whether it's been changed elsewhere via side effects. The other problem is that OO encourages proliferation of types in your code. Keeping track of that quickly gets out of hand.

Clojure embraces immutability, and any changes to the data happen explicitly in a known context. This makes it much easier to know exactly what the shape of the data is at any one place in your application.

Meanwhile, all the data is structured using a set of common data structures. Any iterator function such as map, filter, or reduce can iterate any data structure, and it's completely agnostic regarding the concrete types. The code that cares about the types is passed in as a parameter. Pretty much any data transformations in Clojure are accomplished by chaining functions from the standard library together, with domain specific code bubbling up to a shallow layer at the top.

There's also the culture of using Spec and Schema in Clojure, so you often have assertions at the interface level. For example, there's ring-spec providing the specification for Ring.

17

u/yawaramin Oct 27 '17

Why is the burden of proof on static typing, and not on dynamic typing?

14

u/yogthos Oct 27 '17

My position has always been that both are effective, and it's a personal preference. Since you think static typing is more effective, it's on you to provide the evidence to support that idea.

10

u/yawaramin Oct 27 '17

I don't think I implied that any more than you implied that dynamic typing is more effective in your original comment.

7

u/yogthos Oct 27 '17

Then it sounds like we agree that both approaches work fine in practice, and there's nothing to provide a replacement for. It's just a different set of trade-offs.

4

u/quicknir Oct 27 '17

I could say pretty well the same thing about functional programming/mutability/whatever. Is that your stance about imperative programming, or OO, or immutable by default vs purity vs const aliasing (a la Rust, C++) vs nothing (python, java)?

5

u/yogthos Oct 27 '17

My stance is that in my anecdotal experience Clojure works better than imperative/OO languages I've used. Since we don't have clear empirical data available on what works best, you basically have to try things for yourself and see what you like best.

0

u/[deleted] Oct 27 '17

[deleted]

7

u/armornick Oct 27 '17 edited Oct 28 '17

whatever works for you, but I don't see any evidence that it is

I don't agree with your observation. I see plenty of dynamic typing enthusiasts who say dynamic typing is superior. See the OP, for example.

2

u/yogthos Oct 27 '17

OP is not saying that dynamic typing is superior. OP is giving examples of real world scenarios where dynamic typing is a better fit. He also notes situations where static typing is a better fit.

1

u/CurtainDog Oct 27 '17

Er, that's the way proof works. You can consider static typing to do something over and about dynamic typing, that is performing a type check at compile time. The question is what value that additional step provides.

3

u/yawaramin Oct 27 '17

Depends on how you look at it. You can also consider dynamic typing to be doing something over and above static typing, i.e. performing runtime type checks. What value does that provide relative to compile-time type checks?

3

u/yogthos Oct 27 '17

That provides a lot of value. First, you're able to write code in a way that's most natural, as opposed to a way that can be checked statically. Second, it makes the system more flexible at runtime. Most applications have to deal with the outside world, and it's not static. Your application needs to be able to adapt to the changes at runtime, and static systems make that difficult to do.

Here's a real world example for you from my work. My application was talking to a remote service, and the API of the service changed. I was able to connect to the REPL and update the logic to match the new API with zero downtime. This is not something that would be possible with a static language.

2

u/valenterry Oct 27 '17

Most applications have to deal with the outside world, and it's not static

It can be modeled with types ahead of runtime, so in the context of static typing it is static. That does not mean that the data is static too...

Your application needs to be able to adapt to the changes at runtime, and static systems make that difficult to do.

Well, they force you to be explicit about error handling in certain situations. Not sure if I would call that "making it difficult".

1

u/yogthos Oct 27 '17

The point is that the types of data change as well. I might get one type of JSON message today, and a wildly different type tomorrow. I have no control over that, and I can't model for that change ahead of time.

The type I'm redefining to might be completely different from the original. With a dynamic language I can rewrite any part of the system at runtime. Perhaps this is possible in principle with static typing, however I haven't seen this done practically in ML, OCaml, Haskell, Scala, Java, C#, and so on.

Furthermore, this extends beyond data. With a dynamic language I can do something like the following trivially at runtime:

(eval '(defn add-one [x] (inc x)))

(add-one 10) => 11

What's the answer to that in a static language?

3

u/valenterry Oct 27 '17

With a dynamic language I can rewrite any part of the system at runtime

What? How can you "rewrite the system at runtime" with e.g. python or javascript?

You can interpret data dynamically, sure. But you can also do this in any statically typed language.

About your last example: well what would you do without an predefined eval function? And while you would/should neither do that in a statically typed language nor in a dynamically typed language, we can emulate eval. It means however building a runtime within a runtime. No one does that for very good reasons. Except in very controlled environments, see e.g. twitters util-eval library for doing that in Scala.

2

u/yogthos Oct 27 '17

What? How can you "rewrite the system at runtime" with e.g. python or javascript?

Can trivially do it in any Lisp, and I've used this functionality to fix production problems with zero downtime.

About your last example: well what would you do without an predefined eval function? And while you would/should neither do that in a statically typed language nor in a dynamically typed language, we can emulate eval.

You'd do plenty of things. For example, an application I work on loads business rules for forms from a database. These get reloaded at runtime by the server and you need to use eval for that.

It means however building a runtime within a runtime. No one does that for very good reasons. Except in very controlled environments, see e.g. twitters util-eval library for doing that in Scala.

I don't care what you can emulate in principle, at that point you'll be writing a dynamic language within your language. Show me a static language where that's possible today that I can use.

I love how these conversation always end up following the same pattern:

show me something I can't easily do with static typing

here you go

oh nobody could possibly ever need that

¯_(ツ)_/¯

→ More replies (0)

1

u/baerion Oct 28 '17

This has very little to do with static typing, and more with the language having an interpreter. With Haskell I can run my server in a GHCi session within tmux, connect to it and switch out an event handler while the server is running. There are downsides to this approach, but they are really just limitations of Haskells ecosystem (e.g. no JIT compiler, hot-swapping being experimental, etc.). This has nothing to do with static typing per se.

But even if you were right, emulating dynamic typing within a statically typed language isn't as bad as you make it sound. At least you can move gradually between the strength of your types, with casting or conversion to more pronounced types, rather than being stuck with just a single type.

2

u/yogthos Oct 28 '17

As I said, I haven't seen a practical static language that I would consider doing this in production with. Perhaps it's possible in principle, although I definitely think there are limitations. You can't just run any top form in Haskell without going through main for example.

If majority of your business logic is going to be in this hand rolled dynamic language it would be absolutely pointless to hand roll one inside a static language.

→ More replies (0)

32

u/yawaramin Oct 27 '17

Btw, Haskell's motto is not 'avoid success at all costs', it's 'avoid "success at all costs" '.

19

u/devraj7 Oct 27 '17

It's both and it's intentionally ambiguous.

51

u/ExPixel Oct 27 '17

How does Haskell manage to over complicate even its own motto?

35

u/yawaramin Oct 27 '17

That's kind of the joke.

12

u/CKoenig Oct 27 '17

yeah I always felt that was a mistake - it should be

avoid $ success at all cost

8

u/Tysonzero Oct 27 '17

But that ambiguity is like half of the joke...

3

u/Axxhelairon Oct 27 '17

and my motto for Haskell is the condensed version of that, 'avoid'

5

u/armornick Oct 27 '17

Of course, you have curried the avoid function to take "success at all costs" as an automatic parameter, right?

4

u/kcuf Oct 27 '17

Your loss

7

u/Tarmen Oct 26 '17

I actually rather like dynamic languages but not really for the reasons mentioned in this post. For most points I just thought but there is a battle tested solution that solves this perfectly well.

Lenses deal.amazingly well with nested records, for instance. Refactoring a positional adt to a struct is backwards compatible and use sites can be fixed incrementally. Having a functor like Maybe on every part of a struct and switching it out for Identity later in the data flow is a semi common pattern both in haskell and other languages like typescript with mapped types. Speaking off typescript, you can insert/delete/merge ts objects without effort. You get a ton of static guarantees out of it and it can be incrementally added so it doesn't have to slow down during exploratory phases.

Anyway, I didn't quite get the point about adt's being bad for fast changing domains. They are probably slower when writing the initial version but they make updating code for changed requirements mich faster in my experience. It usually is enough to change the Types.hs file and let the compiler lead you. In a dynamic style (whether in a dynamic language or not) this can be emulated with unit tests but that requires more basic/overlapping tests that have to be kept up to date and possibly more bugs if that doesn't happen. Could someone give an example of what the post meant?

5

u/vivainio Oct 27 '17

Posit 1: if your language is competing mainly with Haskell, it's not going places

Posit 2: dynamic languages are way easier to create and maintain than static ones. Static languages of any quality will require much larger teams than dynamic ones. That's why small 'Rockstar' teams like Rich Hickey will always need to stick to dynlangs

3

u/mixedCase_ Oct 27 '17 edited Oct 28 '17

I would disagree with your second assumption because knowledge is usually preserved through generations in the static typing world. "Standing on the shoulders of giants" and all that.

I would submit Idris as an example of that. Mostly Edwin Brady's child with a few other collaborators and hobbyists, none of which work on it full-time. It's heavily inspired by Haskell, but making use of what Haskellers have learnt about using the language on different settings; what works great, what trade-offs didn't work out as planned, and where it just missed the boat completely.

On the other hand, the dynamic world and the weakly typed (as in, not powerful rather than its usual meaning; think Java or Go) world are constantly reinventing the wheel: forgetting about our past mistakes as well as our successes.

1

u/yogthos Oct 28 '17

Lisp invented the wheel thank you very much. :)

4

u/mixedCase_ Oct 28 '17

Too bad Clojure isn't a real Lisp since it has square brackets :^)

EDIT: The nose in the smiley face wasn't escaped, resulting in a superscripted closing parens, so I had to edit the comment. A statically typed smiley would've prevented that.

1

u/yogthos Oct 28 '17

You missed the opportunity to check the results in the preview REPL. :P

2

u/destinoverde Oct 27 '17

Except, over time, you add a fourth and a fifth. Pretty soon, you've got seven or eight of them.

That's only seen in bad design, optimization techniques base on specialization, or generated code.

A few interesting points but the title is misleading since is the static type system part is only about Haskell and Java.

2

u/pellets Oct 27 '17

What we wound up doing was nesting pattern matching to get at the value we wanted. The deeper the JSON nesting, the deeper our pattern matching.

This part had me doubting that they were very good with Haskell. You can get deeply nested values out of JSON and XML with things like

json \ "ojb0" \ "obj1"

provided by useful libraries.

6

u/devraj7 Oct 26 '17 edited Oct 27 '17

A type system gives you a new design space. It lets you express things, like type constraints, that you simply don't have to in untyped languages. That gives you a lot more choices to make

Actually, no. Type systems don't give you more or fewer choices than a single type.

Types give you additional guarantees about the correctness of your code, that's pretty much the essence of it.

As a side note, it's interesting that Haskell programmers, while they leverage an incredibly powerful and flexible type system, are also missing out on one of the best advantages of working with a statically type system: automatic refactoring. The author of this article didn't even touch on the subject probably because he never experienced the power of automatic refactoring neither in Clojure nor in Haskell, but anyone who's programing in Java/C#/Kotlin can attest how important this functionality is to producing clear and maintainable code.

1

u/imposs1buru Oct 27 '17

Yeah that's because Java/C#/Kotlin have tons more boilerplate than Clojure or Haskell. You need all that tooling to work around deficiencies in your shitty language.

1

u/max630 Oct 27 '17

It's easy. Just implement it.

1

u/aliem Oct 27 '17 edited Jan 23 '18

deleted 0.6494 What is ^^^this?

4

u/Tarmen Oct 27 '17 edited Oct 27 '17

Dependent types bridge that wall and let you mingle values and types. This is valid Idris for instance:

item : (b:Bool) -> if b then Int else List Int
item True = 42
item False = [1, 2, 3]

For basic cases the ergonomics are ok because idris can autocomplete and infer a lot of code based on the types you give. For complex stuff you still might have to proof things by hand because undecidability and all that.

Refinement types might be a viable more lightweight alternative. They are more about validation like Int -> { v: Int | v > 5 }. The compiler can check these from the code you write anyway so it's closer to NotNull annotations in java or documentation/unit test hybrids. I think typescript does something similar to restrain types to certain values like "foo" | "bar" | "baz" which are further refined as values pass through control flow.

4

u/pipocaQuemada Oct 27 '17

The thing, though, is that there are types and then there are types.

Yeah, saying "this is an int and this is a string" isn't terribly interesting.

Types, however, can track much more interesting properties. Like "concatenating a list of length n with a list of length m gives you a list of length m + n", if you want to go off into dependently typed languages. Or they can assert that you can't have double freed memory, if you like Rust. Or just that this Int isn't just an Int but actually represents an username or acceleration.

There's a reason that languages with the most interesting type systems double as proof assistants.

2

u/aliem Oct 27 '17 edited Jan 23 '18

deleted 0.1779 What is ^^^this?

0

u/[deleted] Oct 27 '17

[deleted]

9

u/agcwall Oct 27 '17

I don't see how you can get away from refactoring in any language. When your requirements change, or you find a better way to do something, you need to refactor. Static type systems make this process less error-prone.

Edit: I would also argue that this is one big thing the Haskell community is currently missing: A professional IDE with refactoring support. It would go a long way. (Yes, I'm aware of Leksah and Haskelly, they don't come close to the convenience of Visual Studio or Eclipse).

9

u/devraj7 Oct 27 '17

Right, because once you write a Haskell function, you never ever need to rename it. Ever. Refactorings are for loser languages, right?

Refactoring is useful in all languages, period.

4

u/pron98 Oct 27 '17 edited Oct 27 '17

It's really charming that some Haskell fans think that if somebody doesn't adopt Haskell or its approach, it must mean they don't understand it. The reality is that language choice/design is much about personal aesthetic preference. It's really more art than science, especially as no specific design (among all reasonable ones) is shown to be significantly better than others, let alone better in all situations.

Not everybody likes your favorite TV show, and if they don't, it doesn't mean they don't get it. That doesn't mean you can't still talk all you want about how great it is, only that you shouldn't spend so much time trying to explain why others don't like it.

It's perfectly possible to have good arguments against types and at the same time have good arguments for them. It is also possible and reasonable to believe that types are good for some things, and less so for others. One must not even believe that types are the answer to everything (or the best answer so far) and still be very interested in type systems and their potential uses.

BTW,

A type system gives you a new design space. It lets you express things, like type constraints, that you simply don't have to in untyped languages.

This is not true, especially in Clojure, which has contracts.

2

u/destinoverde Oct 27 '17 edited Oct 27 '17

This is not true, especially in Clojure, which has contracts

They are not verified globally, lack of information to an IDE, no inference, and have to be checked manually at runtime. I think is cooler if you have the best of both worlds, but the kind of checks you do with contracts are not the same as with a static type system.

1

u/pron98 Oct 27 '17 edited Oct 27 '17

They are not verified globally, lack of information to an IDE, no inference, and have to be checked manually at runtime.

The idea of contracts is precisely to separate specification from verification; the contracts specify, and some tools verify. That's a very powerful thing, just as the idea of types which ties the two together is powerful for other reasons. Currently, the verification tools include automatic test generation and runtime assertion generation. There's work underway (1, 2) to infer specs. Tools for automatic "static" verification of specs can also be built, as well as IDE support.

the kind of checks you do with contracts are not the same as with a static type system.

I agree with that, but Clojure specs also specify "types". You're right that they'll never be as good as types for that purpose, but that's the specific (and reasonable) tradeoff that Clojure's designers have chosen for its intended use cases. The main thing that types do and contracts can't (and aren't supposed to), is to play a role in the semantics of the program, such as name resolution (overloading).

1

u/destinoverde Oct 27 '17

There's work underway (1, 2) to infer specs. Tools for automatic "static" verification of specs can also be built, as well as IDE support.

Sure. Will be interesting to see how that will turn out.

4

u/SlidingObscure Oct 27 '17

I used to be gung ho about type systems. Now I believe that if you are adequately testing your code, type systems provide no real safety benefit.

Now I am gung ho about testing.

6

u/valenterry Oct 27 '17

Now I believe that if you are adequately testing your code, type systems provide no real safety benefit.

Yeah but if you do that, you spent more time on writing, understanding and maintaining tests than writing, understanding and maintaining types (and the tiny amount of tests for what your types don't cover).

And you lose lose the guidance of types, the compilers help in syntax highlighting, refactoring and so on.

Not really worth it, in my eyes, for anything more than a couple of script..

0

u/yogthos Oct 28 '17

Static typing does not obviate the need for tests. So far, nobody has been able to show that static typing catches a significant percentage of errors not caught by tests.

3

u/valenterry Oct 28 '17

I never said this. But they make a huge amount of tests unnecessary. I'm talking from experience as it's hard to show any "hard evidence" - but you would agree with me that Clojure is more productive than writing plain ASM even though there does not exist hard evidence for this right?

1

u/yogthos Oct 28 '17

I don't have a huge number of tests in my Clojure code bases either though. Most of the tests I have are specification tests around the API. Exactly same tests I would write in a static language.

You have to consider that you have a superior workflow in a language like Clojure. I have tight integration between the runtime and the editor. Any code I write, I can run instantly and see exactly what it's doing. This is vastly superior to the TDD workflow.

Meanwhile, the code is also largely stateless, so I don't need to test it in a context of a particular application state as I would in an imperative language.

So, I write API level tests, and if those pass that means the code that's not being tested directly is doing what it's supposed to. The specification is the contract for what the code is supposed to be doing overall, and that's the kind of correctness I actually care about.

I think Clojure is more productive than writing Haskell as well even though hard evidence doesn't exist for that. Meanwhile, you probably think Haskell is more productive. Our subjective experiences are divergent here, and we're obviously going to rely on our own experience as opposed to the others. :)

3

u/valenterry Oct 28 '17

I don't have a huge number of tests in my Clojure code bases either though. Most of the tests I have are specification tests around the API. Exactly same tests I would write in a static language.

I don't think so. Even if you have not so many tests, with a static typesystem you would - in most situations - have even less tests.

More, if you think your Clojure workflow is vastly superior to type-driven workflows then please give proof or emphasize that it is superior to you.

1

u/yogthos Oct 28 '17

I don't think so. Even if you have not so many tests, with a static typesystem you would - in most situations - have even less tests.

[citation needed]

More, if you think your Clojure workflow is vastly superior to type-driven workflows then please give proof or emphasize that it is superior to you.

Obviously this is subjective and I'm talking from my own perspective. I'm telling you that I find the dynamic workflow more effective, and that I don't write more tests than I did when I used static languages. If your experience is different keep using static languages, nobody is taking them away from you.

Only thing I'm trying to get through to you here is that plenty of people who have worked with both static and dynamic languages prefer the latter. The claims you're making simply don't match my exprience.

2

u/valenterry Oct 29 '17

Only thing I'm trying to get through to you here is that plenty of people who have worked with both static and dynamic languages prefer the latter. The claims you're making simply don't match my exprience.

I don't deny that! The only thing that I am trying to get through is, that types can replace tests and are a better option in most cases.

Btw, I feel that types are winning the fight. ;) More and more languages get a static typesystem (PHP, most JS transpilers, ...) even though it is much harder to design languages like that. On the other hand, things like REPL and type inference try to make those languages feel more dynamic.

1

u/yogthos Oct 29 '17

I don't deny that! The only thing that I am trying to get through is, that types can replace tests and are a better option in most cases.

I've seen no evidence of that, if you mean that you prefer that workflow personally, that's a different question.

Btw, I feel that types are winning the fight. ;) More and more languages get a static typesystem (PHP, most JS transpilers, ...) even though it is much harder to design languages like that.

This just reminds me of the OO hype we lived through already. It pretty much followed the same pattern, people made a whole bunch of assertions about it that sounded good on paper, and all of a sudden OO was just how you did things. Now we know that the claims regarding maintainability, code reuse, and so on didn't really pan out in practice.

What fascinates me the most is that it's always static people who just can't accept that people prefer dynamic typing. Pretty much anybody on the dynamic side says use what works for you, both seem fine. For static aficionados it's a war.

2

u/valenterry Oct 29 '17

I've seen no evidence of that

As I said already: there is no hard evidence. I find it quite intuitive though. For example: Some user enters information which must be validated. It either succeeds or it fails. Now, with a good typesystem I can let the compiler check that there is at least one error if the validation fails, so that it never can happen that the validation fails but the result is an empty list without any errormessages in it. In a dynamically typed language you need to cover this with a test.

What fascinates me the most is that it's always static people who just can't accept that people prefer dynamic typing.

You are not talking about me are you?

→ More replies (0)

4

u/ferociousturtle Oct 27 '17

I'm the same. I've used Haskell, F#, C#, Scala, C++, OCaml, VB6, VB.NET, and who knows what else. A handful of those professionally, the rest just for dummy little projects.

JavaScript and Rails had me hating life, and I blamed dynamic typing.

But Clojure has me second-guessing this. It's a really nice language, and dynamism is a big part of what makes it nice.

3

u/devraj7 Oct 27 '17

Now I am gung ho about testing.

You should be gung ho about both testing and static type systems because they both bring different benefits.

1

u/SlidingObscure Oct 27 '17

Static typing definitely brings benefits but they are not free.

1

u/yogthos Oct 28 '17

At the end of the day you care about semantic constraints. Types are not a good tool for expressing that. All they tell you that your program is internally self-consistent. What you want to know is that it does what was intended. The only way to tell that is by making a specification and testing against it.

1

u/max630 Oct 27 '17

to change from positional to named, and then to rewrite pattern match expressions in almost every file

As far as I understand, PatternSynonyms should finally help with it.