Getting people started with Clojure?

I’m currently the only person slinging Clojure in a mostly .NET (C#, to be more precise) shop. I’ve proposed to do a short (~90min) intro session to functional programming in Clojure, with optionally further, more hands-on sessions down the line.

The idea for this session is to give them a high-level overview of what FP is, and how to approach problems in a functional manner, as well as providing concrete examples of these ideas in Clojure (and how we use the REPL, modeling data, etc.). If they “take the bait”, I plan on doing some more sessions maybe with some advent of code problems, and a toy web service later on.

Given that I got a very enthusiastic response, I’d like to make the most of the opportunity. I have some ideas of how to organize the session, but I’d really appreciate any suggestions you guys might have.

1 Like

Babashka is an easy way to try out some Clojure without installing any additional tooling. This may or may not be helpful in some parts of your workshop series.

You can write some snippets of Clojure in a file and then execute it instantly from your command line.

It also comes with a web-server built-in so it could be a nice way to learn about Ring as well. It currently doesn’t have a routing library so you would have to build your web-app from the ground up by dispatching on the request map.

It might not be suited for everything you want to cover due to lower performance.

2 Likes

Actually, it’s a good idea to also show that clojure can be used for scripting… I have a few simple bb scripts that could fit the bill. Thanks!

Yeah, you could emphasize the idea that Clojure is a simple language that you can re-use in many environments: ClojureCLR/Magic (might appeal to them as C# programmers, although I do not know what is the state of that), JVM, ClojureScript (browser / node), scripting. Learn once, use anywhere.

1 Like

I have a repository with self contained examples showing babashka for web-apps:

It provides a babashka-fork MS-Windows binary that has reitit routing.

The intention of the Readme.md is to get a newcomer started without additional help.

2 Likes

I highly recommend talks from Rafal Dittwald for some inspiration on introducing FP concepts

I’ve also put together a list of beginner resources my team uses for onboarding that might be of help

https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f

4 Likes

I recently gave a workshop on functional programming and used a video from Rafal Dittwald as well :smiley:

Most people know javascript at least a bit. In this talk the principles and differences between Imperative, OO and Functional style are shown with a code refactoring example (in javascript) foremost with regards to handling state (Minute 7:51 - 28:22, 39:31 - 54:34).

@mvarela The workshop I gave was more about functional Programming in javascript and not in clojure, but maybe the structure could be of some help to you.
My principle was lead my coworkers from the know to the unknown and then show how a problem can be solved with the newly received knowledge.

I started with a comparison of imperative style vs functional style with list operations. Most (hopefully all) programmers should be familiar with the functions map, filter and reduce. I showed how you would map and filter in an imperative style: Everyone can see the verbosity and code duplication; Then I showed it using the map and filter function (concepts one can explain here: higher-order fns, fns as values, so-called lambdas). Then I explained reduce and that one can solve mostly any list-traversing task using reduce.

Then I talked about pure Functions, and had 8 functions prepared and asked for every fn what do you think: Is this a pure Function? That got us talking and thinking about side-effect, referential transparency and mutable state. Then I asked what benefits pure functions have over impure ones and described further benefits, which did not come up in the discussion.

This led to the next topic: Immutable Data Structures. Here I talked about, how to achieve immutable-ish datastructure in javascript (this might be a good time for you to praise clojures data structures :smiley:)

This led to the next question: How to work conveniently with immutable datastructures?
I explained how to compose fns with pipe, compose or juxt. How to use currying and point free style (if the talk was more about clojure I would have talked about partial application and the threading macro) and showed how to use those fns for an elegant solution to a practical problem.

Then I talked about functional architecture and showed some picture from the talk I mentioned from Rafal Dittwald. My idea was to gave them first the tools to solve small problems with functional style and then to show how those practices add up to a clean functional architcture.

5 Likes

Thanks, @Yogthos and @tiku!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.