Clojure Tip 💡
Re-implement your code multiple times
One of the best ways to get good at the idiom-level coding is to re-implement the same function multiple times. Implement it once, and get it working. Then have fun and try to implement it a different way. Try to do it without let-bound variables. Then try it with only built-in functions. Try it in point-free style (using
comp). What does it look like if you change the order of arguments.
Each of these constraints will force you to come up with creative solutions. Your brain is taxed and you get better. Over time, you’ll find that your expressivity with the code is much better. Your first attempt will be better than before. It’s a great way to get better.
I talk about this is a recent episode of my podcast.
Clojure Media 🍿
I recently updated an old install guide for Clojure. I dusted off VirtualBox and tried out every single command on a brand new install of all three of the main operating systems. I’d love to keep this up to date and add more troubleshooting tips. If you have any trouble installing Clojure, please let me know.
Currently recording 🎥
I am now recording a course called Property-Based Testing with test.check. Property-based testing (PBT) is a powerful tool for generating tests instead of writing them. You’ll love the way PBT makes you think about your system. And you can buy it now in Early Access. Of course, PF.tv members have had access since the beginning, along with all of the other courses.
I’m excited about these three new lessons (over 60 minutes of video). The question I’ve heard most consistently about PBT is how to come up with properties. The examples people give are too simplistic. This is an important skill to employ, and I never wanted anyone who took my course to feel like they didn’t have a toolbox of options.
These three new lessons are just the start. They each look at different ways to come up with good properties. Here are the new lessons this week:
- Strategies for properties: functionality, in which we take the direct approach and test that the function does the work it is meant to do.
- Strategies for properties: invariants, in which we learn that sometimes it is easier to test what shouldn’t change.
- Strategies for properties: algebraic properties, in which we see how algebraic properties can help us come up with properties.
There are three more lessons about creating properties.
I’ve made the first and fifth lessons free to watch. Go check them out.
Members already have access to the lessons. The Early Access Program is open. If you buy now, you will get the already published material and everything else that comes out at a serious discount. There are already 5 hours of video, and looking at my plan, this one might be 9-10 hours. But that’s just an estimate. It could be more or less. The uncertainty about it is why there’s such a discount for the Early Access Program.
Clojure Challenge 🤔
Last week’s challenge
The puzzle in Issue 337 was to implement Soundex.
You can check the submissions out here.
This week’s challenge
Derivative of a function
In Calculus class, I learned two forms for the derivative. The first was the Limit definition. The other was a symbolic method, which used many identities that you had to learn to be able to find the derivative.
Here is the limit definition of the derivative:
For this challenge, define a function
deriv that takes a function and returns the derivative of that function, using the limit definition. You can use any very small value for
h, or perhaps provide it as an optional argument.
This exercise is taken from SICP Chapter 1, Section 3.4.
As usual, please send me your answers. I’ll share them all in next week’s issue. If you send me one, but you don’t want me to share it publicly, please let me know.