I’ve recently had my whole ability as a programmer called into question. What has caused this personal crisis? trying to learn one of the most baffling languages around.

Clojure is a world away from languages like JavaScript, Java or C#. Firstly because it’s a completely functional language. Secondly, because the syntax is well, weird.

To get an idea of what I’m on about. Let's have a look at this simple function to find anagrams.

If you are reading this as someone who already knows Clojure or another LISP dialect. You will probably know exactly what this does, but I hope those who have not done any Clojure or LISP before will agree that this is a little confusing.

For those interested. This function finds anagrams of a word. It does so by taking in a list of all words that exist and a string. It then filters out any words in the dictionary that are not anagrams of the string. If the string is a word in its own right the word is removed from the list (as it can’t be an anagram of itself). The remaining words are anagrams of the string.

The same function in Javascript would look like this:

So to get my head around this new language I need to apply a more structured approach. Thankfully I have one up my sleeve. In this blog, I will describe how to learn any language by writing 3 simple apps.

So What do I need to learn?

Every language has different quirks and speciality things that a new user would want to learn. Even still a generic list of things that cover ‘Language Basics’ can be produced. To my mind these things are.

🗹 How to set up the environment to write code in that language.

🗹 How to assign values to variables.

🗹 How to select between two paths (Usually an ‘if’ statement).

🗹 How to iterate over a block of code.

🗹 How to create and manipulate basic data structures.

🗹 How to create functions/methods or subroutines.

🗹 How to perform basic mathematical calculations (+ — * /)

🗹 How to communicate with the file system.

🗹 How to print to the console/prompt.

🗹 How to write tests

So now we have our list of skills that we would like to learn let’s get learning. I have 3 standard apps that I write that tick all these boxes. Let’s have a look at what they are.

App #1: The ‘Hello World’ app.

The hello world app is the canonical app that developers start with when writing with a new language. It has one acceptance Criteria (AC). The AC is to print the phrase ‘Hello, World!’ to a console. Let’s write that out as an AC list:

AC:

Must print the phrase ‘Hello World!’ to a console or prompt.

Here’s what it looks like.

What is the benefit of this app? The main purpose of this app is to validate you can set up all the tools necessary to develop in your chosen language. you also learn to print to the console too.

Looking back at the checklist defined in the previous section, If you have completed this app you can tick two things off your list!

✅ How to set up the environment to write code in that language.

🗹 How to assign values to variables.

🗹 How to select between two paths (Usually an ‘if’ statement).

🗹 How to iterate over a block of code.

🗹 How to create and manipulate basic data structures.

🗹 How to create functions/methods or subroutines.

🗹 How to perform basic mathematical calculations (+ — * /)

🗹 How to communicate with the file system.

✅How to print to the console/prompt.

🗹 How to write tests

As mentioned previously I’m learning Clojure using this method. You can check out my Clojure implementation on Github for further clarification on the and how to solve it.

So now we know we can get the language running. Let’s get some proper code running.

App #2: The ‘Anagram’ app.

For this application, you should be able to type a string into the command shell e.g. “refresh” and the application should unscramble it into a set of words that are formed with the same letters. In this case, the only result would be ‘fresher’.

Let’s have a look at our AC’s.

AC:

Take a string through the console input

Take in a file with a dictionary of useable words.

Output a list of words to the console that are an anagram of the inputted string

Be Tested!

So after all that let’s see what we can tick off my checklist:

✅ How to set up the environment to write code in that language.

✅ How to assign values to variables.

✅How to select between two paths (Usually an ‘if’ statement).

🗹 How to iterate over a block of code.

✅ How to create and manipulate basic data structures.

✅ How to create functions/methods or subroutines.

🗹 How to perform basic mathematical calculations (+ — * /)

✅ How to communicate with the file system.

✅How to print to the console/prompt.

✅ How to add tests

So we can see that after this app we’ve already covered most features of a language. We create variables to store the word and its anagrams. We need if statements or equivalent to determine if the two words are anagrams. We need data structures to hold the list of anagrams (advanced mode users might try using a trie to load in our dictionary of words). It’s a big app so to keep it tidy it will need functions. The word list will come from the file system. The output will be printed to the console and we need tests to check it will work.

Once again I’ve given this a go and you can find what I’ve done on GitHub.

The next app is the biggest. It will teach us new things but also solidify our understanding of what we’ve done so far.

App #3: The pizza app

Photo by Thomas Tucker on Unsplash

The pizza app is where we bring it all together. The app is designed to emulate a pizza ordering system. Ignore the checkout or a fancy UI (unless you don’t want to) and focus on just printing out a list of pizzas and allowing the user to add them to a basket. Let’s look at that in AC form.

AC:

Prints a list of pizzas on the menu to the console.

User can select a pizza and add to basket.

Basket displays a subtotal.

Basket displays the tax amount (% of your choice).

Here it is in gif form:

The subtotal and tax use maths which is one of our unchecked points. An app like this will need an event loop as well. Looking back at our checklist we can see that we have ticked off every item. You also might find that an app of this size will involve ticking off all the others as well. That’s intentional — It’s called practice.

✅ How to set up the environment to write code in that language.

✅ How to assign values to variables.

✅ How to select between two paths (Usually an ‘if’ statement).

✅ How to iterate over a block of code.

✅ How to create and manipulate basic data structures.

✅ How to create functions/methods or subroutines.

✅ How to perform basic mathematical calculations (+ — * /)

✅ How to communicate with the file system.

✅How to print to the console/prompt.

✅ How to add tests

Once again, you can check out my solution to this problem.

Bringing it all together.

We learn by doing. And now you have no excuses about what apps to write to help you learn. So the only thing left to say is this: What are you going to learn next?