4 ms·
I'm pretty sold on Clojure's value, I've read up on its structure/syntax, but generally struggle with learning the standard lib and trying to read/write actual
by lukifer 7y ago
I'm pretty sold on Clojure's value, I've read up on its structure/syntax, but generally struggle with learning the standard lib and trying to read/write actual code. Any resources you can recommend for gradually ramping up, and/or "lightbulb moments" for a dev steeped in C-like languages?
- vnorilo 7y agoHaving written C++ for 25 years, I found it very enjoyable to write small toy client-side web apps with clojurescript, figwheel and reagent. Reagent's Hiccup-like syntax for html is lightweight and gets you interactive stuff on screen quickly with hot reloading. Iterating quickly helps me learn, and getting dynamic graphics on screen provides that dopamine drip feed I need to stay motivated.
- ex3xu 7y agoOutside of standard recommended resources like the ones offered here [0], I found that doing the problems on 4clojure.com and then comparing with the answers of top users was helpful for experiencing some of those kind of lightbulb moments in Clojure. [0]: https://github.com/razum2um/awesome-clojure#guides https://github.com/razum2um/awesome-clojure#guides
- heartofgold 7y agoI second this. Struggle with each problem and then view other answers to see how elegantly they solved the same problems. This worked wonders for me as well.
- JamesLeonis 7y agoOne extremely useful resource is the Clojure Cheatsheet [1]. It organizes the standard library by all kinds of uses (data types, use cases, etc). It then links to the documentation of that function in Clojure.org, which often have examples of the function's use. Likewise, each function page (if you scroll down) has a "See Also" which lists similar functions, which helps discover other functions in the standard lib. Beyond the Standard Library, I find the Luminus Project [2] an excellent source of real-world code and documents for problems around web development. Further along these lines is the Clojure Cookbook [3] as well. [1]: https://clojure.org/api/cheatsheet https://clojure.org/api/cheatsheet [2]: http://www.luminusweb.net/docs http://www.luminusweb.net/docs [3]: https://github.com/clojure-cookbook/clojure-cookbook https://github.com/clojure-cookbook/clojure-cookbook > "lightbulb moments" for a dev steeped in C-like languages? I'm from C++, so I feel what you mean when moving from Imperative to Functional. I have two insights that helped me: * Despite the huge type systems, languages like C have "Raw Memory" as the universal data structure. Think about pointer magic or the `union` type. Clojure does something similar; Despite the different data structures, the universal structure is `seq` which allows iteration over a data structure in the same way pointers iterate over any memory. * Clojure's immutable data structures eliminate the Pass-By-Reference and Pass-By-Value dichotomy. As such, you aren't so much (with functions) altering memory as transforming data. It feels much more like math (especially Linear Algebra) where you are transforming data. Seeing my code as a series of transforms greatly helps my understanding of a piece of Clojure code.
- rafd 7y agoIf you're new to functional programming, I recently gave a talk on applying FP concepts at ClojureNorth: https://youtu.be/vK1DazRK_a0 https://youtu.be/vK1DazRK_a0 The main example I work through is in JavaScript so that Clojure's syntax doesn't get in the way (I love s-expressions, but they're not the point of the talk).
- pdsouza 7y agoCame across this talk a few weeks ago and I have to say this is one of the best pragmatic talks comparing non-FP vs. FP paradigms I've ever seen. I really like your example problem, how you explore state and mutation in the different paradigms, and how you refactor step-by-step towards a functional design. Thank you!
- rafd 7y agoI'm very glad you liked it! Thank you for your kind words.
- jonahbenton 7y agoAs someone who came from a similar background, the ice broke when I went from trying to write code the C way- in whole files, running the nascent program from the command line, struggling with compiler errors, adding printlns for debugging- to working at the repl. The repl is the whole thing.
- finalfantasia 7y agoIt seems to me what you’re struggling with is functional programming (the paradigm) instead of Clojure (the language or grammar) itself. This is pretty common for people who are used to the C-like languages. I strongly recommend reading “Clojure for the Brave and True” [1] (especially, Part 2) to anyone who is getting started on either functional programming and/or Clojure. [1] https://www.braveclojure.com/clojure-for-the-brave-and-true/ https://www.braveclojure.com/clojure-for-the-brave-and-true/
- microcolonel 7y agohttps://clojuredocs.org/ https://clojuredocs.org/ has been helpful, especially the examples, and the direct links to the code. Like working with libraries in any other language, if you have trouble understanding how something is working, reading the implementation is often your best recourse. Using let can also be a decent crutch, if you're just not used to doing things with functional composition and (occasional) macros.
- AlexCoventry 7y ago> Any resources you can recommend for gradually ramping up http://www.4clojure.com/problems http://www.4clojure.com/problems
- iLemming 7y agoOne of the best practical Clojure books in my opinion is this one: https://www.manning.com/books/clojure-the-essential-reference https://www.manning.com/books/clojure-the-essential-referenc.... IMO it's a second "must read" book after "Joy of Clojure 2nd ed."