All posts by andywootton

About andywootton

A modelling metaphor mixologist

Tooling for Clojure and ClojureScript

[:ChangeLog
(:v0.2
“recognise that ‘resolving dependencies’ and ‘build’ are different operations.”
“Add conversion tools between project.clj & deps.edn”)
(:v0.3
“Remove CLI tools described as a build tool comment.”)]

WARNING
I still have much to learn about ClojureScript tooling but I thought I’d share what (I think) I’ve learned, as I have found it difficult to locate advice for beginners that is still current. This is very incomplete. It may stay that way or I may update it into a living document. I don’t actually have much advice to give and it’s only about the paths that have interested me.

Clojure development requires:

  • a text editor,

and optionally,

  • a REPL, for a dynamic coding environment
  • dependency and build tool(s).

The absolute minimum Clojure environment is a Java .jar file, containing the clojure.main/main entry point, which can be called with the name of your file.clj as a parameter, to read and run your code. I don’t think anyone does that, after they’ve run it once to check it flies.

Based on 2 books, ‘Clojure for the Brave & True’ and ‘Living Clojure’, my chosen tools are emacs for editing, with CIDER connecting a REPL, and Leiningen as dependency & build tool. ‘lein repl’ can also start a REPL.
Boot is available as an alternative to Leiningen but I got the impression it might be a bit too ‘exciting’ for a Clojure noob like me, so I haven’t used it yet.
CIDER provides a client-server link between an editor (I’m learning emacs) and a REPL.

If you use Leiningen, it comes with a free set of assumptions about development directory structure and the expectation that you will create a file, project.cli in the root directory of each ‘project’, containing a :dependencies vector. Then magic happens. If your change the dependencies of your project, the config fairies work out everything else that needs changing.

Next, I wanted to start using ClojureScript (CLJS.) I assumed that the same set of tools would extend. I was wrong to assume.
Unfortunately, CLJS tooling is less standardised and doesn’t seem to have reached such a stable state.

In ‘Living Clojure’, Carin Meier suggests using cljsbuild. It uses the lein-cljsbuild plugin and the command:

lein cljsbuild auto

to start a process which automatically re-compiles whenever a change is saved to the cljs source file. If the generated JavaScript is open in a browser, then the change will be shown in the browser window. This is enough to get you going. It is my current state.

I’ve read that there are other tools such as Figwheel, now transitioning to ‘Figwheel Main’ which hot-load the transcribed code into the browser as you change it.
There is a lein-figwheel as well as a lein-cljsbuild, which at least sounds like a drop-in replacement. I suspect it isn’t that simple.

There are several REPLs, though there seems to be some standardisation around nrepl.
It was part of the Clojure project but now has its own nrepl/nrepl repository on Github. It is used by Clojure, ‘lein repl’ and by CIDER.

There is something called Piggieback which adds CLJS support to NREPL. There is a CIDER Piggieback and an NREPL Piggieback. I have NO IDEA! (yet.)
shadow-cljs exists. Sorry, that’s all I have there too.

At this point in my confusion, a dependency issue killed my tool-chain.
I think one of the config fairies was off sick that day. The fix was a re-install of an emacs module. This forced me to explore possible reasons. I discovered the Clojure ‘Getting Started’ page had changed (or I’d never read it.)
https://clojure.org/guides/getting_started

There are also (now?) ‘Deps and the CLI Tools’ https://clojure.org/guides/deps_and_cli and https://clojure.org/reference/deps_and_cli

I think these are new and I believe they are intended to be the beginners’ entry point into Clojure development, before you dive into the more complex tools. There are CLI commands: ‘clojure’ and a wrapper that provides line-editing, ‘clj’
and a file called ‘deps.edn’ which specifies the dependencies, much as ‘projects.clj’ :depencies vector does for Leiningen but with a different syntax.

I’m less clear if these are also intended as new tools for experts, to be used by ‘higher order’ tools like Leiningen and Figwheel, or whether they will be adopted by those tools.

[ On the day I wrote this, I had a tip from didibus on clojureverse.org that there are plugins for Leiningen and Boot to use an existing deps.edn,

so perhaps this is the coming future standard for specifying & resolving dependencies, while lein and boot continue to provide additional build capabilities. deps.edn refers to Maven. I discovered elsewhere that Maven references existed but were hidden away inside Leiningen. It looks like I need to learn a little about Apache Maven. I didn’t come to Closure via Java but I can see the advantages to Java practitioners of using their standard build tool. I may need to drop down into Java one day, so I guess I may as well learn about Java-land now.

Also via: https://clojureverse.org/t/has-anyone-written-a-tool-to-spit-out-a-deps-edn-from-a-project-clj/2086, there is a https://github.com/hagmonk/depify, which ‘goes the other way’, trying it’s best to convert a project.clj to a deps.edn. Hopefully that would be a ‘one-off’? ]

I chose the Clojure language for its simplicity. The tooling journey has been longer than I expected, so I hope this information cuts some corners for you.

[ Please let me know if I’m wrong about any of this or if there are better, current documents that I should read. ]

Advertisements

A new target for Software Developers: Sensei.

I originally wrote this as an answer to a question on Quora but I’m increasingly concerned at the cost of higher education for young people from families that are not wealthy. I had parents who would have sacrificed anything for my education but I had clever friends who were not so fortunate. The system is bleeding talent into dead-end jobs. Below, I consider other models of training as I hope it might start a conversation in the technology community and the political infrastructure that trickles money down into it.

Through learning about ‘Agile’ software development, I became interested in related ‘Lean’ thinking. It borrows from Japanese cultural ideas and the way the martial arts are taught. I think the idea is that first you do, then you learn and finally you understand (as illustrated by the film ‘Karate Kid’.) That requires a ‘master’ or ‘Sensei’ to guide and react to what s/he sees about each individual’s current practice. It seems a good model for programming too. There may be times when doing is easier if you gain some understanding before you ‘do’ and advice and assistance with problem solving could be part of this. I’m not alone in thinking this way, as I see phrases like “kata” and “koans” appearing around software development.

I’ve also seen several analogies to woodworking craft which suggests that a master-apprentice relationship might be appropriate. There is even a ‘Software Craftsmanship’ movement. This could work as well in agile software development teams, as it did for weavers of mediaeval tapestries.

A female Scrum Master friend assures me that the word “master” is not gendered in either of these contexts. Of course, not all great individual crafts people make good teachers but teams with the best teachers would start to attract the best apprentices.

If any good programmers aren’t sure about spending their valuable developer’s time teaching, I recommend the “fable in novella form” Jonathan Livingston Seagull, written by Richard Bach, about a young seagull that wants to excel at flying.

Small software companies ‘have a lot on’ but how much would they need to be paid to take on an apprentice in their development teams, perhaps with weekly day-release to a local training organisation? I’d expect a sliding scale to employment as they became productive or were rejected back into the cold, hard world if they weren’t making the grade.

Model Software

Today, I had to stop myself writing “solving the problem” about developing software. Why do we say that? Why do software people call any bounded area of reality “the problem domain”?

My change of mind has been fermenting for a while, due to modelling business processes, learning about incremental, agile software development and more recently writing and learning functional programming. In the shower this morning, I finally concluded that I think software is primarily a modelling medium. We solve problems using the models we build.

Wanting to create another first-person shooter game or to model the fluids in a thermo-nuclear reactor are challenges, not problems. We build models of systems we have defined and the systems don’t even have to be real. I read a couple of days ago that a famous modern philosopher said our world is made of both reality and our ideas. Assuming the computer hardware is real, the software can model either reality or our imagination; our chosen narrative.

‘Digital’ gets everyone working with software models instead of reality. Once everyone lives inside the shared model, when does it become our reality?

Or when did it?

Idea-bending minds, mind-bending ideas

Long ago, I took 4/9ths of an undergraduate physics degree, along with 4/9ths computer science and 1/9th mathematics. Having had little or no contact with physics in the intervening years, I’ve started to do some light reading about relativity in the last couple of years. This week, I came across a tip on Quora * to a fellow traveller in space-time: “stop thinking of the speed of light as a number”. Erm… WHAT?! As every school child knows, the maximum  speed of light (or any other form of electromagnetic radiation) in a vacuum is about 600,000 Km/s. That sounds like a number to me. The problem with speed in Einstein’s relativistic model of reality though, is that distance and time get very weird. That makes them hard to think about, so the advice was to ignore what we think we know and look at things in a new way.
[* – I’ll add an acknowledgement to the author of  the comment on Quora, if I ever find it again. It took me a while to understand what I’d read. ]

I’m not sure I was entirely paying attention when I studied physics last time. I don’t remember anyone explaining the precise nature of the the scientific method, or indeed what physics actually is; that’s metaphysics. This time around I see science as the process of understanding how nature works, using evidence rather than guessing then arguing the case for your beliefs. That is philosophy, or a religion. Physics, in particular, is about observing reality and working out what the rules are. It is NOT about saying why things happen. As science was becoming formalised, it was known as ‘natural philosophy’ i.e. philosophy that refers to evidence from nature.

Einstein’s Theories of Relativity say that matter and energy are equivalent. His equation of mass-energy equivalence records the relationship between the alternative mass and energy forms of matter. It is a very well known equation, even with people who have no idea what it refers to.

The form of the equation we are most familiar with is

E = mc²

E is the concentrated energy contained in a mass, m. E is a much bigger number than m because we know that c is a big number AND it’s squared.

This equation can be re-arranged to a form I don’t remember seeing or taking note of before:

c = √(E/m)

This new way (at least to me) of looking at this century old theory says that c is related to the ratio between the Energy and mass of an object. This ratio stays the same, even as space-time expands or contracts, according to the General Theory of Relativity. The recent confirmation by the LIGO project of gravitation waves that also travel at c, were also predicted, so this gives extra weight to the theory

I’ve realised that physics often relates things to each other, without saying which is the ‘fundamental thing’. Does gravity bend space-time or is the curvature of space-time what causes gravity? The equations work either way.

John Archibald Wheeler said it a different way: “Space-time tells matter how to move; matter tells space-time how to curve” and matter can be converted to energy, energy to matter.
Continue reading Idea-bending minds, mind-bending ideas

I’m through the Digital looking-glass

I think I’ve ‘got’ for the first time what the “DIGITAL” thing is.

I’ve been searching to find the meaning of the phrase “digital transformation”, which I assumed encompassed a change from ‘analogue’ to ‘digital’. I finally understood yesterday – that’s not what it’s really about.

The transformation happened slowly to me, over most of my life. My first programming was planned on paper then character boxes were filled-in with a graphite pencil on cards. They were shipped by road to a punch machine that punched the binary codes onto the cards which were then were fed into a computer by operators I never saw. A week later I got some printout back, usually telling me what had gone wrong.

Soon after arriving at university, I had access to GEORGE 3’s Multiple On-line Programming system: a terminal. I used a line editor to create a card-image file which was stored on disk then later submitted to the batch queue. Undergraduates were only allocated space to store one program at a time. There wasn’t room to keep things permanently on-line because of the price of disk space. Some of the research students still walked around with boxes of cards. It was easy to copy a card-stack on one of the card punches and keep it in a safe place. They could probably store more code that way.

I’ve been mostly digital since the 1970s but I saw my digital world as a binary virtualisation of a physical medium. I moved very slowly from dependence on physical to online-only artifacts which had always been representations of digital data.

I realised yesterday that most people have only recently moved their business objects: files, documents, photographs, drawings, 3D-models and social network connection information into the digital realm – from atoms to bits. That frees those objects from their bindings at a single, fixed physical location, leaving them to roam in more than the 3 dimensions of our visualisable reality. This paradigm shift has suddenly hit many without warning, like a revolution, whereas I experienced it as a series of small increments. I’ve been greatly underestimating how disorienting it has been for other industries to reluctantly release their tight grip on physical objects and how worrying it may be for those still facing the cultural adjustment.

I remembered the other day that I used to jump off a shed roof at 5 years old. I could see the spot where I would land. I can’t imagine throwing myself out of a plane into free-fall and that’s why there are ‘digital coaches’. My empathy has been retrieved from an old backup tape. I’m sorry if my lack of understanding ever inconvenienced anyone.

The functional Pi Racket

I have a love/hate relationship with Clojure tooling.

I wanted to learn functional programming (FP) in a Lisp because:
1. There’s a thing I want to do and it felt like the right way to do it
N.B. ‘right’ is not always ‘easiest’
2. Lisp once beat me up quite badly. I’m bigger now. I wanted to go back and punch it on the nose
3. I won’t really ‘get’ immutability until I do some, with no option to cheat.
3. I find homoiconic functional programming conceptually elegant…

…then you try using the Clojure development environment and discover there isn’t one that everyone agrees on and the one used by expert requires you to learn a new language of keyboard hieroglyphs first.

I’ve done just enough Lisping to think that we are being as irresponsible teaching kids only object oriented programming as the BBC were in teaching them BASIC, but it would be actual child abuse to introduce them to FP via emacs and a language dependent on the underlying Object-Oriented Java Virtual Machine for it’s connection to libraries & reality.

This morning I realised I hadn’t plugged my Raspberry Pi in for ages. If you were a child who started coding with Scratch and a few drum loops on Sonic Pi then maybe a bit of the Squeak Smalltalk (Scratch is written in Squeak) or Python in a nice IDE, imagine being handed the ancient emacs scrolls and sent into a corner for a week to learn spells, before you could even start to learn to function. FP is going to initially make soup of your flabby imperative, ‘place is state’-damaged brain anyway. There is no need to make it harder. Teaching languages don’t have to train you for a job, only to think.

If we are going to raise functional children, we need a gentle slope up to Clojure. Clojure is probably the best practical language but it’s too hard. I’ve seen a few people suggest starting with Racket, which is a version of the Scheme Lisp dialect. This morning I poured DrRacket onto my Pi.

There was a minor hiccup with DrRacket not knowing what language I wanted it to read. Kids would need to be protected from that. I wanted “Determine language from source”, not to tell it I was a ‘beginning student’.

Because DrRacket is multi-lingual, the first line of the source code tells it what language to read:
#lang racket

You type in code then press the run button. This is not your grandfathers emacs REPL. Children should have no natural fear of their (parens). Ooh look, cats!

#lang racket

(define (extract str)
(substring str 4 8))

(extract “the cats out of the bag”)

;;-> “cats”

Relative re-energising in 2018

I read the instructions on my microwav(abl)e lunch: “800W for 4 minutes”. I wondered if that was input or output power. If microwaves got more efficient, would there be an increase in burned food? I needn’t have worried. Our microwave is 1200W in, 800W out but is that Root Mean Square, like a guitar amp? That’s how to blow up 100W speakers with 50W valve amps. They’re Peaky Bosters, like that Cillian Murphy’s accent in Series 1. Should I worry whether my risotto rice will assplode at 3:2 efficiency.

“Why would They label things relative to an obsolete technical standard?”, you might ask, if you’d never seen a modern 11W, 50W-equivalent(ish) light-bulb. You’d think ‘They’d at least have introduced a light-output based standard. There is a standard: ‘Lumens’ (total) and/or ‘Lux’ (intensity.) That’s an adventure for another day.

How many Horse-Power is your car; what size of horse; and how frisky is it feeling? I took a photo of a horse once, using an Digital Single Lens Reflex with a zoom lens that was specified by a foal length in Millimeters equivalent to a 50mm lens on a 35mm diameter camera with a slightly different frame width:height ratio. There are no sprocket holes on the digital either.

I’m trying out dropping ‘title-case’ in blog post titles. I didn’t even know what it was until a week ago. Unnecessary upper-case letters in titles appear to upset the design sensitivity of the font-folk. They have other ways of emphasising and I prefer not to offend people’s aesthetic until I mean to. I was persuaded to conform because the convention scrambles structure, content and style, while over-loading capital letters.