r/Clojure • • Jan 19 '14

Clojure, the bad first impressions

http://kodare.net/blog/clojure-bad-first-impressions/
70 Upvotes

81 comments sorted by

6

u/ickysticky Jan 19 '14

I am also new to clojure. Here is how my experience has been similar and different.

  • I actually found leiningen first, before even reading a tutorial, not sure how, but I did. So I don't have that complaint.

  • Yes(indeed fuck yes) to the point about error messages. My biggest gripe with clojure is the error reporting. It is less than good IMO.

  • Not sure about the issue with the REPL. What is the problem? Unnecessary error messages?

  • Have had no reason to read the source so far. But those issues sound odd, and out of place in a mature project.

3

u/kankyo Jan 19 '14

The REPL issue is something that just makes me uncomfortable... a good system is many instances of caring about the details. If people don't care about details that makes me think "what other details have they also neglected that are harder to see?".

3

u/[deleted] Jan 19 '14

It's the limited amount of manpower -- the devs don't seem to focus on "cosmetic" issues, but those can also be important.

10

u/kankyo Jan 19 '14

Author here.

I initially had the broken links on clojure.org to the documentation listed, but I bugged some people and now it's fixed!

There are clearly a lot of things that are awesome with Clojure, but details like the ones I've listed here can damage the community disproportionately compared the very minor changes needed to fix them. Or in other words: most of the things on this list are probably fairly easy to fix, and will make the experience for newbies a lot better.

4

u/yogthos Jan 19 '14

I definitely agree with some of the issues listed, such as poor error reporting and the fact that the official documentation is less than adequate.

However, I'm not sure I agree with some of the other complaints. For example, I like the way the built in test works. I see what function I ran, what was the expected result and what the produced result was. I'm not sure how much clearer it can be frankly.

The REPL output is often useful as it gives you more information about the cause of the error. In most cases the line number is sufficient, however sometimes you might want to see the complete stack trace.

Also, this is not an issue when you use a decent editor. For example, Cursive will catch the error and simply print the error message for you.

The editor is the proper place to address this kind of thing, I would want the language to give me as much information as possible and have the editor worry about displaying it in a nice way.

Clojure source code has a lot of commented out code with no explanation. This is unprofessional and makes me suspicious about the entire thing.

The commented code is definitely not a pretty sight, but I certainly can't agree that this alone should make you suspicious of anything. The fact that Clojure is used by lots of companies in production and many successful products have been built with it clearly demonstrates that there's nothing suspect about it.

Also, as a Java developer I don't really see anything obscure about the formatting of the source.

6

u/kankyo Jan 20 '14

However, I'm not sure I agree with some of the other complaints. For example, I like the way the built in test works. I see what function I ran, what was the expected result and what the produced result was. I'm not sure how much clearer it can be frankly.

Except that's actually not what you get. Take this test as an example: (is (= 4 (+ 2 3)))

What is the "expected value"? It's 4. What did we really get? 5. What is the actual output of this test?

expected: (= 4 (+ 2 3))
   actual: (not (= 4 5))

Wtf is that? Super unhelpful. A big problem is that the clojure default test framework doesn't actually separate between expected and the thing that is being tested, so it can't actually print that in a way that is helpful.

Let's take a more complex example:

(is (= {:a 1 :b 2 :c {:d 3 :e 4}} {:a 1 :b 2 :c {:d 4 :e 4}}))

This gives the output:

expected: (= {:a 1, :b 2, :c {:d 3, :e 4}} {:a 1, :b 2, :c {:d 4, :e 4}})
actual: (not (= {:a 1, :c {:d 3, :e 4}, :b 2} {:a 1, :c {:d 4, :e 4}, :b 2}))

That's just pathetic. It seems to just print the original expression with "not" in front of it! Compare to midje:

Expected: {:a 1, :b 2, :c {:d 4, :e 4}}
  Actual: {:a 1, :b 2, :c {:d 3, :e 4}}

Still not great but a lot better. Still not as good as py.test:

E         Hiding 2 identical items, use -v to show
E         Differing items:
E         {'c': {'d': 3, 'e': 4}} != {'c': {'d': 4, 'e': 4}}

...which skips showing the things that are the same in the first dict, although it unfortunately shows the things in the subdict that are the same...

1

u/yogthos Jan 20 '14

Wtf is that? Super unhelpful.

I certainly agree that it could be prettier, but it's not wtf worthy in my book. The python example is definitely nicer since it focuses on the part that's different. I think that would certainly be an improvement to do that.

3

u/kankyo Jan 20 '14

Maybe I need to point out here that I think Clojure is cool and does some very fundamental things inherently right, where most other languages do them wrong.

I get the feeling you're defending Clojure even when I'm pointing out the weak spots. Everything has a thing that is worst, it's just a matter of accepting that and then fixing it so that your favorite language has a worst case that is better than the other languages....

1

u/yogthos Jan 20 '14 edited Jan 20 '14

But I do agree with you that test results could be displayed nicer. I'm all for improving the beginner experience and I've been advocating that for a while myself. I just think some of your statements are somewhat hyperbolic.

For example, I 100% agree about error messages being useless, but I don't agree that stack traces are an issue because practically all Clojure editors handle them intelligently.

I think tests could be clearer, but I don't agree that showing expected and the result is some kind of a wtf. I certainly don't agree that some commented code in the Clojure implementation makes the entire thing suspicious.

5

u/ds300 Jan 19 '14 edited Jan 19 '14

as a Java developer I don't really see anything obscure about the formatting of the source

It uses 8-space indentation and this crazy-weird brace alignment. e.g.

        public ITransientMap conj(Object o) {
                ensureEditable();
                if(o instanceof Map.Entry)
                        {
                        Map.Entry e = (Map.Entry) o;
                
                        return assoc(e.getKey(), e.getValue());
                        }
                else if(o instanceof IPersistentVector)
                        {
                        IPersistentVector v = (IPersistentVector) o;
                        if(v.count() != 2)
                                throw new IllegalArgumentException("Vector arg to map conj must be a pair");
                        return assoc(v.nth(0), v.nth(1));
                        }
                
                ITransientMap ret = this;
                for(ISeq es = RT.seq(o); es != null; es = es.next())
                        {
                        Map.Entry e = (Map.Entry) es.first();
                        ret = ret.assoc(e.getKey(), e.getValue());
                        }
                return ret;
        }

You can't tell me this is idiomatic Java style.

Having said that, I've read most of Clojure's source now and It's all pretty readable. Except the compiler, which is 8000-odd lines of long complex methods and practically zero comments. I gave up pretty quick with that one.

6

u/burkadurka Jan 20 '14

Also, reading the Clojure source is generally not the first thing one does while learning the language, so I wouldn't call this a bad first impression... maybe a bad third impression.

4

u/kankyo Jan 20 '14

Well... it's probably a WEIRD first impression, I agree :P But that's what my first impression was...

I had an idea of trying to fix some of the points on my list, that's what lead me to the compiler...

5

u/[deleted] Jan 20 '14

I guess as a developer, trying to fix the source was his first point of call rather than moaning in a blog post. Instead of potentially recruiting a new core developer, Clojure put him off by simply having an inaccessible style and discouraging large comment blocks, leaving him to question if it would be worth it trying to change anything.

1

u/Anderkent Jan 20 '14

I started peeking at the sources within a week of learning clojure - it's just the only way to understand things sometimes.

2

u/lechatsportif Jan 20 '14

That's interesting, obviously he was tuning the style for scanability. You almost dont need syntax highlighting when blocks are so visible.

2

u/kankyo Jan 20 '14

Except of course that all C, C++, C#, Javascript, Java, etc etc coders in the world are used to scanning code formatted in one way and NOT that way. So that's a bit of a fail in that case. And of course, just hiding the braces totally would give you the same readability for blocks because it's all about indenting anyway...

1

u/Anderkent Jan 20 '14

It's not consistent about it either (see Numbers.java) which uses K&R. The compiler on the other hand has gems like emit.

2

u/kankyo Jan 20 '14

Actually, Numbers.java mixes K&R with that other weird style. In the same class even! Blech.

2

u/fullouterjoin Jan 20 '14

It would be nice to have http://astyle.sourceforge.net as either part of the build process or a commit hook.

3

u/[deleted] Jan 20 '14

Aw, that looks awkward.. anything decent should just be a Reformat away in Eclipse. Come on, Clojure guys!

-2

u/yogthos Jan 20 '14

Yeah, the curly placement in the ifs is a bit out there. Overall, I've definitely seen worse formatting though. :)

I'd say Python source is definitely harder to follow though. :)

4

u/burkadurka Jan 20 '14

Unfair comparison, that's a generated file.

-2

u/yogthos Jan 20 '14 edited Jan 20 '14

Ah so it is, didn't look at the comments. Here's one that's not generated as far as I can tell, and that doesn't look much more appealing in my opinion.

1

u/zhemao Jan 24 '14

Uhh, I don't really see what's wrong with that one. The formatting is consistent and pretty standard for a C program. There are a lot of if statements for error checks, but that's just what you have to do if you want to write a safe C program.

1

u/yogthos Jan 24 '14

It's not the formatting that I find problematic there, but functions like print_exception that just keep going and going. Not exactly fun reading in my opinion.

1

u/yogsototh Jan 19 '14

From my point of view there should be two levels of error message. Human readable one by default (just give me the line and some short insight) and an editor level one with some option given providing all the crazy details.

2

u/yogthos Jan 20 '14

I think it's fine for the editor to handle this aspect. Otherwise you run into situations where you might not get the relevant information about the problem when running your program.

Light Table, CCW for Eclipse and Cursive for IntelliJ handle this precisely as you describe. Writing Clojure without a proper editor wouldn't be any fun even if you did have one line errors by default.

0

u/yogsototh Jan 20 '14

I use vim and I use a French keyboard. So the vim keybindings bugs in lighttable for example. Furthermore, vim is just awesome and I really don't want to use any other editor. Actually, my vim configuration for clojure is far more enjoyable than using lighttable (even if you forget the keybindings problem).

My only complaint do far is how to handle error lines.

I use a script that watches my source file. Each time I change one, the script launch my tests. And this is great.

But instead of having nice colored output, I only have a bunch of hard to read error when any of my test fail or if I made an error and get a runtime error.

So, actually my problem is that there is no way of having a short error message in the terminal except by creating my own filter. And I would really appreciate to have such option.

And also, vim is more than a decent editor for writing clojure. It is awesome. Excerpt error are out of reach for my current vim configuration. I read them in another terminal. I might fix that in a future thought.

2

u/Gonzih Jan 20 '14

Tried fireplace?

1

u/yogsototh Jan 20 '14

Not yet thanks!

1

u/masklinn Jan 21 '14

An issue with Clojure, though, is that the one with "all the crazy details" gives the details of the Clojure VM blowing up in the underlying technology (JVM or JS). Having plenty of extensive clojure-level error details would be fine, having huge JVM stacktraces is a pain in the ass.

1

u/oskarkv Jan 22 '14 edited Jan 22 '14

I definitely agree with some of the issues listed, such as poor error reporting and the fact that the official documentation is less than adequate.

I actually think the documentation is very good. It was exactly what I wanted.

I am actually curious now about what people are referring to when they say that the documentation is somehow bad.

1

u/yogthos Jan 22 '14

I think the documentation on clojure.org could definitely be better. For example, why not point to Leiningen, since that's what everybody uses. Why not list the editors that are good for working with Clojure. Why can't standard library API provide examples the way ClojureDocs does. These are just the basic things that could make the initial experience much better.

-1

u/bliow Jan 20 '14

Any response to the tons of criticism on Hacker News? In particular the macro + static analysis stuff seems off point.

2

u/kankyo Jan 20 '14

Criticism of what? Do you have a link?

1

u/bliow Jan 20 '14

whoops, mistook this post for another. sorry.

38

u/r00k Jan 19 '14

I wanted to dislike this post, but I think the criticisms are pretty fair.

18

u/[deleted] Jan 19 '14

Agreed. This isn't a post from someone with an axe to grind. It's someone keeping an honest list of their early frustrations. Good feedback for the community.

17

u/yogthos Jan 19 '14

I think the error reporting in Clojure core functions definitely leaves a lot to be desired. For example, let's say we pass a wrong type to +, we'll get the following error:

(+ 1 "foo")
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number

Why can't it say something like:

second argument to + was "foo", a number is expected

While, it's obvious what's going on to somebody who's got experience with the language, it's very daunting for beginners.

2

u/iamzeph Jan 20 '14

To be fair, Python isn't much prettier, other than including the operand (which isn't exactly relevant in Clojure):

>>> 1 + "foo"
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: unsupported operand type(s) for +: 'int' and 'str'

6

u/ares623 Jan 20 '14

I think python's is better. It's easy to parse that using + for an int and str is not allowed.

It's not the case in Clojure's message.

-10

u/[deleted] Jan 20 '14

Who cares what python does or does not do?

11

u/david72486 Jan 20 '14

It's relevant to see how other languages behave under similar conditions, as a point for comparison.

-6

u/[deleted] Jan 20 '14

Why not compare it to a language that wasn't designed by a clueless newbie? Set your sights higher, comparing to python is like saying you're pretty good at basketball by comparing yourself to primary school standards.

2

u/kankyo Jan 20 '14

...like? And please post the corresponding error message from your chosen language.

5

u/minikomi Jan 20 '14 edited Jan 20 '14

Racket's use of contracts ensures that you get good errors for almost all builtins:

> (+ 3 "yeah")
+: contract violation
  expected: number?
  given: "yeah"
  argument position: 2nd
  other arguments...:
   3
  context...:
   /Applications/Racket v6.0.0.1/collects/racket/private/misc.rkt:87:7

Bonus: doing (help number?) will point you at [number?](http://docs.racket-lang.org/reference/number-types.html#(def._((quote._~23~25kernel)._number~3f))) 's definition

2

u/[deleted] Jan 20 '14

I like CL, this is the result using one implementation (clisp):

[1]> (+ 1 "foo")

*** - +: "foo" is not a number
The following restarts are available:
USE-VALUE      :R1      Input a value to be used instead.
ABORT          :R2      Abort main loop

-2

u/[deleted] Jan 20 '14

Yes, the dreaded Common Lisp errors that won't bail out back to the repl!

3

u/david72486 Jan 20 '14

It sounds like you're saying Python is not a serious programming language, just as you wouldn't expect a primary school basketball star to compete in the NBA. If that's what you're saying, then I think many people would disagree with you. If I'm overly generalizing, feel free to elaborate.

2

u/iamzeph Jan 20 '14

oaty1 is a troll around here; check out his comment history in this sub. He's also obviously a huge CL proponent (maybe religiously so), and while CL does some things very well, it's also (IMO) a giant hairball, the epitome of cruft and design-by-committee.

3

u/joequin Jan 20 '14

I don't like python at all, but it does do error reporting better. Do you really want python to do something better than Clojure because we refuse to recognize it?

0

u/[deleted] Jan 21 '14

[deleted]

1

u/iamzeph Jan 22 '14

Well no, my point that a highly used language like Python has its warts too (it has plenty, but I mean in regards to error reporting).

The Racket and (to a lesser degree) CL examples below are friendlier errors, tahat get to the crux of the problem.

2

u/Daishiman Jan 24 '14

But Python has niceties like clearly reporting where an error appear and, for the most part, exceptions are well laid out.

This has been the exact same problem I've had with Clojure; 50 line stack traces of Java functions that mean nothing to me.

1

u/Anderkent Jan 20 '14
(+ 1 "foo")
ClassCastException java.lang.String cannot be cast to java.lang.Number  clojure.lang.Numbers.add (Numbers.java:126)

The clojure.lang.Numbers.add should help.

As to why it can't be nicer - it could in this specific case, but a general solution is hard. Numbers.java could typecheck args before casting (or catch ClassCastExceptions)... But that's still not super useful if you don't know how exactly the function was called.

2

u/yogthos Jan 20 '14

I'm mainly saying that it could print the argument that it got in the error message. It's already there, and the function name should be available as well as it's just a symbol.

Again, we know what function was called, because it was called as + and not as clojure.lang.Numbers.add, all the information is there, it's just not being shown in a friendly way.

1

u/Anderkent Jan 20 '14

This information is out there somewhere, but it's several layers of indirection between it and where the actual problem occurs. Now, I suppose you could do stack trace inspection and thus derive what actually called you, what args were given to it, etc. But it's not simple, writing it separately for every core function would be insanity, and a generic solution is even harder.

3

u/yogthos Jan 20 '14

So, just to be clear what I'm proposing is this:

  • the function prints its own name in the error message

  • the function prints out the parameters that it sees on the stack

That's all we're talking about here. I see no reason why this information can't be captured and displayed in a generic fashion when an exception occurs.One approach is to simply catch the exception at the call site and inject the information there, I'm sure a more efficient way is possible though.

1

u/Anderkent Jan 21 '14

Ah, but which function? The one that throws the exception? Then you'd see clojure.lang.Numbers.add 1 "foo". Which, sure, is somewhat useful, but adding a try catch to every single function out there is a pain.

The lowest level clojure function in core? Again, either have to manually add the same codeblock in every function (luckily with macros that might be more manageable - defcorefn or something that catches ClassCastExceptions) - but you have to check where exactly the classcast is happening (could be that the exception is unrelated to the args), the java / clojure boundary is somewhat arbitrary at times, and it all seems pretty messy.

The problem is that any 'generic' exception you see (NPE, ClassCast etc) might come from the clojure code, but might code from some underlying java lib. You want 'prettified' output in the first case, but still the original output in the second. I guess clojure could switch to its own exception types that know how to render themselves... But again, it's a large change in many places, not a generic solution.

4

u/yogthos Jan 21 '14

I agree that it would be a large change, but it certainly would be very helpful to users.

A proper solution is obviously not trivial, but it's certainly is not intractable either. This is probably one of the most common time wasters for the developer, as you see a lot of silly errors all the time and you have to spend those extra seconds parsing them in your head.

I think a good example of the impact is Clang vs. GCC error reporting. Right now, Clojure reports errors like GCC and it causes pain and frustration to all the users on daily basis.

2

u/OmniJinx Jan 19 '14

On the next-to-last point about the commented out code, I agree that it should have been deleted rather than commented out. However, a quick git blame gives you the commit, so it's not without explanation.

https://github.com/clojure/clojure/commit/679c79508713acddca1e18d1e28dafae885e5096

5

u/xenomachina Jan 20 '14

I find it somewhat ironic that you suggest using git blame to find the explanations for commented out code. Commented out code tends to be a sign of someone who doesn't really trust their version control system. In general, code should be deleted, not commented out. If someone needs it back they can get it from an older version of the code.

3

u/burkadurka Jan 20 '14

This is true, unless (not sure if this is case here) you want the commented code around as documentation for the surrounding code. For an imaginary example

// FIXME: this is a hack around issue #352 until someone figures out why the commented out portion segfaults
//missiles.launch();
gun.shoot(target=missile_launch_button);

1

u/kankyo Jan 20 '14

There are other use cases for commented out code too, like some code that makes debugging easier. This is not the case here though...

5

u/xenomachina Jan 20 '14

Right, though in that case you're effectively talking about code that's part of a comment (ie: acting as documentation), not commented out (ie: merely disabled) code.

7

u/Anderkent Jan 19 '14

Uh 'Get rid of X' is not an explanation for why X is commented out. I can see you got rid of X.

4

u/crazysim Jan 19 '14

I have a fairly small one.

"Copyright 2008-2012 Rich Hickey"

1

u/ares623 Jan 20 '14

Heh, yeah. I always found that strange. No problem with it though.

4

u/crazysim Jan 20 '14

I think it is a problem. The pages aren't very Web 2.0 big font everywhere and use-all-the-spaces so its above the fold usually on the screen and that makes it pretty prominent. The copyright notice on a site is a cheap thing to check for when considering how maintained a project is. The OP is about first impression and this doesn't help that.

5

u/kankyo Jan 20 '14

Hah, hadn't seen that. This is a little embarrassing. Newbie mistake to write copyright years like that. One should always write "2009-" or have some code that grabs the current year for the end when you generate the page.

10

u/neverov Jan 22 '14

Clojure favors immutability, that's why the code is not deleted, just commented out.

2

u/agumonkey Jan 19 '14

I agree about commented dead code but this is very short and atomic (a small class). There are other short bits spread around though. Seen far worse (not in clojure) that was run by thousands of websites.

2

u/ares623 Jan 20 '14 edited Jan 20 '14

Dammit I hate the errors so much. When working in the REPL, I have to scroll a lot just to see what I did wrong. And I work in a tmux session. Scrolling in it sucks. And even worse, sometimes the errors don't even make sense!

Are the official docs subject to the CA as well? That could explain the lack of it. Signing the CA just to contribute docs sounds like a pain.

4

u/crazysim Jan 20 '14 edited Jan 20 '14

Needing to mail the CA is such a contributor boner killer.

edit: though the pedestal CA workflow is generally better. Maybe they'll adopt that for Clojure itself someday.

http://pedestal.io/#contribute

1

u/[deleted] Jan 22 '14

And I work in a tmux session. Scrolling in it sucks.

Does it help at all to zoom in on that pane?

2

u/tonetheman Jan 20 '14

Ooooh yes. That one first one is killer. Not only should the top link on how to get started with clojure include lein it should say look here is hello world, and then give details on how it is supposed to work.

I took messed with clojure and was amazed at how many things I read that said run the repl and I constantly cursed and said thats great I would like to write a program and run that...

1

u/[deleted] Jan 19 '14

On #2, that's standard for the JVM, though a related annoyance with Clojure is that the stack traces you get are often pretty weird and harder to discern meaning out of than your average Java or Scala stack trace.

1

u/sandos Jan 19 '14

I agree about the built-in test message, they are way too confusing.

1

u/iamzeph Jan 19 '14

These definitely are rough patches for Clojure, but it's not like no one is aware of them :) I'm sure Rich et al. are more interested in making sure the functionality is there first.

0

u/[deleted] Jan 20 '14

[deleted]

3

u/yogthos Jan 21 '14 edited Jan 21 '14

I think the fact that we're starting to have these kinds of discussions is a great sign.

Clojure has been around for a little while, but it looks like in the last year it's been getting a lot more attention and as more people start using it the more pressure there's going to be to polish the rough edges.

While I don't agree with all the points the author raises, it's fantastic to get a fresh perspective and start the discussion on how to improve the developer experience.

-9

u/lgstein Jan 19 '14

I think it's supposed to be some kind of joke.

5

u/kankyo Jan 19 '14

"it" being? The post or the 30+ lines of stack trace? :P