Fork me on GitHub

If we want to discuss the pros and cons of static typing vs dynamic typing 🙂

Jakob Riishede Møller19:01:19

I wrote the question in the Clojure channel because the documentation suggest that you should avoid type hints without any reason given


Right, and you got an answer from one of the core Clojure team on that.


In Clojure, type hints serve to avoid reflection (and improve performance) in some situations. But they are not like type declarations in other languages. They are just hints for the compiler.


In general I do think it's nice to avoid reflection. Sooner or later you want that anyway is my experience. It also works better if you're going to run the code through GraalVM


There is a flag *warn-on-reflection* which you can set. Then the compiler will warn you if it cannot infer the types it needs to avoid reflection.


In general, discussions about static vs dynamic typing are a bit pointless because most of the discussion is subjective: some developers prefer static typing because they believe the restrictions it places on your code are worth the avoidance of certain errors; other developers prefer to avoid those restrictions in exchange for losing the ability of the compiler to detect certain possible errors.

👍 1

It's worth noting that static typing tends to prevent you from writing a certain class of programs that are correct at runtime but fail at compile time due to type checking.

💯 2

Can you give one/two concrete examples? Where can I read more on this? I have a feeling this is true, but cannot think of good examples.


@UJRDALZA5 -- that course ran on Coursera for several years as "Programming Languages" (I took it back in 2012 out of curiosity and then I was a Community Teaching Assistant for it for several more runs).


That is an excellent read!

Jakob Riishede Møller19:01:44

Well I like to have a high level of IDE support, and I am rather disappointed with the tools I have tried to set up for that (in VSCode)


Clojure has core.typed (aka Typed Clojure) that provides an optional static type checker based on annotations being added to the code. It's kind of painful to use tho' and there are certainly Clojure idioms that core.typed won't accept: you have to refactor to code that can be annotated to satisfy the type checker.

Jakob Riishede Møller19:01:46

I use calva - I find it a little buggy


You can also try Cursive / IntelliJ, it's been around for a while and is the most IDE-like. Disclaimer: I don't personally use it.


Most editor integrations rely on runtime inspection -- code completion, docstrings, etc. But most editor integrations can also run static code checkers (linters) like Joker and clj-kondo.

Jakob Riishede Møller20:01:14

Oh - nice to know 👍


Yeah, Cursive is the most IDE-like in terms of the features it provides -- but most Clojure developers prefer lighterweight editors (Emacs, vim, Atom, VS Code)


@jakob.riishede.moller An interesting podcast to listen to: S2 E2 - REPL with Stuart Halloway There one of the Clojure core team members explain sophisticated IDE tooling vs spartan tooling and why you need very little with Clojure oftentimes

seancorfield20:01:14 covers the State of Clojure results for 2019 -- Q12 shows the breakdown by editor choice


It's probably a different philosophy: Clojure is a pretty minimal language with a small set of features that compose nicely. Compare that to e.g. Scala or C++ which is quite impossible to use without an IDE


Java is also virtually impossible to write without IDE support (totally agree on Scala and C++ too).


The difference between these languages is also: Clojure is interactive, the REPL is your main tool, whereas with the other languages you have a write / compile / run cycle which gets tedious and you depend on external tooling to get things right before you can even run something


30% of clojure users still write their clojure in the biggest heaviest IDE going 🙂


@U050MP39D I wonder how much that 30% overlaps with the 30% that came to Clojure from Java?


good question. this data point at least came from ruby+vim and uses cursive


well. with an intermediate stop at lighttable and getting burned developing a bunch of plugins etc for a small editor that got abandoned 🙂


My arc was pretty much Java -> Groovy -> Scala -> Clojure with Eclipse as my primary IDE until I got to Clojure.


@jakob.riishede.moller If you want to get the most leverage out of Clojure without depending on other tools, learn to use the REPL well:

Jakob Riishede Møller20:01:45

I will try to - I'm not used to that though (programming PHP at work 😫)


(and Clojure's REPL is fundamentally different to other languages' REPLs by the way -- in Clojure, the semantics of compilation match the semantics of the REPL: you could feed your entire program to the REPL in the appropriate order and it would be identical to how Clojure compiles the code from disk).


I think Stu talks about the semantics compared to other languages in his REPL-Driven Development talk (given to the Chicago Clojure meetup a few years ago)...


He specifically compares Clojure's REPL to Java "new" shell on one slide.

Jakob Riishede Møller20:01:42

I have bookmarked it 🙂


Even in languages that have some sort of add-on REPL (which is usually an interpreter, rather than compiled like regular code), the typical workflow is still edit-compile-test. In Clojure, the REPL makes it possible to edit & test your code in an expression-by-expression workflow: the tightest feedback loop possible.


@jakob.riishede.moller Other than PHP in your day job, what other languages have you worked in fairly extensively? Curious to draw comparisons with Clojure.

Jakob Riishede Møller20:01:48

Well - it may look curious, but in later PHP versions some level of type hinting is supported and can be utilized for dependency injection and good IDE support

Jakob Riishede Møller20:01:25

And I dont do the usual Laravel


Yeah, I remember PHP starting to develop a type system (I did a fair bit of PHP in the 3.x and 4.x days and stopped just into the 5.x days, if I remember correctly).


A friend of mine became a PHP developer just as 7.x was coming along and his code looks a lot more Java-y than any PHP I ever wrote.


Well, Java that has been completely peppered with additional punctuation "noise" 🙂

Jakob Riishede Møller20:01:08

I think, it requires a lot of discipline to use PHP in a sound way


Clojure requires discipline too -- but it also makes it hard to write imperative, mutable code so that's definitely a win. Some people run into NPEs (null pointer exceptions) a lot in Clojure but I think that depends on coding style -- I run into that sometimes but nowhere near as often as I did when I first learned Clojure back in 2010.

Jakob Riishede Møller20:01:04

I heard a rumour that Robert C. Martin spend 5 years getting happy with Clojure?


Uncle Bob loves Clojure 🙂

Jakob Riishede Møller20:01:24

Oh I meant spent - not spend


It's definitely got a learning curve -- and a lot of people never get comfortable with it. I've used dozens of languages over my 35 year professional career and I enjoy Clojure more than any other language.


And, in addition to the dozen or so languages I've used in production, I try to learn a new language for fun every year or two.

Jakob Riishede Møller20:01:54

I'm a little familiar with TypeScript too

Jakob Riishede Møller20:01:53

(I am a web-developer, but have spent most of the time doing backend stuff)


Elm is a great frontend alternative to JS. It achieves its guarantees by being very opinionated about architecture and generally very restrictive overall via types and the deliberate design constraints in the language.

Jakob Riishede Møller20:01:46

Yes - I am impressed by the little I know about Elm


If I had to do frontend work, I'd probably go with ClojureScript so I could share code between the front and back end (and share data easily too as EDN). But if I wasn't doing Clojure on the backend and needed to do frontend stuff, I might consider Elm (although when I built a little web app to monitor my solar panel system, I did get pretty frustrated with how restrictive Elm feels to me).


If I couldn't do Clojure on the backend and still wanted to be on the JVM, I'd probably go to Kotlin. I've done Scala and wouldn't really want to go back to that.


Because TS is JS + types and I absolutely detest JS as a language.


(my background is in language design and compiler/interpreter systems so I tend to have very strong feelings about languages 🙂 )

Jakob Riishede Møller20:01:43

I think TypeScript is an improvement though

Jakob Riishede Møller20:01:10

But the webpack circus...


Oh sure... almost anything is an improvement on JS 🙂 I mean, CoffeeScript is an improvement too but I still find CS horrible to write programs in!


In some ways, I'd have liked Haskell to take over the world as the #1 mainstream language -- because my PhD work was on ML-family syntax languages and type inference -- and then we probably wouldn't be having any of these discussions :rolling_on_the_floor_laughing:

Jakob Riishede Møller20:01:42

Can you imagine a compiler from Clojure to webassembly?


But I also grew to love Lisp back at university so I would always have had a soft spot for something like Clojure too...

Jakob Riishede Møller20:01:00

I am a Ph.D. in applied probability - so - I like the functional approach

✔️ 1

Does WebAssembly have managed GC yet? That seemed to be the stumbling block when Clojure to wasm has been discussed in the past...

Jakob Riishede Møller20:01:09

I don't know - I just find the idea to replace JS promising 😎


@jakob.riishede.moller Considering your background, maybe is interesting to play with

seancorfield21:01:30 -- fascinating read, and includes feedback from the Scala.js and Elm maintainers.

Jakob Riishede Møller21:01:51

It was great chatting - but I have some housekeeping to do (I am single 😄) and it is 10pm in Denmark


@jakob.riishede.moller Greetings from The Netherlands (same timezone)!

Jakob Riishede Møller21:01:51

@borkdude Greetings - over and out 🙂


Greetings from Copenhagen! Consider joining #copenhagen-clojurians , it’s fairly quiet but it doesn’t have to be :)


Jusr reading the last things. I guess it would be possible to use rust to compile Clojure to wasm.