PurelyFunctional.tv Newsletter 366: Is the Clojure philosophy bad for beginners?
From OO to Clojure Workshop!
Watch my free workshop to help you learn Clojure faster and shift your paradigm to functional.
Clojure Tip 💡
Is the Clojure philosophy bad for beginners?
People often ask if Clojure's philosophy is bad for beginners, so I'd like to address it in the context that I set up in the last issue. In short, if it's true that Clojure libraries shouldn't anticipate all of the needs of the user, doesn't it make it hard for beginners to use the library? My short answer is I don't know.
Here's the code from last week that the CSV library expects the users to write themselves:
(defn rows->maps [csv] (let [headers (map keyword (first csv)) rows (rest csv)] (map #(zipmap headers %) rows)))
Any experienced Clojure programmer could write something like this with
no sweat. But could a beginner? I doubt they could do it without some
help. Some of the concepts are at least intermediate level, like
It started to hit home in the Spring of '74 after I taught Smalltalk to 20 PARC nonprogrammer adults. They were able to get through the initial material faster than the children, but just as it looked like an overwhelming success was at hand, they started to crash on problems that didn't look to me to be much harder than the ones they had just been doing well on. One of them was a project thought up by one of the adults, which was to make a little database system that could act like a card file or rolodex. They couldn't even come close to programming it. I was very surprised because I "knew" that such a project was well below the mythical "two pages" for end-users we were working within. That night I wrote it out, and the next day I showed all of them how to do it. Still, none of them were able to do it by themselves. Later, I sat in the room pondering the board from my talk. Finally, I counted the number of nonobvious ideas in this little program. They came to 17. And some of them were like the concept of the arch in building design: very hard to discover, if you don't already know them.
Seventeen nonobvious ideas in two pages of code. And this is a language designed for children! What hope does Clojure have of being beginner-friendly?
Alan Kay's conclusion was that programming is hard. It has to be taught like we teach reading---over many years with many examples and lots of guidance. There are a lot of ideas that aren't hard when they are taught, but they are hard to discover on your own. We need to learn them and pass them on to the next generation. Programming is culture.
So when people say it's unfriendly to ask beginners to write the code
above, I agree, but I think the solution is not to wrap it up in a
function and give it to them. I think the solution is to teach them to
do it themselves. That's passing on culture, and in fact that's what
Beginners solve their problem and learn a bit of Clojure at the same
The extra advantage is they are learning something that is useful elsewhere. They're not learning the ins and outs of the options of that particular library. They're learning to use the core library and transform data in a Clojury way. We need to teach the next generation.
Book update 📖
Chapter 6 is out! Buy it now: Grokking Simplicity.
Also, the liveBook is ready for prime time! This means you can preview the content of the book before buying and you can read it online after you buy. Amazing!
You can buy the book and use the coupon code TSSIMPLICITY for 50% off.
A new episode is coming soon. In it, I read Lambda: the Ultimate GOTO by Guy Steele, Jr.
Clojure Challenge 🤔
Last week's challenge
The challenge in Issue 365 was to model a Starbucks coffee. There were no submissions :( I guess modeling problems aren't that fun? Let's try something different.
This week's challenge
Number of hands of poker
Poker users a 52-card deck, where each card is unique. After shuffling, a player gets five random cards. How many different hands are there? Remember, in poker, the order of the cards in your hand does not matter.
Write a function that takes the number of cards in a hand
h and the
number of cards in the deck
d and calculates how many possible hands
(defn combinations [d h] ..... )
Hint: there is a mathematical formula for combinations already!
As usual, please reply to this email and let me know what you tried. I'll collect them up and share them in the next issue. If you don't want me to share your submission, let me know.