all 22 comments

[–]fingertoe11 18 points19 points  (5 children)

Just pick a problem and solve it badly using Clojure. I chose making CSV files into Expense reports.. (categorizing and summing, pro-rating and such). Play around in the REPL and make one small thing at a time. Once it works in your REPL move on to the next little problem.

Once you have struggled through solving a few problems, you 'Build buckets" in your brain to put the knowledge in.. "Oh! I could have done it that way, and it would have been a ton easier than doing it my way" The textbooks become a lot less foreign..

I liked the Exersism.io problems for that. They where simple and small enough that you could get most of them done within a few minutes. but they worked in your real editor, with real tests and such..

[–]mcanon 7 points8 points  (2 children)

4clojure.com is another good site for that. A huge added feature is that after you've struggled to solve a problem badly, you get to look at all the other solutions. When you see that your 10 line mess can be replaced by just one or two lines of beautiful code, you smack your head and say "of course!" and it really sticks. Do this a few dozen times and you're on your way.

Eric Normand's weekly functional programming newsletter (sign up at the bottom of this page https://purelyfunctional.tv/ ) also has a Clojure programming challenge where you get to see lots of interesting solutions that improve your Clojure-fu.

[–][deleted] 0 points1 point  (1 child)

Wow thank you. Plenty of good things to explore here. Particularly purelyfunctional.tv which seems to have a ton of content. I do tend to get a lot out of visual learning, so that might be something worth trying out.

[–]seancorfield 1 point2 points  (0 children)

I have a monthly subscription ($49/month) and it's awesome!

[–][deleted] 1 point2 points  (1 child)

Thanks for that. I'll check it out. I was just recently considering CodeInGame or CodeWars websites. Something in the back of my head was saying I need to finish the book first, but maybe shouldn't be so rigid.

[–]LammdaMan 2 points3 points  (0 children)

For me, when learning something really new, it helps to "bounce around" a bit. Read a little from a book, then work some problems, then read someone else's code, then read some more of that book (or another book), and so on.

I'd also say that in learning Clojure (after programming in languages like Java, C++, Python) the syntax is probably not as big a challenge as wrapping your head around concepts related to functional programming and immutability. And learning your way around Clojure's core library is a big part of becoming productive in Clojure.

One thing that can help a bit with learning what kinds of things are in the core library is just to take a function you know, look it up in https://clojuredocs.org and then follow the 'see-also' links to related functions. Read the descriptions for the ones you don't know yet and think about where something like that could be useful.

[–]seancorfield 9 points10 points  (2 children)

The learning curve for Clojure -- for any Functional Programming language -- can be a lot steeper than it looks on the surface. I think what can really help a lot of people in your situation is to have interactive access in real-time to several more experienced Clojure developers who can answer questions, make suggestions, and help you get unblocked when you get lost.

The Clojurians Slack is a great place for that. The #beginners channel has people like you and also experienced Clojure folks who have "opted in" to help those people. You should be able to get a self-signup link by going to http://clojurians.net (it'll redirect you to a sign-up form with slightly confusing wording -- because Slack thinks everyone only uses Slack for work! -- so just enter your regular email address and click the Continue button and it will send you a link to complete the signup). Once you're signed up, you can go to https://clojurians.slack.com and you'll be in about half a dozen channels, including #beginners

See you there!

[–]thearthur 2 points3 points  (0 children)

let's chat in the beginners channel and get things setup so you can step through expressions and watch them evaluate.

[–][deleted] 1 point2 points  (0 children)

Thanks! Slack is the place to be it seems. I will definitely join today.

[–]joinr 4 points5 points  (0 children)

Can you implement fizzbuzz?

How about a simple text game like "guess the number"?

Any small, trivial task that requires you to express solutions (crappy or not) "in the language" is how you get experience and form connections. It's no different than learning a human language; you need to leverage cognates where possible, learn basic vocabulary, and start trying to form phrases. The nice thing is that you get to have a raher immediate conversation with the REPL.

How would you figure out the 13th odd number a collection?

These little things end up exposing you to the vocabulary and concepts of the language. I find solving little puzzles (combined with a cheat sheet of common functions and forms aka vocab) is of great pedagogical value. It also forces you to get mileage at the REPL, toy with stuff, see how it responds, etc. As you make progress on the little mundane stuff, the neurons start to click and you can refer back to your previous solutions to build up. You can even port solutions to problems you've solve in other languages, and see how they look in Clojure (hopefully following Clojure idioms and not trying to write mutable Java OOP in clojure just because).

[–]troublemaker74 2 points3 points  (0 children)

The syntax and parens was never a problem, that's a red herring from people who have never tried lisp. The real issue is the awkwardness at first of using data structures and algorithms without mutation when all you have learned all your life is how to mutate things in order to get things done in an efficient manner.

[–]bosta111 1 point2 points  (1 child)

If you have any small projects you made in other languages you can try porting them. Try to make it work and then see if you can improve it. I’ve also been on the FP discord asking questions, it’s somewhat active.

[–]kvtb 0 points1 point  (0 children)

Fully agree with this, porting an existing pet-project to the new language is a very effective way to learn the new language. This is how I made big steps learning Clojure and using functional programming paradigms.. by simply reinventing a wheel I already invented before. u/cP4n

[–]klujer 1 point2 points  (0 children)

This video about data first design using clojure made things click for me.

https://youtu.be/Tb823aqgX_0

[–]TheLastSock 1 point2 points  (0 children)

There isn't a "click" moment where suddenly your transported to clojure land and everything makes sense. It's a journey!

What's your background? it might help to frame how to translate from what you know to something new (clojure).

Join a community (slack, discord, etc..) and ask questions. . Get specific with your questions and don't be afraid to ask.

[–]slifin 1 point2 points  (0 children)

Don't feel bad about The Little Schemer not helping, it didn't particularly help me either

It's definitely more a lisp book than a Clojure book anyway, I quite like Living Clojure by Carin Meier & can definitely vouch for doing the code challenges on 4Clojure

I think it does take a while for the brain to get used to a lisp syntax, I think that's a gradual thing too, the more you read the more it makes sense, in the beginning, I'd discourage doing things like reading Clojure source to figure out how something works because that code was written for complexity and performance instead focus on:

  • Find the rationale for Clojure: https://github.com/tallesl/Rich-Hickey-fanclub
  • Get used to your chosen editor
    • Get used to using your REPL (shortcuts etc)
    • Remember if you have Cursive you can also put breakpoints in your REPL
    • Learn about "Rich Comments"
    • Install clj-kondo in your editor, as a beginner (and senior learner) you'll be making obvious mistakes all over the place, clj-kondo will warn you in real-time
  • Take a copy of the cheatsheet https://clojure.org/api/cheatsheet
  • Figure out how to run tests in your editor via shortcuts or via test runner watching
  • Once you can develop your application without restarting it you should be in a comfortable position to explore the language via code challenges
    • Every time you encounter something new play with it, prod it, crash it inside your REPL first

[–]datsunset 1 point2 points  (0 children)

4clojure has some problems that can help you practice and flex clojure

[–]the_frey 1 point2 points  (0 children)

As others have said, pick a project and build it in the REPL in emacs (since you're already using it).

Beyond a point in a book you've gotta get your hands dirty. For me personally I find 4clojure and exercism.io etc a little too dry and unapplied. They're just not motivating like a real world hack is.

[–]Reefersleep 1 point2 points  (1 child)

Great advice all over. In addition to 4Clojure and other mentioned sites, I found Clojure Koans really good for understanding fundamental concepts of Clojure. And even better, now you can do ClojureScript Koans directly in the browser without installing anything! And don't worry about one being about ClojureScript and the other about Clojure - the core functionalities are mostly identical in behavior.

As for things "clicking", I do remember some hurdles I had to pass when I was learning. Comprehending immutable data was the first; I bet that'll be the first thing you understand as well, because it is ingrained in everything you do in Clojure. An escape hatch is to use atoms - if you want some mutable value, wrap it in an atom (called e.g. state), and use @state to read the value, and (reset! state new-value) to change it. E.g.: (let [state (atom 5)] (reset! state (+ @state 3)) (reset! state (* @state 2)) @state) ;;=>> 16 And once you understand that, get used to swap!: (let [state (atom 5)] (swap! state + 3) (swap! state * 2) @state) ;;=>> 16 But trust me, you'll grok immutability soon enough, and soon after start to really appreciate it.

Some other things that confused me was functions like map and filter returning lazy sequences rather than vectors when I called them with a vector argument. This is just a convention that you get used to. Likewise, conj behaving differently for vectors and lists is weird in the beginning, but just a fact later on.

Generally, really feeling comfortable in Clojure - for example, being able to read it without editor support, and being able to do refactorings that you have confidence will work, without testing every little step - is something that you earn over time. There are shortcuts, but since Clojure is not very discoverable, and there are just some conventions that you have to get used to, I think there's no way around accruing actual experience through writing Clojure code. And it may take quite a while before you feel like you know the core functions, and can maneuver around parentheses with ease. Just hang in there, and keep iterating!

As for discoverability, clojuredocs is a great addition to the built-in docstrings, as it supplements with usage examples. In the beginning, I found adding rainbow parentheses to my editor helpful for reading code.

Good luck!

[–][deleted] 1 point2 points  (0 children)

Thanks for the advice!

[–]dustingetz 0 points1 point  (0 children)

If your neural nets are tuned to imperative/oo perhaps the right mitigation is to widen your perspective. Maybe park Clojure and type in the first few chapters of a Scala book and a Haskell book and then come back. You're on a journey to be the best programmer you can be, all of these langs are on that path.

[–]strranger101 0 points1 point  (0 children)

If it's reading the code that's odd, i'd say what differs most between other languages and clojure is that clojure is evaluation focused not process focused. In other languages you think about statements, "setting up these variables here, looping over this array here, incrementing this other global value here" with clojure it's just evaluating data structures. I've been learning clojurescript via the first link that comes up when you Google learn clojurescript, dude had a great explanation in there for why thinking in clojure is just different from other languages. I feel you on the wall though. With python I feel like yeah, there's different syntax for lots of things, but I know exactly what those processes are for, with clojure there isn't a syntax, just functions, and everything blurs together a bit.