Hacker News new | ask | show | jobs
by grouchoboy 3236 days ago
The perfect language to expand your brain. In a world dominated by java, php, c++,... In my opinion yes, Clojure could the perfect language to continue learning concepts, at same level would be Haskell.
3 comments

The perfect language to expand your brain is mathematics.

I agree with Wadler that the best programming languages are discovered. First, the principles are revealed in a proof by a logician. Then about two or three decades later computer scientists "discover" the same principles. And another two or three decades after that mainstream programming languages reluctantly integrate the ideas.

This is all to say that computer languages are behind the curve. If your goal is to expand your brain you're better off digging into the fundamentals behind computer languages. Then you can see the flaws and trade-offs in all languages including Clojure, Haskell, C, Agda, Idris, Javascript, etc, etc, etc.

I've said the Clojure is a decent language. I don't think there is a perfect one. Not yet.

> The perfect language to expand your brain.

Clojure is still restricted/limited compared to Common Lisp.

In what ways, specifically? Building binaries?
To fully explain, it would require a blog post, and it has been covered before, but i'll make a try:

- Proper stack traces. Debugging Common Lisp code is not only easy, it is far easier than in 90% of programming platforms out there. Clojure is severly lacking here; it has been promised that there will be an improvement; i will be watching since this will greatly improve Clojure

- "Lisp-2 versus Lisp-1": On Common Lisp, functions and variables have separate namespaces so they don't conflict. This makes writing code, especially macros much easier. Macros are one of the biggest reasons to use a Lisp dialect in the first place, so this is a rather strong point.

- Object orientation facilities: CLOS, CL Object System, is arguably the most powerful OOP system on a mainstream language. You should really take a look at it, it can just blow your mind. Clojure has no comparable OOP implementation. I recommend CLOS to anyone that feels disillusioned with OOP.

I could stop here, because the three points above are very strong differences, but there are some other points to consider:

- Standarization and portability (1/2): CL is an ANSI standard, and there are many ANSI-compliant, mature, compilers: LispWorks, SBCL, Allegro CL, ABCL, Clozure CL, ECL, CLISP, and others. There are features that the ANSI standard does not cover, like interacing with C libraries, but there are already portable libraries that allow you to also do this on a portable way. So, in this way, your code can be compiled by those implementations, often without any change needed at all.

- Standarization and portability (2/2): The ABCL compiler allows you to target the JVM and call Java code from Lisp or call Lisp code from Java. The Clozure compiler lets you target the LLVM. Practically most modern platforms can be compiled from CL to native code by using the suitable compiler.

- Interfacing: As mentioned above, you can interface with Java, and with C, as needed. C interfacing is very easy, btw.

- Speed: CL can be very fast. For example SBCL is really fast, particularly with numbers where it can be as fast as C. In general it is in the same speed of Java code running under the Oracle's latest JVM. I think that CL code under SBCL probably should be much faster than Clojure running under JVM.

- Number data types: CL supports, with high perfomance and natively: Complex numbers, Rational (fractional) numbers, floating numbers (with the IEEE standard), integers, binary numbers, and arbitrary-length numbers. Bonus: The same typical operators (+,-,*,/) work perfectly with them, so using them is simple. In this feature, CL fares even better than Fortran (seriously.)

- Static typing? CL is not statically typed, but the standard allows you to declare the type of your variables. A compiler like SBCL will catch many type errors during compilation (and of course they will also be catched at runtime). Doing this has also the big bonus of increasing performance dramatically.

- Mainstream: While not popular, Common Lisp is a mainstream language, so there are tons of books and resources out there, as well as having been used successfully complex production systems, like for example auto-piloting the Deep Space 1 spaceship (NASA) for days.

It's also very pragmatic, and probably most used functional languages in the industry at this point.
> probably most used functional languages in the industry at this point

Perhaps, though unlikely[1] (Haskell seems to have been picking of steam of late).

[1] https://trends.google.com/trends/explore?date=today%205-y&q=...

wish that were true, but i doubt it. scala, prolog and erlang are all higher on tiobe index.
I personally don't view Scala as a FP language, it's a FP/OO hybrid. It's not opinionated in that regard, and a lot of code in it is written in traditional OO style or a mix of the two.

Erlang is another widely used functional language, but it's not very widely used outside the telecom niche. Clojure has the advantage of running on the JVM, and makes it easy to target a much wider range of domains.

Clojure is also a hybrid. The other part is called Java or Javascript. This is claimed as an advantage, since there is already a lot of functionality in another language to be reused by a direct interface. Some stuff is simply deferred to the host language and since the other part is based on OOP, applications will then be a mix of more FP-oriented code calling OOP-oriented code.
This is an implementation detail, and doesn't affect the API presented to the user. For example, consider the clj-http library that's backed by the Apache http Java library internally https://github.com/dakrone/clj-http . As a user of clj-http, I don't know or care about the fact that it's a wrapper around OOP code.

Furthermore, if you wanted to, you could reimplement the internals in Clojure and the users of the library wouldn't be affected.

Being able to leverage existing mature libraries is a huge advantage, and the fact that they can be used via idiomatic functional APIs provides the best of both worlds experience.

The author of such a wrapper library writes this hybrid code.

Wrapper libraries are one way to deal with hybrid code.

right, but technically so is Clojure - you can get your hands dirty and mutable with relative ease.

Scala's problem is that they marketed it as "we're almost java - you can just sprinkle some functionalness on your code as you go and you'll be fine".

Clojure is a lot more focused and opinionated. It's unarguably a functional language first and foremost. Note that you can write any style of code in any Turing complete language, the key difference is what style of code the language encourages.