Hobby programmer

Hello,

I’m a bit of a geezer who wants to take up programming as a hobby. I have done tiny bits of python, ruby, and rust. Like barely beyond “Hello World”. I am now looking at Elixir, F#, and Clojure. Basically, trying to find the language I want to settle into too deep dive and learn.

I was wondering if the community thinks Clojure as a very first language is a good idea? And point me to the super beginner friendly learning materials if there are any. I’m fairly technical but not a developer at all.

Thanks for your time.

Tim

10 Likes

Have a look here: Clojure beginner resources · GitHub

2 Likes

I think Clojure is a great first language. Definitely check out the links that @borkdude posted above.

What do you think would be fun for you to do with the language you learn?

Once you know the basics, you’ll probably have the best experience if you pick a project where the outcome is fun for you and then try to use the language you’ve learned to make that. Clojure is general-purpose enough that you can use it for most any kind of project with few exceptions.

If you like math, you can try doing a bunch of the https://projecteuler.net/ problems. This is also nice because you can find other folks’ solutions to the problems and compare your code to theirs. Here’s problems 1-50 as an example: GitHub - mhspradlin/euler-clj: Project Euler problems done in Clojure.

Depending how you learn, you might also consider going through SICP (the “wizard book”). It’s written for Scheme, but the code translates fairly well to Clojure. This is great for giving a good understanding of the fundamentals of writing programs.

1 Like

I’m not 100% sure. But I enjoy playing with CLI apps. So most likely stuff for the command line is where I would start.

Cool, I think cli-matic is supposed to be a good library for writing CLI apps in clojure: GitHub - l3nz/cli-matic: Compact, hands-free [sub]command line parsing library for Clojure.

That should help handle the plumbing of parsing arguments and invoking your function so you can focus on the interesting parts of your program. Or, if the interesting part for you is the parsing of arguments and invoking a function, you can look at it as a reference for how they solved it!

Thanks for the info. @borkdude provided a comprehensive list of resources. Do any of you have a specific suggestion on which one to start with first?

Welcome! It’s not every day we get a celebrity like Tim Apple around here. :wink:

Clojure is definitely a unique choice to start with only since most of the world seems to learn on ALGOL-derived languages (C, Java, etc.). That’s not necessarily a bad thing, and Clojure will help you learn some good coding habits early, but you may find the way most of the world codes a little quirky.

Clojure builds on top of Java (and doesn’t fully cover that foundation), so Java interoperability may be a small stumbling block for you if you don’t know Java, but I wouldn’t call it a major impediment.

The nice thing about Clojure is the ability to code things interactively and get immediate feedback. I think that is one huge advantage for a beginner.

You also might look into Clopad as a super quick way to get started. No need to learn the tooling just to try out some Clojure basics, just run the app and type.

1 Like

I haven’t gone through it myself, but Clojure for the Brave and True is written in an approachable style and I don’t think it assumes any foreknowledge: Foreword | Clojure for the Brave and True

3 Likes

@timapple, I don’t really disagree with anything that’s been said by others, but:

I think that compared to some languages, there can be bit of learning curve for Clojure on the day that you go beyond just typing stuff into a REPL, in order to set up projects and learn what rules to follow so that everything works. But you should be able to follow the recipes you’re given at that point, and things will be OK. I don’t think this should stop you.

There are languages with more helpful error messages than Clojure, but I have no idea how Clojure’s error messages compare to F#'s or Elixir’s. It used to be that Clojure error messages were scary and confusing for newbies, though they contained a lot of information. Now error messages are often normal, helpful, error messages, but sometimes they are cryptic, because the compiler can’t figure out enough to give you useful information. (You can still ask to see the old, scary error message, though, and sometimes that contains the information you need.) I think this situation will improve. However, again, given that you’re a technical person who can at least play around a tiny bit with all of the languages you’ve mentioned, I don’t think this should concern you very much.

Clojure is an enormously fun language, in my opinion. It’s fun because of the way it makes (idiomatic) Clojure programming easy and convenient. It’s a joy to use, much of the time. I don’t feel the way about any other language I’ve programmed in, and I’ve used quite a few.

Of the three languages you mentioned, F# is statically typed, while Elixir (I think) and Clojure are dynamically typed. This is a difference that matters for one’s initial experience with a language. As a rule of thumb, a dynamically typed language is more flexible about how you construct code. As a result, I think a dynamically typed language is easier to learn as a first programming language. Statically typed languages are less flexible, but they force you to avoid certain errors before your program will even run. Some people prefer that for learning–you can decide–because if your program runs, you won’t be surprised by certain errors while the program is running. On the other hand, it means that you can’t try out a program as quickly. With dynamic typing, though you may encounter an error when the program runs that wouldn’t be possible with a statically typed language, you at least got to see the program run and got feedback from whatever it did do right.

(If you like F#, you might want to also look at OCaml, from which F# was derived, but you may have good reasons to prefer F#. I’m sure you know of Scheme already, and presumably decided on Clojure as better for your interests.)

clojure power turtle interactive learning

Took my nephew through this; he liked it. I’d say it works for a complete beginner. Notably, many things are abstracted away (no tooling to install, no project setup, etc.).

1 Like

Or just start with the Clojure CLI and rely on -X to invoke functions so you don’t have to worry about argument parsing at all:

;; src/hello/world.clj
(ns hello.world)

(defn greet [data]
  (println "Hello" (:name data) "!"))

and then:

clojure -X hello.world/greet :name '"Tim Apple"'

See Clojure - Deps and CLI Guide to get the Clojure CLI setup (assuming you’re on macOS/Linux – Windows is a trickier journey).

6 Likes

Actually not that bad. Just get the powershell script and it will generally self install pretty nicely. The only downside is the non-portable string quoting (not a problem if you know about it, or just dump everything into your deps.edn). I have had good success with tools.deps on windows for the last year or so (did some training on datomic back in 2019 that was heavy on using tools.deps, and ran into an obscure problem at one point on windows, but generally speaking stuff just worked). I have yet to integrate the clj command from powershell with emacs though, so still using lein for most development.

Fyi I had occasion to use clj-new recently (sort of a tepid migration from lein) and it just worked. Very nice to see a compatiblity path there.

1 Like

On windows I recommend the Graal port: GitHub - borkdude/deps.clj: A faithful port of the clojure CLI bash script to Clojure. Used as native CLI,

At least for me it always worked better than the official PowerShell script.

I also just fundamentally just like the idea that it’s Clojure all the way down :stuck_out_tongue_closed_eyes:

As for the OP, I don’t think there’s as many “beginner to programming” resources for Clojure than there’d be for other languages like say Python. But I’ve heard from others on the slack say they learned to program with Clojure and didn’t thought it made it any harder for them.

I would second the recommendation for Clopad and writing scripts meant for -X execution using the clojure command is a good way to start. Having a very simple ready to go playground when you start.and not getting.worried about all the tooling and setup and infrastructure really helps for motivation, just start playing with writing code and seeing it run.

You also might have fun trying out: http://quil.info/

I personally learned to program using Processing, and Quil is Processing for Clojure. There’s something really fun about making art with code, it’s rewarding immediately, and its also relatively simple, since most of it is self-contained. So I think it’s a great way to start getting to learn the basics.

1 Like

ClojureBridge has been teaching Clojure to beginners – including complete programming beginners – for years, so you may find their curriculum has some interesting, introduction material there: ClojureBridge/curriculum: Curriculum for the ClojureBridge workshop series. (github.com)

2 Likes

Hello Tim.

I’m also a hobby programmer, although I also program computers in a commercial environment. The two activities are quite different.

My commercial activities involve a little bit of Python, a little bit of C# (the official company language), a fair amount of R, an increasing amount of PowerShell, and a whole lot of Excel/VBA.

My hobby programming is done with one eye to bringing it to the commercial environment. So, I don’t need to write a lot of code but need to show that I know how to build projects, write code, and ultimately deploy the code. I code in Lisp (including Clojure) and Haskell.

What follows is entirely opinionated.

The following would be good choices:

  • Python. Yes, you can do “Hello World” in it, but it is a good choice for CLI programming, and has an amazing depth as a programming language. Perhaps you’ve given up too soon? It can be slow, but you can use fast libraries, and also build in your own code in C++ and Fortran. It comes with a REPL, but you can also use Jupyter for data exploration, etc.
  • Julia. Julia is a language like Python (with REPL and Jupyter), in fact I would say that if you can code Python you can code Julia within a few minutes. Julia can be used for all sorts of programming, but leans towards .linear algebra.
  • Clojure. Clojure is the Lisp version of Java. I like Clojure, but it has a little bit of a learners bump right at the start. At first, nothing will work, but if you persist it will start to make more sense. Clojure has all (?) of the Java libraries available, and is very deep. This would keep you busy for a long time. Clojure seems to be used more for web programming with access to databases, which is what Walmart uses it for. A lot of people use Emacs as an editor, but unless you already know Emacs I would avoid this if you’re just starting out, Clojure will give you enough to think about.
  • Chicken Scheme. Another Lisp, this time Scheme. Chicken Scheme’s USP is that it transpiles to C, and hence compiles to very fast native code. A bit low level for my tastes, but would suit your wishes to write command line code…

To answer your question, yes, I think Clojure would be a good language for you, once you get over the initial learners bump. You may have a preferred editor - on Windows, Visual Studio Code is quite nice.

As far as books go, Clojure for the Brave and True could be considered as an approachable book. It might also be considered as a bit childish? e.g. a program to print “I’m a little teapot”, or a program to bash hobbits. You can read it a bit online for free, and make your own mind up.

You can also join a Clojure programming group, and make it a more social thing.

1 Like

I just want to point out that Python and Julia do not have REPLs in the way that the Clojure community normally defines them.

They have what I would call a command shell, which is a command line application that can be sent commands and evaluate them and print their result.

Generally though, in Clojure, when people talk about the REPL, REPL-driven-development or why REPLs are awesome, they’re not talking about that.

What Clojurists most often mean by REPL is a live integrated inside an application REPL that lets you evaluate and hot-swap every single line of code at will and on-demand all at runtime without ever needing to restart the application, while also being able to inspect the runtime state at will.

A lot of languages have command shells, very few have fully integrated live REPLs in this vein.

I’m not sure if anything would prevent them to have such REPL, but I haven’t heard them having one.

So in Clojure a REPL is almost better thought of as an IDE, they can auto-complete, list variable usage, show documentation, show functions available in a namespace, run tests, and additionally to those common IDE features, they can also hot-swap code forms, evaluate arbitrary code forms, pretty print their result, etc, and this all happens for your program over your actual source files in your editor of choice.

I think the closest thing to relate to it is that it’s very close to the Inspectors inside browsers when you press F12, just more general to any program and running inside an editor instead of inside a browser.

I’d like to think this has improved a lot now that we have the Clojure CLI and tools.deps, but I might be wrong.

I’d say if you want the same simplicity to get started as Python, you should look into Babashka https://book.babashka.org/

In fact I’d say it’s probably a great place to start your journey:

  1. Download the bb binary and put it on your PATH
  2. Run it to get a command shell: bb
  3. Create a file with Clojure code in it and run it with: bb my-file.clj

The other advantage of starting with Babashka is that you won’t need to worry about what library to use to do what, you don’t have a choice :stuck_out_tongue_closed_eyes:, it comes batteries included with its own set of libraries for most things, and that’s all you can use (well when getting more advanced you’ll learn that you can if you really want use more libraries then the included ones, but you won’t reach that point for a while, so don’t worry about it).

And if you’re confused about how learning Babashka is similar to learning Clojure, well it’s because Clojure is the programming language, and Clojure JVM, Clojure CLR, ClojureScript, Babashka are implementations of that language for various runtimes. They all use the same language, which is Clojure.

Since you don’t know programming or Clojure very well yet, I would say understanding the implications and peculiarities of different runtimes isn’t important for you yet. You can learn all the basics of programming and Clojure with Babashka, and worry about the infrastructure and runtime differences once you’ve mastered that.

5 Likes

What Clojurists most often mean by REPL is a live integrated inside an application REPL that lets you evaluate and hot-swap every single line of code at will and on-demand all at runtime without ever needing to restart the application, while also being able to inspect the runtime state at will.

That’s not something that I, or a beginner, can do. This is a pity, since it sounds like a compelling feature.

I use Visual Studio Code. In a PowerShell terminal, I type lein repl and then I get the Leiningen REPL. This doesn’t do the sort of things that you’re talking about.

ClojureREPL

So, that’s my Pythonesque REPL.

I can do something like what you’re suggesting in Common Lisp (SBCL). Take for example, this extremely suspicious code:

(defconstant zero 0)
 
(defun fact (n)
  (if (= n 1)
       (/ 1 zero)
       (* n (fact (- n 1)))))

It’s fairly obvious what it does, it calculates factorials very badly. When you run it, it reaches divide by zero, and goes into the debugger. Whilst in the debugger, I can edit and reload the code. Perhaps I meant 1 rather than (/ 1 zero). I can fix the code at this point, whilst the code is running.

When I code the same(-ish) thing using Clojure / Leiningen, it doesn’t do this:

(defn fact [n]

(if (= n 1)
   (/ 1 0)
   (* n (fact (- n 1)))))

image

How do I do this interactive editing in Clojure, please?

I’d like to think this has improved a lot now that we have the Clojure CLI and tools.deps, but I might be wrong.

Alas, yes. Clojure has improved quite a bit, but out of the box it still does some odd things. Take for example, the classic (1 2 3). It doesn’t give a page of errors, but still throws up an odd result. We both know what it means, but it’s still not beginner friendly.

If you also confuse def with let, and get tangled up in Emacs, the whole thing can get ugly.

1 Like

I’m fairly certain it’s not possible. CL has a condition system, which is basically a bidirectional try/catch mechanism, that no other language has. its REPL makes use of that to do the interactive development. in other languages, when the exception is caught the stack is destroyed. CL doesn’t destroy the stack until after the exception handler finishes, which is what allows it to recover from it.

there’s basically a range of REPLs. Clojure programmers claim the python REPL isn’t truly interactive and CL programmers claim the Clojure one isn’t fully interactive. so, take all the “that’s not a real REPL” talk with a grain of salt. a REPL is a REPL, some just have different features than others. the CL one is probably the top of the food chain because it’s the most interactive, but that doesn’t mean the others aren’t valid or useful.

1 Like

farolero has the beginnings of a condition system with restarts and an ineractive debugger. It’s not commonly integrated, but nothing stops a person from wrapping the default clojure repl. I am curious to see what the limitations are in practice.

I think a couple of these links might help illustrate how to access the Clojure REPL-functionality that @didibus was referring to.

  1. With Atom and Chlorine, this YouTube tutorial series from Between Two Parens is pretty good: How to use a Clojure REPL in Atom - YouTube
  2. For VS Studio and Calva, this intro clip on Calva might come in handy. Getting Started - Calva User Guide

Hope this is helpful! :slight_smile: