Beginner's advice, Is Clojure the right place to start/Continue the programming journey?


#1

Hi everybody,

How are you?

First of all, I would like to thank everybody on the Clojure community answering almost all my questions. You’re the best!!!

As you know, Clojure doesn’t have a lot of new learning resources and I am willing to do the work, but I will need a lot of help!!

I can understand most of Java, C#, JS code, OOP, but I never did any project, just saw tons of video tutorials. I just love programming and see technology tutorials, talk, etc…
You could say, I am a enthusiast that wants to build real projects by myself.

I would like to start building a website with adm/blog/gallery/contact form/products page/search basic stuff.

It is easy to find whole websites like this in form of tutorials in spring boot/asp.net core/node.js/express.

Several examples…

But I really liked Clojure…

So I really don’t know what to do…

What would be your advice for me?

Thanks.


#2

I would say the best place to start is:

  • Using duct, and write your application server side in Clojure only. Do not touch ClojureScript yet.
  • If you needed at some point to write separate application services, I would use Pedestal.

But, I’ll even suggest something completely different and unorthodox. Use a Java framework, and add some Clojure to it. One of:

For each Java controller, have a similar Clojure controller, and in the Java controller, just call into the Clojure one.

For example, in Spring MVC:

Inside SomeJavaController.java:

      ModelAndView mv = new ModelAndView("someView.jsp");
      IFn someClojureController = Clojure.var("namespace.to.your.clojure.controllers.some-clojure-controller", "render-page");
      mv.addObject("clojure", someClojureController.invoke(requestParam1, requestParam2, ...));
      return mv;

For each JSP page, just have the JSP template be: ${clojure}. And Now in your Clojure controller, return the full HTML, and have the Java controller just send the full HTML returned by the Clojure controller onto the model as clojure.

Inside someView.jsp:

${clojure}

Now in your Clojure controller, I recommend you use Hiccup for HTML templating. Here’s hello world:

Inside some-clojure-controller.clj:

(ns namespace.to.your.clojure.controllers.some-clojure-controller
  (:require [hiccup.core :as hc]
            [hiccup.def :as hd]
            [hiccup.element :as he]
            [hiccup.form :as hf]
            [hiccup.page :as hp]
            [hiccup.util :as hu])

(hd/defhtml hello-world-page
  [first-name last-name]
  (hp/html5
    [:head [:title "A Clojure Spring MVC Hello World!"]]
    [:body
      [:p "Hello " first-name ", " last-name "!"]]))

(defn render-page
  [request-param1 request-param2 ...]
  ;; This assumes request-param1 and 2 were first and last names.
  (hello-world-page request-param1 request-param2)

That said, since you are just starting, I might even just use JSP for now as your template language. When you call your Clojure controller namespace from the Java controller, just pass it the model, and have it return the model. And template your HTML using JSP. As such:

Inside SomeJavaController.java:

      ModelAndView mv = new ModelAndView("someView.jsp");
      IFn someClojureController = Clojure.var("namespace.to.your.clojure.controllers.some-clojure-controller", "render-page");
      return someClojureController.invoke(mv, requestParam1, requestParam2, ...);

Inside some-clojure-controller.clj:

(ns namespace.to.your.clojure.controllers.some-clojure-controller)

(defn render-page
  [mv request-param1 request-param2 ...]
  ;; This assumes request-param1 and 2 were first and last names.
  (doto mv
    (.addObject "first-name" request-param1)
    (.addObject "last-name" request-param2)))

Inside someView.jsp:

<!DOCTYPE html">
<html>
  <head>
    <title>A Clojure Hello World, using JSP for the templating.</title>
  </head>
  <body>
    <p>Hello ${first-name}, ${last-name}!</p>
  </body>
</html>

The advantage of this approach is that Spring MVC and Apache Struts are very well documented, compared to Clojure frameworks. They are also very simple, old, tested, proven frameworks, with no fancy bells and whistles. A good overall place to start.

The choice is yours.

P.S.: Shout out to coast as well. It can also be a good place to start for a beginner, has good-ish docs, though it’s quite new (maybe incomplete in some aspects?).


#3

I also recommend putting ClojureScript aside for now. It’s not that it’s harder per-se, but arguably it’s one of the most complex spaces to be in, especially as a beginner. Not only do you need to be familiar with Clojure (and therefore probably Java/JVM), but also JavaScript, Node/Browser differences, Clojure/Script differences and some vague idea about what’s going on when compiling CLJS, as well as understanding „the web“ in general.

If you‘re at the point where building a MVC-ish server application in Clojure is simple to you, and you know a bit of Javascript already, I think Clojurescript becommes the most sane choice, and not too hard to learn.


#4

Seconded learning ClojureScript and full stack developing after having written a server or two. I tried walking the ClojureScript route several times, and spent much time on getting browser live-reload and a browser REPL up and running. Clojure, in contrast, was way easier to get started with. And poking at a running Clojure process from the REPL is pure joy.


#5

@ecsmix,

From my experience, the primary advantage of Clojure is having the REPL; being able to act directly upon your application. Secondary is that Clojure’s other features (which are nice in themselves) support REPL usage. Therefore,

Get an editor setup with a good REPL, and start using that to learn further. Being proficient with your editor REPL is going to speed up your learning speed for anything else.

In general, I learn Clojure stuff this way:

  1. See some code I don’t understand
  2. Fire up a local REPL and run it
  3. Run only parts of the thing, to see how the parts interact
  4. Read (doc strange-new-function) to see what arguments are expected
  5. Put the new stuff into practice!

The flipside of the REPL is the flexibility of Clojure. The REPL works best with pure data, because that can be seen, explored and interacted with. Clojure’s flexibility allows you to build the applications you want on a data foundation. I find that to yield quite powerful architectures. You can for example generate that data. And then you have a data abstraction for your problem, which means you can pass the data in any way you like.

As you progress, model your applications as data. See where that takes you!

If you want a concrete resource, try out Clojure for the brave and true. That’s going to take you through some nice problems and show you good solutions and approaches.


#6

There are a number of good books in addition to Clojure for the Brave and True, though I know that that book is often recommended, and it has a cost advantage. I think that that Carin Meyer’s Living Clojure looks like a good starting point, although I haven’t used it. Programming Clojure by Alex Miller, Stuart Halloway, and Aaron Bedra should be pretty good if you are coming from OOP, and maybe know a little Java. I started with the previous edition of that. Miller is one of the main Clojure developers. I’m sure some of the other books oriented toward people who already know OOP and Java are also good. I’ve found Clojure Programming by Emerick et al. extremely helpful on a number of more advanced issues. It also has introductory material that looks pretty good, but I haven’t actually used the introductory parts because I had been using Clojure for a while when I got this book. (I find this book more helpful on the deep stuff than The Joy of Clojure, which is widely cited as a good intermediate-to-advanced book, and which is certainly useful on some topics.)


#7

Hi guys, thanks for all recommendations, keep them coming…

I have several pdfs books on Clojure and some video tutorials.

I saw some already and I got repl with Intellij and cursive kind of working on windows 10.

However, it doesn’t have a lot of examples in Clojure doing web apps, connecting to graphql, react without closurescript/angular/vue, doing simple stuff.

Aren’t those books outdated for 1.9 clojure and some libs used?
Like this one:
https://pragprog.com/book/dswdcloj2/web-development-with-clojure-second-edition

Thanks again.


#8

Also consider Luminus. It has some guide for building a guest book application which may be a good start.

Also newer versions use the reitit routing library which puts a lot of focus on good error messages and documentation.


#9

I would not hesitate to recommend Web Development with Clojure. I read the second edition a few months ago, and it really helped me get a handle on what you need for web development, and how Clojure provides solutions to that. It’s written by the author of Luminus, but not really tied to Luminus or a specific version. The Luminus docs are also really good.


#10

What you get if you use a published book from a good publisher is an educational tool that has been chosen by editors as worth publishing, where the editors, authors, and internal reviewers have worked together to refine the original work of the authors into better educational tool. In addition, a good publisher will take care to produce a work whose formatting is good for its purposes. Finally, the fact that the authors and publishers make a bit of profit provides additional motivation to them to produce a product that readers will find helpful. (And if they do a good job, they deserve to get paid if the pricing is reasonable.) That doesn’t mean the result of the publishing process is ever perfect, and there are of course some completely free works that don’t come from a publishing house that are also good. However, I feel that the process that produces a published book is more reliable, on average. (This isn’t true for all publishers. I don’t consider Packt a reliable publisher, for example, although I think that some of their books are useful. They have a very low-budget editorial process, afaics.)

The process of curating and refining takes time, so there will always be a time lag given that languages and libraries are changing. Even a book that was just published will be a little bit out of date if there have been recent releases of the language or libraries discussed in the book.

So there’s a tradeoff. The more up-to-date you want your learning resource to be, the fewer options you have. The more you want to be able to trust that you are getting an effective learning resource, the more you may have to put up with out of date bits here and there.

When I’m starting out learning something, I usually like to find a good learning resource–a good published book, usually–and then I supplement it with whatever stuff I can find on the web that will update what’s in the book. On the other hand, if what I want to learn is something that is close to what I already know well, I might just go for whatever I can find on the web. This all comes down to personal choice, though, and cost can play a role.


#11

I’m not sure I understand the question here. You mean you only found examples for complicated things, like using graphQL, ClojureScript, Angular, Vue, etc. ? And you want simpler examples?


#12

Hi,
What I meant that is easier to follow along a video tutorial and other languages have more tutorials, even using newer technologies like Graphql, Next.js, SSR with Clojure with angular or react, etc…


#13

I’m making no promise, since I’m pretty busy. But if you send me an example free video for another programming language, if I ever have some free time, maybe I could see if I can reproduce a similar one for Clojure.


#14

That would be amazing, and I would like to help, edit, master the audio and publish on youtube, so we can demonstrate the benefits of using Clojure.

The websites are Pluralsight, Lynda, Udemy.

If you go on youtube, there are several examples on Java, Spring, C# .Net Core, Node.js, Go, etc…

My main goal would be creating a simple web site with some features like blog, adm part, contact form, gallery, shopping cart, security, SEO, Server side rendering.

Using React, Postgresql or Mysql, Graphql, Next.js.

I know it’s a lot of work…


#15

Hi everybody,

I read something today here on the forum that made me happy and I would like to understand more about it. I already send a message to the person who posted.

I would like to understand more about this and I read something like that about Clojure as well.
Like so, for some reason you don’t to spend as much time learning Clojure as other languages because it is small, simple and as powerful??

Specially this part:

[quote]
I found myself constantly struggling to compose functionality around those, stuff that struck me as very trivial with a plain request map from Ring. From that point on, I discovered that there wasn’t actually much to learn to get from Clojure beginner to intermediate – there were years and years to unlearn . After getting basically all of the PHP world stuff “out of my system” I could start to learn new/higher concepts that weren’t even on my radar before (SCIP etc.).[/quote]

In another words, Clojure with Ring, Composure offered the same features as Laravel, I meant all the features, am I right to conclude that?

Thanks.


#16

Hey @ecsmix, a few points:

  • First off, there’s no true equivalent for Laravel, Rails, Spring, … (you can use Spring via Java from Clojure, of course, but I’d recommend staying away from it). There are many reasons for this, and lots of discussions have been had about (web) frameworks in Clojure. I suppose a simple summary would be that a server/server application in Clojure is much more akin to a JavaScript Express app than any other traditional MVC framework, you pick your own stack of libraries and retain flexibility (but you have to deal with added complexity)
  • I used Ring as an example for the kind of “unlearning” one can expect to do when going the route I went . It is in no way anywhere close to the feature set of a full web framework, since it’s just a layer of indirection over HTTP, but there is overlap. Modern PHP frameworks bring in a lot of code and classes for managing and interacting with HTTP requests/responses, their parameters and all the parsing and coercing that’s particular to HTTP requests. Back when I was doing PHP, there was a lot of churn in this area, and I had to learn all those pesky “fluent APIs” to build up or query objects (see https://www.php-fig.org/psr/psr-7, and compare with Ring’s way of simply giving you a hash map because you already have Clojure)
  • Time-wise, it’s a little more nuanced, and very much depends on where you’re coming from, and where you’re going to. I probably didn’t express this properly in the comment you quoted, too. Personally, I took a long, long time getting productive in Clojure (I could only learn it in my free time, I had a strong OO/imperative background and opinions, learning resources weren’t as good as they’re now, I chose to learn Clojure, the JVM, ClojureScript, and Emacs all at once, which was idiotic), but that isn’t representative of anything. I’ve been reading and hearing a lot lately about new Clojure developers getting ready for production in timespans of three months or so, which should be perfectly possible with some guidance and the material and tools available today
  • As to “framework features”, or what you’ll be able to achieve, the story is different from traditional frameworks as well. After having written backends in both PHP and Clojure, it’s my professional opinion that you’ll have to be an intermediate to advanced Clojure developer to be able to fully replicate e.g. Laravel’s functionality/features with your own choice of libraries. That being said, even as a beginner in Clojure the work is much more “sane”, with extremely transparent feedback loops due to the REPL workflow, and the better you get, the more you can leverage the power and flexibility of the ecosystem.
  • There are, however, close matches for “framework” in the Clojure ecosystem. Luminus, Coast and Duct, I think have been mentioned all over the place, and are amazing projects to get started with. Those take a lot of boilerplate out of your hand (which is a big part of any framework, anyway) and make it easy/easier to accomplish common web application related tasks, but they come at the price of making a lot of choices for you without you necessarily knowing why, or how they really work. Managing glue/boilerplate code, alas, is mostly on you, although modular approaches to application architecture help (see Duct’s way of going about it).

In the end, the choice is yours. There’s no forbidden route (pun intended), and depending on where you want to be next year, or in 5 years, a lot to consider.

For example, if you want to get started writing backends in Clojure, with the possibility of “full stack” with ClojureScript later, picking a leiningen template like Luminus and working to understand it is probably your best bet.

Or, if you’re only really interested in frontend development, have some experience with other languages/frameworks, and would like to develop a single page application with ClojureScript, just spin up a Laravel/Express/whatever-you’re-familiar-with backend and use shadow-cljs in a standalone project to develop the client.

I hope this clears up my comment a bit. All of this very much pertains to the web, for any other kind of development using Clojure/Script (or even the .NET version), like ML/AI, graphics, games, desktop/mobile, and so on (all of which are possible with Clojure, but not really with PHP or something), I’m not the person to ask. I’m sure if you elaborate on where you are now, and where you want to be eventually, the community here and on Slack can make more concrete suggestions :slight_smile:


#17

And this may not be the answer that you want to hear, but I think it is an important one: It really doesn’t matter what language or frameworks you use, not in any meaningful or long-lasting way. The real key is to stop watching videos and reading books, and start actually building things. You need to have something you want to do, that will motivate you to get past all the frustration and confusion of actually building it. Creating working systems, just like writing good books, is really hard work, and there are many roadblocks along the way. The only way anyone has ever gotten any good at it is to write a lot of things, and not be ashamed of the fact that the first ones turned out not very good.


#18

Amazing…that’s why is so hard to leave Clojure with a community like you guys.

Thank you so much!!!

Where I am. well, I am a enthusiast, love to see video tutorials on different languages, saw a ton of them, since the beginning of rails…I know some Java, C#, OOP, JS.

All I can say is that I love to be able to built things, to fully understand how everything works and connects…

Thanks!!


#19

You’re right…need to decide which road(tech) to choose.


#20

I think if you’re not sure which road to start with. And your goal is to learn. I would start with only ring and compojure.

When you run lein new compojure, you’ll get a very basic setup, using ring-server as your web server, ring to manage http requests/responses, and compojure to route URLs to your desired back-end logic. It’ll also set you up with ring-defaults which will deal with setting up your middleware handling chain in the beginning to sane defaults that just work and are better then what you could come up with yourself for a while.

This is both the easiest road to get started, as well as the best approach in my opinion for you to learn the “Clojure way” of web development.

I would also add Hiccup right away.

Just with Ring, Compojure, and Hiccup you should be able to build a complete web app. You could build a whole blog with only that!

Honestly, stop “looking”. Just install Leiningen and run lein new compojure <my-learning-project-name> Edit the project.clj file to add [hiccup "1.0.5"] as a dependency. And GET GOING!

As you go along from there, working on your blog, ask questions when you get stuck. It is better for you to discover the “missing pieces” as well. I’m not joking by the way when I say you don’t need anything else but those three libraries to implement a full blog. That said, for some parts of it, you could lean on additional libraries to make your life easier, but it is best for you to discover these as you go. See what is painful, and only then, see if a library can help you make it less painful, don’t anticipate these.

Most of those “tech” from those other languages, I’m not going to lie, they’re snake oil. It’s all mostly buzz word. Over engineered, showcased like it revolutionizes web development, yet its just a big mix of old ideas often made more complicated then they actually are. My point with this, don’t get distracted by them. That’s what they’re good for, distracting you from actually learning and building real things :stuck_out_tongue:.

Even in the Clojure world, a lot of the “fancy” stuff is just distraction. Go with Ring, Compojure and Hiccup. Let’s call it the “Simple Stack”. Its not that the other things are worthless, but they’re not necessary. Starting with some of the other things is like buying the most expensive pro-level bike at the 10k range, when you don’t even know how to ride one, and barely have the leg power to walk up a hill :smile: .

P.S.: Why am I changing my recommendation from my other post? Because at first I assumed you had good prior knowledge of a web framework in another language, and web development fundamentals. Without that, Ring, Compojure + Hiccup is the way to go 100%.

It would really help if you could link me one of your fav video from YouTube, for anyone of these. Which isn’t too long (I wouldn’t have the time to ever put something longer then one hour or two). So 1h or 2h long. That way I could see to reproduce an identical one, with similar content and format, but for Clojure specifically.

Regards!