TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Clojure Error Messages Are Accidental

93 pointsby bloatalmost 7 years ago

11 comments

bedersalmost 7 years ago
It&#x27;s unfortunately part of the learning curve. Being a beginner with clojure myself, I was put off by some of the more arcane error messages.<p>But compared to &#x27;undefined is not a function&#x27; it&#x27;s about 10 times better ;) Glad to see this being improved.<p>Don&#x27;t get discouraged by this. Even if you never plan to use Clojure in a project, dive in and take a good long gulp from the functional tea of enlightenment. It will make you a better programmer.<p>My advice for people complaining about docs: <a href="http:&#x2F;&#x2F;clojuredocs.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;clojuredocs.org&#x2F;</a> is much much nicer.<p>The standard docs are very very terse and you&#x27;ll need to learn the typical abbreviations and idioms.
评论 #17432034 未加载
james-mcelwainalmost 7 years ago
Clojure is just so coupled with the host language. Which isn&#x27;t a bad thing, since it helps make interop effortless, but does make it difficult to appreciate as a standalone language.<p>I first tried to learn Clojure before I knew anything about Java and things like error messages made it really difficult to get started.<p>Coming back after having written Java professionally for a year, things like random Java exceptions showing up or long stack traces suddenly became a lot more tractable, although still not &quot;beautiful&quot;.
评论 #17432062 未加载
kimialmost 7 years ago
Alex Miller wrote a few days ago on this very topic: <a href="https:&#x2F;&#x2F;clojureverse.org&#x2F;t&#x2F;improving-error-messages-in-clojure-as-a-library&#x2F;1765&#x2F;27" rel="nofollow">https:&#x2F;&#x2F;clojureverse.org&#x2F;t&#x2F;improving-error-messages-in-cloju...</a>
gkyaalmost 7 years ago
That implementation for &quot;keyword&quot; is simply horrible. If it&#x27;s correct that most errors caused by bad input to functions come not from verification but from an arbitrary place in code where a type-specific operation is applied is correct, that&#x27;s more horrible. This deeply discourages me from touching Clojure ever.
评论 #17430931 未加载
评论 #17432760 未加载
lbjalmost 7 years ago
The overall conclusion is correct, most error messages happen by accident, but a lot the examples look like expected behavior to me. Maybe because Ive been using Clojure for too long, or maybe because its the expected trade-off when using a dynamically typed language. You get more fluidity at the cost of type checks - The way to mitigate this downside is adding checks of your own. Clojure has supported this since way back when using pre&#x2F;post conditions.<p>Example:<p><pre><code> core&gt; (defn mydiv [n d] {:pre [(pos? d)]} (&#x2F; n d)) #&#x27;mydiv core&gt; (mydiv 10 2) 5 core&gt; (mydiv 10 0) AssertionError Assert failed: (pos? d) core&#x2F;mydiv </code></pre> As opposed to the standard<p><pre><code> core&gt; (&#x2F; 10 0) ArithmeticException Divide by zero clojure.lang.Numbers.divide (Numbers.java:158) </code></pre> Chasing down Numbers.java will take time, but with a pre-condition you get the exact name of the function and the test which failed.
评论 #17430896 未加载
alkonautalmost 7 years ago
&gt; The worst sin of stack traces is that the most important information is printed first, then followed by less and less important information, usually a few screenfuls of it.<p>No. It’s at the top of the web browser window. At the top of the unit test out window in the IDE and so on. Flipping stack traces to help console reading would be a mistake. Should be made optional in that case.
al2o3cralmost 7 years ago
&gt; But if the official spec doesn’t restrict get, Spec will let people redefine the spec for get for themselves.<p>&gt; They can choose whatever subset of the type they want.<p>Total clojure-spec noob question: is this type scoped somehow, or does using your own type mean chasing down bugs in libraries that assume a looser version?
评论 #17424788 未加载
评论 #17430890 未加载
kuwzealmost 7 years ago
Yeah Clojure&#x27;s error messages pushed me to Common Lisp (although I am still quite a neophyte in both).<p>I haven&#x27;t tried it, but maybe Sayid[0] would be of help to Clojurians?<p>[0]: <a href="http:&#x2F;&#x2F;bpiel.github.io&#x2F;sayid&#x2F;" rel="nofollow">http:&#x2F;&#x2F;bpiel.github.io&#x2F;sayid&#x2F;</a>
评论 #17432154 未加载
hota_mazialmost 7 years ago
&gt; It is more useful to think of error messages as non-existent than to think of them as bad.<p>If this is true, my respect for Clojure just completely dropped.<p>Error messages are a crucial part of a language and they are instrumental to the robustness of the programs it helps create.<p>The fact they have been so severely neglected by the Clojure teams makes me think the authors of the language don&#x27;t really understand modern large scale programming.
评论 #17431264 未加载
评论 #17432404 未加载
评论 #17431238 未加载
评论 #17431321 未加载
评论 #17432517 未加载
评论 #17432048 未加载
jgalt212almost 7 years ago
Very good talk by Bozhidar Batzov at PartialConf 2017 that covers this point as well.<p>Clojure, The Bad Parts<p><a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=1YCkOo5Y4Oo" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=1YCkOo5Y4Oo</a>
didibusalmost 7 years ago
I think most of the reason for not having all these runtime checks in core is performance.<p>Though I guess if there was an easy way to turn them off for production it would maybe be okay.
评论 #17431951 未加载