r/Clojure • • Jan 07 '19

State of Clojure 2019 Survey

https://clojure.org/news/2019/01/07/clojure-2019-survey
70 Upvotes

24 comments sorted by

8

u/alexdmiller Jan 07 '19

If you took the Clojure survey, and marked “Reference docs” as a priority for making improvements, I would be interested to learn more.

  1. do you mean something other than the docs at https://clojure.org/reference/*? (Like API docstrings?)

  2. do you think existing docs should be improved or new things added. And then I’m interested in learning if there are specific things (if so, an issue at https://github.com/clojure/clojure-site/issues would be best) or if this is something else.

Just trying to understand better when you marked that, what did you have in mind for improvement?

14

u/vincent-dm Jan 07 '19 edited Jan 07 '19

I did. Mostly because I had a lot of trouble making sense of them when I started with Clojure (2016). Since issues with documentation affect beginners the most, I think it's useful to make it accessible to them.

I gave some examples of what bit me back then in the notes, but I'm more than happy to expand on what held me back as a beginner:

  1. official API is very terse IMHO. It reminds me of minimalist poetry in how it tries to convey maximum meaning with a little words as possible. I always use Clojuredocs, but unfortunately the examples listed there seem uncurated (lots of overlapping or confusing examples)

  2. The Reference is much more accessible, but still seems to be biased towards people with a Lisp and/or Java background.

In the survey I mentioned how the pages about polymorphism assume a lot of familiarity with why it is needed and how it is done in other languages. I see an opportunity to add a more general reasoning of why closed code (like switch statements) can often be improved with polymorphism and how it is better. E.g. an example of two pieces of code which contain a similar case statement, and how they are replaced by a protocol + record. Another useful thing would be a table to compare to pros and cons of the different polymorphism mechanisms in different situations.

Another example of a hard-for-beginners page is the one about macros, which begins with

Clojure has a programmatic macro system which allows the compiler to be extended by user code. Macros can be used to define syntactic constructs which would require primitives or built-in support in other languages. Many core constructs of Clojure are not, in fact, primitives, but are normal macros.

When I was a beginner, coming from a PHP background, macro's were a mystery to me, similar to how I hear people talk about monads etc. A paragraph like the one above is not really helpful in that case, since it uses a lot of jargon. For me it created more questions than it answered:

  • What does programmatic mean here? What would be an un-programmatic system?

  • Why in god's name would I want to extend a compiler? That sounds like something geniuses like John Carmack do. (IMHO the problem is that the sentence describes a mechanism to do something, but does not mention any goal I consciously want to achieve as a budding programmer)

  • syntactic constructs I would be assuming (but uncertain) that this basically means the same as the word syntax (as how it is used in casual conversations, e.g. HN comments or SO discussions)

  • core constructs what is a core construct?

When I was a Clojure noob, I would probably have been helped more with an introduction in the spirit of:

Macros are just Clojure code, but what makes them special is that they are run before compilation and generate other Clojure code when executed. You can use other people's macros or define your own to make your code shorter or more expressive (similar to how you can use a formula to generate a series of values in a spreadsheet, or define abbreviations to type faster on a smartphone).

A benefit of macros unique to Clojure (and other Lisp-languages) is that they can be used to define new, non-standard syntax, as long as it is a valid s-expression. Execution of a Macro is called macroexpansion and happens once (right before your code is compiled), so there is no runtime performance penalty for code that was generated using macros.

If you ever wrote any Clojure code, you probably already used macros: a lot of things that look like function calls (like defn) are actually macros which expand into a much more verbose syntax which uses only core constructs.

I'm improvising here: my text is probably full of inaccuracies and writing it made me realize again how hard it is to write something that is accessible and correct. Nevertheless, I believe there is room to make these references more suitable to help beginners get started.

I realize that a form like this would also be irritating to experienced programmers, so maybe it would make sense to have a beginner's guide and a more advanced one.

By the way: I find the spec guide an example of a very good one. The moment it came out I immediately realized both why this new library was useful and how it could be used, mainly because of the verbose explanations and the many examples (e.g. the deck of cards).

3) I can't really say much about the tutorials, since the format doesn't really work for me. I personally prefer to read about the concepts and then look up specific small examples (Clojuredocs, Stack Overflow,...) instead of a tutorial which will superficially touch myriad things which I am currently not interested in or prepared for.

I'm lucky that since 2 years I have a colleague who has been very good mentor to me, by helping me understand many concepts of Clojure and programming in general. With each new understanding I become more capable to use the documentation on the official site.

Nevertheless, the memory of running into a wall on these pages due to lack of experience and context is still fresh, so I hope sharing this perspective is useful to you.

To summarize: documentation which addresses the why-question in accessible terms (what real-world problem does this solve), preferably with examples, makes the how part much easier to understand.

3

u/alexdmiller Jan 07 '19

Thanks, that's helpful. Just to add some context (really not trying to "debate" or disagree at all, this really was useful)...

  1. The API docstrings are intentionally concise as you say, attempting to convey the necessary info with as few words as possible (and conversely to avoid saying things which are not committed to, which is in some ways more important :) So we have no plans to change the overall nature of the docstrings (making them longer would actually also increase code size and reduce code loading times, which are other complaints). That said, we think there are many opportunities to combine docstrings with other sources of information to produce richer docs (like Clojuredocs). Certainly an area where more can be done.

  2. The Reference pages are a step up from the API docstrings in that they cover topic areas and can tie together threads between many individual functions. As reference docs, they are intended to be more comprehensive and authoritative, but may not be the best place for actually learning something from scratch.

  3. The Guide pages are more guided tours through different topics. You mentioned the spec guide, but seemed to treat that as a reference? Certainly having a macros guide (or guides!) would be great.

Core team members have written a lot of long form "why" documentation but we have published it as books instead (Programming Clojure, 3rd ed has been worked on by both Stuart Halloway and myself, and Clojure Applied from myself and Ben Vandgrift). Writing these kind of docs is (at least for me) super time-consuming (literally years of work) and requires professional editing, indexing, etc. Or you could consider many of the times we've all given over the years as a different form of "why" docs, which are available for free on ClojureTV.

2

u/vincent-dm Jan 08 '19

I guess I never realized that there's a difference between References and Guides. I mostly end up on these pages because I'm Googling something I want to better understand. The distinction makes sense, but maybe it would help if there is a clear 1:1 relation between a Guide and a Reference for each topic, with cross-links between them?

Regarding books: I bought quite a few of them (Joy of Clojure, Clojure Applied, Mastering Clojure Macros, Java Interop,...) and they are helpful, especially when I take time to sit down and do a "study session". But for me, personally, the medium of books (including e-books) is ill suited to help me while I'm developing.

I mostly learn by running into a specific need and looking for a concrete solution to it. If I stumble upon docs which also give me some guidance (e.g. you can use this function in this way, but be careful not to use it in that way or performance will suffer) the lesson is most likely to stick.

From a beginner's perspective, it would be ideal if all contents of technical books would be online as HTML and findable by search engines. But of course, authors also need to put bread on the table, and most of them already do trememdous work for free. I guess there's an inherent tension between economically viable models for contributors and a documentation-ecosystem that is optimized for beginners who are not committed enough to buy into paid documentation.

2

u/alexdmiller Jan 08 '19

I'm not sure if there's a 1:1 relation in all cases, but definitely would love to have references in a couple places (like spec) that are missing and guides in many places to pair up with reference pages.

Thanks for the feedback.

8

u/[deleted] Jan 07 '19 edited Jan 07 '19

Here's a specific thing that I wasted hours on recently: Attempting to discover the recommended and best way to inherit JS ES6 classes in ClojureScript where the equivalent JS code would use the `extend` keyword. There are a number of approaches and I tried all of them but none of it was obvious.

I wouldn't personally create APIs that do this. However when consuming libraries, for example React components, this sort of thing (sub-classing) is very common, unavoidable and expected.

More detailed reference examples of common ClojureScript scenarios would be greatly appreciated.

3

u/alexdmiller Jan 07 '19

It would be great to make an issue at https://github.com/clojure/clojurescript-site/issues for this so someone could make improvements...

3

u/dustingetz Jan 08 '19

Re. "namespaces improvements" I would like to see thought guidance regarding data namespaces and/or tooling improvements that show a clear right way to do this

1

u/nogridbag Jan 07 '19

I took the survey but when I clicked "Next" after answering all questions it simply brought me to the same page with no confirmation that the survey was submitted. Strange.

1

u/alexdmiller Jan 07 '19

Hmm, maybe a glitch. Try again?

2

u/nogridbag Jan 07 '19

Worked fine the second time!

1

u/[deleted] Jan 07 '19

Same thing happened to me about an hour ago.

1

u/vincent-dm Jan 07 '19

same here

1

u/3rdkulturekyd Jan 08 '19

Same with me too :(

24

u/[deleted] Jan 07 '19

[removed] — view removed comment

4

u/nogridbag Jan 07 '19

This was also my feedback in the final comment question although you stated it much more eloquently. If I had to rely solely on the doc strings it's possible I might have even given up on Clojure. Since I'm also a beginner I find I'm spending most of my time referencing the top 1 or 2 examples on ClojureDocs and avoiding the doc string completely. Right now I'm just tinkering but it makes me a little fearful that using Clojure in a large app without spec or disciplined developers may become really difficult to follow.

I've bought into the idea of preferring maps over Objects but I must admit one of Java's killer tools is JavaDoc.

3

u/alexdmiller Jan 08 '19

There are many, many great beginner resources for Clojure. Is there some reason you felt you may have had to rely only on docstrings? I think it's unrealistic to expect to learn any language based just on the API docstrings alone. Is there some point during when you were getting started that would have been an opportune place to suggest beginner resources?

4

u/nogridbag Jan 08 '19

Oh I definitely didn't have to rely solely on docstrings. I read Brave Clojure and your book Programming Clojure! Both are excellent resources. But often I forget the exact usage of some function and looking through examples in books for a specific function's usage is more time consuming than a reference website or typing (doc "something") in the repl. My previous comment was poorly worded. Without ClojureDocs, my getting started experience may have simply been more frustrating.

I think the issue for me is many of the core methods are overloaded and can do different things given different inputs. In a typed language like Java, these would be separate methods each with a few sentences of documentation (and often an example if the behavior is complicated) in the official JavaDoc. The types also clearly show me the shape of the data I need to pass and the expected return value.

I can't think of a great example but just taking one at random here's the docstring for into.

user=> (doc into)
-------------------------
clojure.core/into
([] [to] [to from] [to xform from])
  Returns a new coll consisting of to-coll with all of the items of
  from-coll conjoined. A transducer may be supplied.

Just from reading this I would never expect to be able to build a map given a vector of two-elem vectors (key value pairs). But ClojureDocs has a clear example of that:

;; This is ok:
(into {} [[:a "a"] [:b "b"]])
;;=> {:a "a", :b "b"}

;; But this isn't:
(into {} ['(:a "a") '(:b "b")])
;;=> ClassCastException clojure.lang.Keyword cannot be cast to java.util.Map$Entry 
clojure.lang.ATransientMap.conj (ATransientMap.java:44)

I realize the key behavior is in conj but the docstring for that also does not make this clear.

2

u/alexdmiller Jan 08 '19

I think there's still a lot of open space for doc (or some add-on) to include additional external documentation. Thanks for the feedback.

8

u/stingraycharles Jan 07 '19 edited Jan 07 '19

The examples were a life saver for me, and still are when trying to figure out more complex behaviors.

It would be great if Cognitect could incorporating them into one, but I'm highly skeptical this would ever happen in that way; more realistically, they will add comment functionality to the existing docs and call it a day.

8

u/[deleted] Jan 07 '19

Agree that the official API reference pages are too dry and seem to assume prior knowledge at times. Much better to have real examples of API usuage that can be pasted into the REPL. I almost never use https://clojure.org/reference/* but use ClojureDocs all the time.

4

u/foobarbazquix Jan 07 '19

cljdoc.org is another source for documentation driven by the community. It’s extensible and covers libraries too. They recently added Dash Docs support for anyone who uses that. The project is on GitHub and the main author is supportive and welcomes contributors.