386 points · by simonpure · 6y ago · 291 comments
1. Tooling. You end up spending way more time getting your tooling setup than it should be. 2. Difficulty in learning. 3. Clear best practices and frameworks. The philosophy of composing libraries is extremely powerful, but to gain broader adoption you still need straight forward frameworks and opinionated best practices.
The last point has many unintuitive consequences. Clojure tends to attract people who enjoy doing new things, or excelling in their craft. But mass adoption also means catering to people who need to do "boring" things where people just want to get their job done. For boring code, which is the reality for many developers, they just want a clear best practice to get the stuff done.
This could be a clear standard library or framework for a task, a clear architectural pattern, and it certainly means easy to access code snippets. There have been some attempts at these things, e.g. Luminous for the web, but the community hasn't rallied around them with enough weight to make newcomers comfortable.
So when faced with choosing: a testing library, any number of libraries compose into a web service, any number of approaches to client side, then in the end still having 100 equally good ways to architect a given piece of code that requires thinking mathematically, well, it's daunting. Especially when you are new to the language and just want to get your boring CRUD app working.
Maybe this is best summed up as saying that Clojure caters to the creative, but to gain widespread adoption it also needs to cater to those stuck writing boring code and just want to be done with it as fast as possible.
In 2017 a customer wanted a set of services written in Clojure. Based on their Java experience they wanted to hire 10 devs. When I arrived they had 4, over the 1.5-year period I was there, they hired and fired 4. When I left they had 3. All 3 were not experienced in Clojure prior to the project (Java), but by 2018 each knew the entire codebase and was able to modify it and able to step in for each other. They spent less than half of their budget and all goals were met ahead of schedule.
IME learning how to put Clojure and its ecosystem in good use takes more time and effort than other languages, but its effectiveness really compensates.
If I could make my own language and stack, I too would be mega-productive. However, others likely wouldn't like it and be confused by it, even though it's dirt obvious to me. Roll-your-own has limits. Sometimes 2 or 3 like-minded Lisp developers connect and roll for a while, but over time they will find it a lucky match-up that the real-world can't repeatedly recreate. Lightning in a bottle evaporates easily.
The bottleneck of "paycheck" programming productivity is communicating between human beings, who may shift over time. Cranking out compact code fast is secondary to this. Program for people, not machines and not cleverness graders.
Cyc is developed by a team since the early 80s. Reduce since the mid 70s. The SBCL and CMUCL Lisp implementations come out of the early 80s. Maxima has its roots in the late 60s/early 70s. The commercial Lisp systems from Franz and LispWorks are developed since the mid/end 80s. ACL2 (a theorem prover used in the chip business) comes from the early 90s. ITA (now Google) started mid 90s. GNU Emacs is from the early 80s. Autocd/Autolisp comes from the early 80s. PTC's Lisp-based CAD system (with a few million lines of Lisp code) must have been originally 2000 or earlier...
Their code was never touched by those who stayed and were able to work together. Later it was rewritten, because in spite of tons of unit tests (which passed), it was full of bugs. The code was considered "write-only". The rewrites averaged at 5-10% LOC.
I agree there's a sometimes frustrating lack of branding and documentation for the one true way of doing things
But I'd be careful what you wish for, Clojure is still fertile land, nothing has come along and crushed all alternatives yet and I think our community is right to think long and hard before promoting the new one true way because most of us are refugees from other languages where it's already happened
On the other hand, to start with just picking something reasonably mainstream (in Clojure terms) is a perfectly good strategy. The choice will be poorly informed, but that's a given if you're a beginner in any case. And such a beginner isn't really in a place anyway to make this choice for a significant project (for any platform/language).
Once an initial choice is made, it seems to me (so far) pretty easy with leinigen templates & plugins just to get started on something. Time from tool setup to coding hasn't been any longer for me than other things I've learned in recent years.
The leaky abstractions were the other painful part – Clojure itself wasn't so bad, but Clojurescript (which would sidestep the startup issue) always seemed to leave me in callback hell.
Ultimately rust (and go to some extent) seemed to fit my use cases better.
If I had to do a web app from scratch I would think long and hard about going Clojure if only because it leverages such a widely used VM. Points 1 & 2 weren't issues for me, but #3 was (and there are similar problems with Elixir).
Building CLI tools in C/C++ is silly. If you like Rust/Go, sure, knock yourself out.
But the obvious choices are the scripting languages with runtimes that are already distributed as part of the OS .On Linux most CLI tools are built in Python or Perl and Ruby or Node.js are decent choices too.
JVM languages aren't an ideal choice due to the startup time, but given the size of the ecosystem you can find a library for pretty much anything you need and now we've got GraalVM to help with the startup time. So not a bad choice either.
I made a couple of simple command line programs at my previous workplace and the functional style of Clojure combined with lazy sequences made processing an unknown amount of resources on our server a breeze.
I would think that the language of choice for a command line program would have more to do with the task you need the program for and not the command line format itself.
Obviously for performance critical stuff such as implementing something like ffmpeg you would want to use rust to squeeze out every last bit of performance.
1. you get all JVM libraries (eg JDBC) 2. it's very compact to write and maintain 3. you can develop stuff using a REPL, and this is very handy for ill-defined problems. 4. if the result is worth it, I can create a Graal native for it (but I hardly ever use this)
I ended up as an author of a thing to minimize the boilerplate involved: https://github.com/l3nz/cli-matic
- Babashka: https://github.com/borkdude/babashka
- Clj-kondo: https://github.com/borkdude/clj-kondo
- Sci: https://github.com/borkdude/sci
- Jet: https://github.com/borkdude/jet
But again, those are tools (especially babashka) from a Clojurist's perspective
In ClojureScript you can use core.async to write async code in straight-line form. But I find myself using it pretty seldom, as handling events explicitly in functions feels pretty natural in Clojure especially given how naturally closures work in the language.
Case in point the var/agent/ref system is fantastic and probably critical to how to think about Clojure projects - but the problems being solved by it are a long way away from the concerns of someone at the beginner-intermediate type level. They don't need to solve multithreading right now. They don't see their data model as an urgent priority.
Compare that to Python where most of the core language is (1) call function, solve problem or (2) feature does something you could already do but with a little less typing.
I prefer Clojure but it is easy to see that the lack of an opinionated onboarding process is going to hurt the language.
But tools-deps don't care about packaging, deploy, install, etc. Like its name, it's focusing on `deps`.
I use tools-deps and shadow-cljs.
Having leiningen not bundled into the clojure distribution, is in strong contrast to the "batteries included" approach of python.
There were also complexities in including local jars into projects, as it required setting up a local maven repository, which is tedious job.
Also when exeptions occur clojure does not give an interactive repl like other lisps.
The problem is that Cognitect (the company behind Clojure) don’t use Leiningen themselves, and instead have released their own tool called deps.edn.
This has only fragmented the community even further, making it even more difficult for newcomers, with questionable benefits.
First, it is not called deps.edn, it is called tools.deps.
Second, it is without a doubt, 100% untrue that projects that Cognitect employees work on, exclusively use tools.deps. Cognitect has client projects they start from 0, and existing projects they shepherd and grow responsibly. Their first priority is to help their clients succeed in their goals, not change the build tool. I have worked with them, and the attitude was always pragmatic > dogmatic.
Where I will agree with you is that some folks in the community took an alpha release of tools.deps and treated it like it was the new lein or boot. It isn’t. It’s different, and as a Clojure programmer of 10+ years I use it in exactly 0 production projects. That said, it improves greatly upon “lein checkouts” by allowing one to refer to git SHAs as versions and do cross-project interactive development.
It currently have alpha support for Windows. They are still ironing out the quirks: https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Wind...
You no longer need local Maven repo, because tools.deps supports local dependencies, you can basically just depend on local folders. It also can depend on git repos.
For what it's worth, I am a system administrator (or DevOps engineer or infrastructure architect or whatever the trendy name is now). I've written several non-trivial automation tools where I had the option to use pretty much any language I wanted. The startup time and overall awkwardness of deploying the JVM for scripting was the undeniable deal-breaker. (I used Python instead).
> For boring code, which is the reality for many developers, they just want a clear best practice to get the stuff done.
More likely they just need a solution with the least-necessary added complexity or observable downsides, and that rules out the bulky JVM with its slow start-up time and the fact that Java has been under the jurisdiction of Mordor since 2010.
I think Clojure’s sweet spot is a small team working on a large enterprise project.
If you want to get started, Clojurists will insist you learn emacs. After all it's so great you must learn it.
Now I have nothing against emacs.
But I don't expect to have to invest significant effort to learn a specific editor in order to use a programming language. No other programming language has this requirement.
I was surprised at how many Clojure users took this as an attack upon emacs. It took some careful explaining to make the point that I have better things to invest my time into, such as building more code in Clojure, rather than learning yet another tool, that does something for which I have other tools already.
There were some great IDEs for Clojure. But they have all fallen into disrepair and being unmaintained.
Not sure where you get the disrepair part, Cursive is alive and well and seems to be a sustainable business for the author, and Calva also seems to do be doing well.
It's true that there have been various open source IDE efforts that are dead now (Counterclockwise for Eclipse went the way of Eclipse, Lighttable and Nightcode were probably a bit too experimental / radical)
I did use Eclipse and Counterclockwise for quite a while and enjoyed it very much.
It's on the wrong side of history in that respect.
I know it's trying very hard to catch up to statically typed languages now by retrofitting some type system, but it's too little, too late.
Static types are where the current state of the art is, and we're not going back. Clojure missed that train and will never catch it now.
Types solve 2% of programming errors. They lead to coupling for the sake of the compiler, and make code harder to change, harder to write, and often needlessly constrain the utility of the code where they're applied.
But they do make the IDE code-completion go, so there's that.
They also make code easier to reason about since the coupling that exists because of types is the result of an explicit and thoughtful decision on the part of the author. You don't as often get into situations where the code appears to work based on superficial similarity of data, only to find out there is some deep difference which prevents it from ever working.
It's also the truth that the more expressive the type system is, the less coupling you are required to do. For instance, if the language supports type classes (traits), you can codify the fact that a part of the system requires not data of a particular type, but of any type supporting some set of operations. This is the very thing you imply is lost when coming from dynamic types, only this time it's tool-backed and not merely accidental.
Very often it feels like they're "elegantly" trying to solve some made-up, bullshit problems for some questionable gain. Feels like bureaucracy for the sake of bureaucracy.
Totally like OOP shit that we're still trying to make sense of, like:
public abstract class Ellipse2D extends RectangularShape
What's the problem? Ellipses are rectangles with some extreme rounded corners. That's exactly how Euclid described them.
Typescript can be annoying but usually it helps a lot with refactoring. It's also pretty great for detecting unused props with react.
I don't use IDEs so my defense of typescript is only based on its type checking merits
Edit: Googled and nope, can't find anything.
Vastly understated in my experience. Even trivial python programs contain errors that could be prevented with a trivial type system like Go's
And performance. Not being fast enough is a bug. Consuming much more energy is a bug, in my book.
Sufficiently expressive type systems are better than dynamic typing. They prevent so many errors, especially in FP-inspired high level data transformation functions. I am saying this as a person who doesn't even like most of FP. (You can infer from my comment history).
That said, I still like some dynamic languages for certain things.
I like static typing and agree that it will eventually "win", but I really don't see where you're coming from here.
> I know it's trying very hard to catch up to statically typed languages now by retrofitting some type system
What makes you say that?
I think dynamic languages are generally a good default, but the current world also matches them pretty well because programs talk to the outside world in a lot more varied ways than before and static typing is not that very good across distributed systems.
Static has a better case when talking about more powerful type systems than what mainstream languages have, but those don't really show accelerating signs of breaking through to mainstream. Rust is an exception in the recent history but it's not really poised to become a widely applicable app programming language.
I'm seeing Clojure related posts on top of HN almost every week. And I'm watching people trying Clojure, coming with all sorts of different backgrounds. I have worked with people who came to Clojure from C++, Ruby, Python, C#, Haskell, Go, Scala, OCaml, JavaScript, CL; people with no programming experience at all.
Of course, that all is incomparable with the craze that something like Typescript receives. And I used to feel anxious, worried that this would be the last ever job where I happily used Clojure. But after my third job where Clojure was the primary language, I stopped sweating about that.
I think Clojure, at this point, has stabilized in the industry and slowly and steadily would continue to attract people. The only thing that can genuinely kill Clojure - is a better version of its fork.
But as you say, it's popular "for a Lisp dialect" and I don't expect it to reach past that. I would love to be proven wrong.
That being said, your post made me realize that instead of lamenting the nicheness of Lisps, I should be encouraging other people to give Clojure a shot. And not only to help Clojure be more successful, but also to bring a little bit of joy to their daily life like Clojure often does. (It sounds trite but it's true.)
At the same time, it still fails at my "golden test": can I gather 5 random freelance engineers and get them to ship a project within a few months, wasting almost no billable time?
I can (and have) with Ruby, Typescript. People can learn those on the go, being productive on day 3 or so.
Clojure is still bit of a journey on itself, involving quite a lot of stuff to learn, and plenty of choices to make.
That's not necessarily a bad thing, nor Clojure's "fault", but it's a real cost/risk that is still there.
I do envision a future where the mainstream is ideologically closer to Clojure, and Clojure offers an (even) more polished set of tools than today. With that mutual proximity, Clojure could indeed eat the world.
That's precisely the reason why Clojure attracts seasoned, experienced, grumpy developers.
Over and over again, they have been perfecting the art of "building things fast." The problem [with the most] programming languages today, that although they provide frameworks, command-line tools, code generators, etc. to build things quickly, the codebases very quickly become difficult to maintain and scale.
So many times, I have seen it myself. I quit jobs simply because I exhausted my mental and cognitive capacity to deal with the code that I wrote myself several months ago.
While Clojure codebases, no matter how messy they can get, they feel very much like gardens - you can slowly and organically keep growing them.
Some may say: "You're talking about Haskell, or Scala, (or some other language)" And in my experience, although you can do pretty cool things in those languages, sometimes simple, dumbed-down solutions are better. Some may argue: "Now you're talking about Python, or Go...". I think Clojure has a perfect balance between "sophisticated, ultrasmart" PLs and Pls with the books titled "X for complete idiots."
I think Clojure is an ideal language for writing business apps and more and more companies starting to see that.
But that isn't at odds with the view that Clojure is more fit in some environments than others, depending on existing knowledge, deadlines, budget etc.
Maybe I'd introduce Clojure in ~6 out of 10 projects. I want that N to be 9.
I’ve learned enough languages that I can spot “a person’s first program in X” now pretty easily.
There's an implicit assumption that all participants know a thing or two about programming, and accordingly are apt learners.
So yes, on day 3 the code won't be perfect, neither on day 6 but after a few code reviews one can get stuff done.
Personally I wouldn't be comfortable prescribing Clojure for such a project, in contrast to other languages which I've never coded in, but that I know that socially, today, work better.
https://www.youtube.com/watch?v=ROor6_NGIWU The Language of the System
https://www.youtube.com/watch?v=MCZ3YgeEUPg Design, Composition, and Performance
https://www.youtube.com/watch?v=oyLBGkS5ICk Spec-ulation
Other languages taught me how to solve problems their way, Clojure taught me how to solve problems.
My biggest hurdle while getting started was lack of Newbie friendly resources. And the language is kinda scary at first, specially if you are like me and have spent 5 years working with Python or JS.
Dr. Fynmann said that if you want to get better at something, teach it.
Following his advice I've published multiple articles [1][2][3][4] and given a talk about Clojure at a js conf [5].
The tooling is steadily improving. I don't think it will be as widespread as JS but I doubt if it aims to be. Clojure seems to attract a certain kind of developers anyways.
---
[1] What I learned after writing Clojure for 424 days, straight https://krimlabs.com/blog/clojure-424-days
Learn Clojure by building a drug dealer api [2] https://krimlabs.com/blog/clojure-drug-dealer-part-1 [3] https://krimlabs.com/blog/clojure-drug-dealer-part-2 [4] https://krimlabs.com/blog/clojure-drug-dealer-part-3
[5] If you are going to transpile JS, why not use ClojureScript? https://www.youtube.com/watch?v=Bs44qdAX5yo
time java -client -jar clojure.jar helloworld.clj
> system time 0.0001s
The -client param makes all the difference :)
And to save folks a click:
> The Client VM compiler does not try to execute many of the more complex optimizations performed by the compiler in the Server VM, but in exchange, it requires less time to analyze and compile a piece of code. This means the Client VM can start up faster and requires a smaller memory footprint.
There's literally so many just insane things about the JVM and its variants, I totally get why some folks are like "JAVA OR DEATH." I just wish I had started learning it 20 years ago, like a lot of 'em, so it wasn't such a gigantic wall of pedantic knowledge to acquire.
Why is there no magical --client / --script option for the Clojure ClI to make startup faster, if this is such an easy solution? Also, you show system time, but the time to load dependencies is in user time, which is slow by the nature of Clojure.
Example:
$ time java -client -classpath /usr/local/Cellar/clojure /1.10.1.492/libexec/clojure-tools-1.10.1.492.jar clojure.main hello.clj
Hello, world
java -client -classpath clojure.main scripts/script.clj 1.39s user 0.08s system 187% cpu 0.788 total
$ time java -classpath /usr/local/Cellar/clojure/1.10.1.492/libexec/clojure-tools-1.10.1.492.jar clojure.main hello.clj
Hello, world
java -classpath clojure.main scripts/script.clj 1.37s user 0.09s system 180% cpu 0.811 total
(Excuse the details of my Clojure install location above)User time appears slightly slower without the -client option, but probably is not statistically significant. Also, anyone who has worked on more than a toy project with Clojure knows that it's not just about the Hello World startup speed, every dependency you add has a significant impact on Clojure startup time.
IIRC Clojure apps are slow to start because they do a lot of first-time setup work that isn't actually executing user code. It's not so much a JVM problem as a Clojure-emitted-code problem. The GraalVM native-image tool fixes it because it can start an app in a pre-initialised state.
> As it turns out, Clojure start time is a complicated and multi-dimensional topic. Clojure projects are slow to start not only because of JVM — JVM itself starts in ~50 ms — but because of JVM specifics the classes are loaded slowly. Clojure projects are slow to start not only because of Clojure — Clojure itself starts in ~1 second — but because of Clojure specifics, the namespaces, especially not AOT-compiled one, are loaded slowly. And so on.
With and without -client 1 second
Built with graal 22 ms
It's cool, but it's like the complete opposite of the main ideas behind Clojure.
My core criticism that is not really mentioned in the article is the error messages. At the beginning I often felt lost and had no idea where to look if something went wrong.
Barrier for entry and continued use in that limited experience was:
- Learning curve for new developers is very high in comparison to other languages, so moving existing engineers over sucks.
- Experienced Clojure developers want a job where they can "do Clojure", not necessarily because they're interested in the problems the business was created to solve, so hiring sucks.
- Lots of conversations turn to "the Clojure way" to solve a problem rather than using industry accepted protocols, standards and tooling. I mean, OK, but this makes interacting with the rest of the World a bit sucky.
- Most libraries never get to v1.0. Most people write 0.0.1 and may do some minor updates so you see it get to 0.0.5 and then it stays there. That's probably because it all 'just works', but it scares most devs when they see that and are about to bake it into their next release.
- Deployment is a known quantity and the JVM is useful in this regard, but it doesn't have the pure simplicity that some other runtimes do. Clojure implementations in other runtimes (Joker, Clojerl, etc.), might help or hinder here.
Startup time is a problem on CLI and desktop apps, sure. At my ex-employer, one server deployed app took several minutes to start and that had challenges.
That was not - I think - the reason the team started to look elsewhere or the reason I'm more likely to pick up Ruby, Python, Go or Elixir for my next project. There are lots of rough edges like the ones I identify above - many of them cultural - that need to be smoothed out a little, I think.
I look forward to functional methods becoming mainstream (again?), and Clojure could get there, so I wish the community luck.
This seems like a common problem with functional languages in general. I've heard the same thing about Haskell, repeatedly. Such devs search out a place where a Haskeller/Clojurist got into a tech lead position and then all pile in, before you know it the team is spending half its time writing DSL compilers instead of adding features to the product.
I look forward to functional methods becoming mainstream (again?)
Has it ever been mainstream? AFAIK it's always been this basically strange offshoot of the family tree that split off a long time in the past.
The core problems you highlight don't have any obvious solution, unfortunately. Learning materials can be improved but ultimately Lisp is very old and very unlike more modern languages. Libraries not getting to 1.0 is a symptom of a small community that derives more satisfaction from an intellectual exploration than having lots of users, combined with lack of commercially driven outcomes. Startup time I guess can be solved with technical solutions (and is being solved, as a side-effect of other projects elsewhere in the JVM ecosystem).
2. The learning curve for the Clojure. Clojure is simple but it's not easy by any means.
3. JVM interop if you are not a java developer it adds in more learning time. Most of the Clojure libraries use java heavily. It's a good thing but it adds in an extra layer of learning java's ecosystem.
4. Error messages. Even after years of Clojure. I still find it hard.
5. Documentation. Most of the packages I use don't have dedicated websites or good documentation.
Even after all the issues. It's still worth the investment. I started working on a crawler for a freelance gig. we first built it using Golang. But due to its complexity and lots of bugs due to mutation. We ported it to Clojure and we are not looking back.
There were always wrappers written by somebody else that always did what I was looking for.
Interestingly, that's absolutely not my perspective and I don't see any sources for that statement in the post.
It would be a lot better for language adoption if people would write more blog posts showing best practices for tooling, and less vague stuff about how awesome the language is.
For example, the startup time thing is completely irrelevant if you use Emacs/VSCode with a standalone REPL that you connect to.
It's non-trivial to set this up (more because of lack of consolidated info rather than time it takes), but it can easily be standardized across machines/envs (I Dockerize all projects in a simple way to allow team members to get started up with REPLs easily).
https://twitter.com/draganrocks/status/1226811229362147331
It has to wait until I wrap up the books that are currently in progress [1], but I expect to start this summer.
To put my own money when my mouth is, here is the bash script to start up a nREPL server in Docker: https://pastebin.com/PPmfDPyA
Here is the Dockerfile: https://pastebin.com/ymcUFdYT
And here is a sample deps.edn with the cider alias: https://pastebin.com/2a7vSFD7
To run this, you'd just put them all in one directory, run cider-up.sh, and then connect to the REPL with Cider in EMACS, or in Calva for VSCode with "Jack in to or Connect to REPL Server" and then "localhost" "4444"
It really has great reach, and its only getting better. Similarly, in terms of programming language, you can use it to explore many paradigms and innovative ideas, like CSP, logic, probabilistic, functional, meta, concurrent, dynamic, typed, contracts, data-flow, OOP, condition systems, monads, etc. All this keeps me interested and constantly learning. Never having to wait for features you miss or wish you had.
I can see myself sticking with Clojure for a long time.
> The way the languages are integrated today, Clojure developers doing full-stack development don’t really have to think about data serialisation/deserialisation. Writing code for frontend and backend differ mostly just in the way that the different implementations access the host platform. The functional aspects of Clojure, especially the immutability and focus on referential transparency, ensure that source code is mostly split into chunks of highly portable code, with the host-interop conveniently put aside in its own sections. You can move code between frontend and backend at your leisure.
Is it really that good using Clojure across environments and runtimes?
I ask because I tried all of this with Scala years ago (I loved the language) and Ruby to an extent, but it was pretty miserable or rather there was really no reward but more effort on my part. I.e. I'd spend more time annotating, bridging, and learning how to interact with the different runtime than I would writing actual feature code[1].
Or like what are the killer libraries everyone loves? Do they (libs/frameworks) support different clojure runtimes ("hosts?") outta the box? Is it easy to write "pure clojure" projects that work for any clojure project?
The one I know about or have heard most about was Datatomic, which always sounded freakin' brilliant, but I don't fucks with non-free databases. Arcadia I just saw and it looks cool but, it also seems like a dumb mountain to climb, if that's how I wanted to start screwing around with Clojure.
[1] Tools like Scala/ScalaJS and RubyMotion (back in the day, heh), were the reasons I ended up a polyglot. They're great tools, if you know the platform, if you don't, you're pretty much still fucked... but once you know the platform it's kind of hard to want to use them.
Example 1: I'm using Clojure's Spec library for validation. There is code that is used on the browser to validate the input that users enter into forms, and the same exact code is used on the HTTP endpoints that are called when the user attempts to submit the form.
Example 2: I'm using the Tongue library to provide client-side translations of the whole UI, but the same data files and library are used in some cases on the server to generate files that contain translated strings.
Example 3: The web UI logic is written using pure data manipulation (thank the Re-frame library for that) and because of that we are able to unit test it on the JVM without having to go through the complecity of launching and driving a browser on our CI server.
Number 3 has me totally stoked; since that's incredibly valuable-- or like a dream to me to be honest, could you speak more about how that works? Is it just from using re-frame (which I'm looking at as I write this)? Is it able to test for visual regressions because of the pure-data UI? Or like how have you found that testing functionality in practice has it been saving y'all a lot of bugs and headaches you think?
The visual part of Re-frame is handled by reagent, which is a minimalist React wrapper that represents React components as pure functions, JSX as built-in Clojure data structures literals (hiccup), and state transformations using Clojure's idiomatic atom data structure. Re-frame builds on top of this base, by enforcing that a single atom (called db) holds all of the state and providing a DSL to create cursors into parts of it.
Like most things in Clojure, Re-frame's initial setup is not a straitjacket and you can swap out the state atom with e.g. an in-memory datalog database using posh/re-posh and make the data retrieval completely declarative too.
> sizeable parts of the code are cross-compiled to run both on the browser
But not all, right? I think the challenge would be knowing which parts can run on both the client and server, so you can know which parts can be moved between client and server.
But code is typically intended to run on either the server, or the browser. What would be the practical benefit of moving code between those environments?
I have not used Clojure so I'm asking because I have a similar circumstance with Node.js on the server, and DOM-manipulating JavaScript on the browsers, and its not easy to move code between those environments, and secondly, I don't much see the need for doing so. Naturally testing everything on the server would be nice, but I'm not sure how my DOM-manipulating client-code can be tested on the server.
Essentially the app was developed as an isometric app, and we had some additional stuff in the server part of the application.
While running ClojureScript serverside might not be everyone's cup of tea, it worked well for us.
The same way as it's done in React. Think of a client app as a loop reacting to user /network events and turning state into html. The same way it's done on server.
Interop with hosts is a core feature of the language so it feels natural to reach for it when you need it and it's easy to write code that handles multiple runtimes but 95% of the time maybe more you don't need explicit runtime features
I copresented a talk on the platform my team develops and how we leverage Clojure features there, specifically the ability to cross-compile between Clojure and ClojureScript that might be of interest https://www.youtube.com/watch?v=IekPZpfbdaI
That's exactly what Clojure does. It makes immutability the default, but offer tons of mutable options with varying degree of contextual restraints for performance.
For example, by default your data-structures and record types are immutable. Now, say you can tolerate some mutability within a local context, you can make your immutable data-structures temporarily mutable (called transients), apply mutation for performance in the local context, and make it immutable again once done.
Another example is, by default, Global Variables are immutable and can't have their value changed, but, you can have them have per-thread local values, which are then allowed to be modified, since they're concurrently safe.
Another example is local variables are also immutable by default, and so are data-structures, but if you need to mutate the variable, you can make it `atomic` or `volatile` depending on the level of guarantees you need around concurrent access. Now you'll be able to change their values, for the former, using an atomic eventually consistent swap and set algorithm, and for the latter, with CPU cache synchronization.
There's more, but basically, the idea is to start with the safest default, and for every new level of: "I need a bit more performance or flexibility", there is an additional construct that can be used to enable it. All the way down to full blown mutable variables and data-structures when absolute performance is required.
The short answer is: Clojure (and other languages/frameworks that emphasize immutability) is not intended for those use-cases.
The long answer is, Clojure added something called "transient data structures" as a trap-door for cases where you really absolutely need mutability for performance: https://clojure.org/reference/transients But they are really intended to be the exception, not the rule.
Enforced immutability is a conscious choice you make to trade some performance for increased robustness. Also, compared to "immutability by convention", enforced immutability allows certain optimizations to be made that greatly decrease the wasted memory and allocation/deallocation that would occur if you naively cloned everything.
If I have an array of ten million numbers. I can alter one of those array elements, getting back a new immutable array with the modification. And fast. Yet the original array still remains without the modification. How the implementation magic works is not a concern when thinking about the abstraction. But you can read how the magic works and like any magicians trick, you end up saying "oh, so that's how it's done".
So you can modify one array element and get the performance (extremely close) to how you expect a single array element modification to perform. You the original copy of the entire array also remains if some other code has a copy of it.
Imagine a recursive algorithm searching a game board with different move possibilities. Apply a move to a board and get a new game board. Yet the original game board remains unaltered. And you didn't have to implement any magic in your search algorithm. No copying of the entire game board. You just get your new game board with the new move applied so that your recursive function can proceed.
Example: a sieve function for primes. Pass it a range of n1 to n2. It seives that range, say from (1 million) to (1 million plus 100,000). It could use an efficient mutable data structure locally. Then return an immutable result. Especially since the result has no reason to EVER be mutable again. You're not going to find more or less primes within that range.
https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Wind...
Leiningen works great on Windows, and Boot is meant to as well (though I don't have first hand knowledge of that).
Isn't it always? Basically anything that's not related to .NET has its warts in Windows. Erlang for example.
It replaces the powershell code with a Clojure based executable.
The most fundamental concept in Clojure, from the famous Rich Hickey talk Simple Made Easy (https://www.infoq.com/presentations/Simple-Made-Easy/) is that your code should strive to be decomplected.
That means that your program should be made of parts that when modified do not break anything else. This, in turn, means you don't really ever need to refactor anything major.
In practice, this has held true for most of my code bases.
Now, my second answer, because sometimes there are some small refactors that may still be needed, or you might deal with a Clojure code base that wasn't properly decomplected, you would do it the same way you do in any dynamic language.
The two things that are trickier to refactor in Clojure are removing/renaming keys on maps/records, and changes to a function signature. For the latter, just going through the call-sites often suffice. The former doesn't have that great solutions for now. Unit tests and specs can help catch breakage quickly. Trying out things in the REPL can as well. I tend to perform a text search of the key to find everywhere it is used, and refactor those places. That's normally what worked best for me.
It helps a lot if you write your Clojure code in a way that limits how deep you pass maps around. Prefer functions which take their input as separate parameters. Prefer using destructuring without the `:as` directive. Most importantly, design your logic within itself, and so keep your entities top level.
In practice, it's better to avoid positional arguments and extensively use maps and destructuring. Of course, there's a risk of not properly passing a key in the map, but in practice that doesn't happen too often. Besides - Spec, Orchestra, tests and linters help to mitigate that risk.
We can agree to disagree I guess. In my experience, especially in the context of refactoring, extensive use of maps as arguments causes quite a lot of problems. Linters also do nothing for that.
Positional arguments have the benefit of being compile errors if called with wrong arity. I actually consider extensive use of maps a Clojure anti-pattern personally. Especially if you go with the style of having all your functions take a map and return a map. Now, sometimes, this is a great pattern, but one needs to be careful not to abuse it. Certain use case and scenarios benefit from this pattern, especially when the usage will be a clear data-flow of transforms over the map. If done too much though, all over the app, for everything, and especially when a function takes a map and passes it down the stack, I think it becomes an anti-pattern.
If you look at Clojure's core APIs for example, you'll see maps as arguments are only used for options. Performance is another consideration for this.
Doesn't mean you should always go positional, if you have a function taking too many arguments, or easy to mix up args, you probably want to go with named parameters instead.
Long term I can see a more intelligent feedback system powered by codeq helping with static analysis and refactor feedback, like unison but better (using a real DB and open for extension)
The Rationale page on clojure.org has a pretty good rundown: https://clojure.org/about/rationale
For me Racket is probably the closest thing to a decent end-to-end modern lisp experience with decent libraries outside Clojure. Gerbil Scheme also looks promising.
For me I’m most often writing smallish standalone apps, which I feel are easier to make in Racket than Clojure. But between the two languages, I’d probably take Clojure if I didn’t have the JVM along for the ride. Of course the JVM is also one of Clojure’s biggest strengths. Also, I don’t trust Oracle enough to stop pretending that Graal doesn’t exist.
And Graal (the option I’m aware of for compiling JVM-based code into a redistributable binary) is definitely Oracle. If I wrote more long-running code, or I could redistribute a stripped down JVM as easily as with Racket’s build tool “raco” I might have a different view, and I’d definitely prefer OpenJDK to Oracle’s.
Did I parse that correctly as: "I don't trust Oracle, therefore I pretend Graal doesn't exist"?
Those are still LispWorks and Allegro Common Lisp.
Clojure, being just over 10 years old, has gotten to benefit from decades of witnessing other languages' spectacular design disasters, and it was designed by one person in a few years instead of by committee over decades. This results in a language that is much more aesthetically coherent, adhering to a pragmatic flavor of FP, and avoids a lot of gnarly warts: for instance, Clojure has one basic way to test equality irrespective of data type, and all basic data structures are immutable.
It's not obvious that (a) is superior to (b), an (c) is often what you get.
I'd like to have a broad view of how many lispers working with one.
the few I know:
- scheme had a coma period due to specs issues (scheme small and large standard)
- commonlisp .. no idea but it seems quicklisp is enough for anybody to work, and there are many libs. Maybe not java/python levels .. but many. It's just out of the radar.
Additionally, there are many Lisp old timers that do not consider Clojure a Lisp.
From my brief experience it can do most of the same things except reader macros.
* Clojure is based on seqs rather than cons cells.
* Clojure renamed certain common functions, like car and cdr, so 30 year old Lisp example code no longer compiles.
* Clojure doesn't have implicit tail call optimisation for recursion.
* Clojure reveals its host platform when it has runtime errors.
I think everyone using Clojure JVM, ClojureScript, or Clojure CLR should be doing this.
I've seen people with no prior programming experience learning Clojure within a few days. And I've seen senior software developers struggling with it for months.
When it was used only for certain kinds of "shallow" compilation it was bad enough (and it was really horrible even then), but this article uses it when describing compilation with whole-program analysis and optimization and machine code as the target.
I like the added distinction "transpiler" provides as I immediately know what the author means. Or the author could just use the term "compiler" plus another sentence to describe which kind. Transpiler seems like the more efficient way to convey the concept.
(Clojurescript does [transpile/compile, pick your favorite] to Javascript)
Anyway, Clojure is great!
[1]: https://stackoverflow.com/a/9859966/750563
[2]: Sorry Template Haskell, Java is more referentially transparent than you, although the consequences of that are not what those same FP people think, either.
But now after looking at their other comments, I see it was not sarcasm.
What an understatement for how messy functional programming can actually be.
```
Fools ignore complexity. Pragmatists suffer it. Some can avoid it. Geniuses remove it.
---- Alan Perlis, Epigrams in Programming.
the first recipient of the Turing Award (1966)
A founding father of Computer Science as a separate discipline
When the solution is simple, God is answering.Everything should be as simple as possible, but not simpler.
Most of the fundamental ideas of science are essentially simple, and may, as a rule, be expressed in a language comprehensible to everyone.
If you can't explain it simply, you don't understand it well enough.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction.
---- Albert Einstein
```https://github.com/linpengcheng/PurefunctionPipelineDataflow
By now I guess that you have had enough exposure, but most of your comments and links to github have not sparkled a lot of interest or comment, and reception has been skeptical / lukewarm.
Take this as just one datapoint but for me your insistent reposting is more noise than any other thing. If you really care about your theory that is cool and all, but may I suggest that you create something like some practical application examples in blog form, edit them thoroughly, and then post them as new topics, intead of polluting "related" conversations? That way you can better gauge what interests this community, and what not.
By the way interleaving english and chinese such as in your repo README.md makes for an unpleasant read - better to separate both in two distinct documents.
Best luck!
In fact, this theory has been unprecedentedly hot recently. Star and traffic on github have risen sharply. On 2020-02-27, it was published by editor on reddit/devopsish, and other clojure communities.
My theory is written for a few people who understand Chapter 2 of the "Code Complete" and can read it without reading other chapters, not for people who cannot understand Chapter 2 and focus on other chapters.
So I have stated in the article: I will not write too many application examples or patterns. Because people who like to read such articles can't learn my theory.Because they lack imagination.
```
Imagination is more important than knowledge.
The true sign of intelligence is not knowledge but imagination.
Logic will get you from A to B, imagination will take you everywhere.
---- Albert Einstein
```For some reason this doesn't often happen with regular Lisp even though CFFI is available. There's a tendency to just reimplement it directly in Lisp, which is the more maintainable option.
I can imagine if I were to learn a new lisp, that was hosted on a language I did not know, and various difficult things leaked through the abstraction making it more difficult for me to work. I might feel similarly.
1. Weirdly irregular syntax.
2. Java import statements and Java error backtraces anywhere you want to do real work.
3. Inexcusable renaming and name collisions on basic Lisp functions.
It's much, much less of a Lisp than Scheme and neither "but it's properly functional" nor "we fixed the tooling now" make that any less true or the language any more interesting for the use cases of using a Lisp or targeting the JVM with a more expressive language.
As an example I remember a presentation done some time ago where the presenter was showing code in F# and many non-technical people understood the code thinking it was a pseudo code at first (i.e. business stakeholders/BA types/etc). That was a win for them. If I showed F# and Clojure code side by side to an ex-coder manager as an example syntax I'm sure would matter and they often have a say in this decision. Buy-in is an important criteria in language selection for sure, as well as current skilled developers. If the pool of devs is small how easy it is to train people and get people wanting to be trained in it thinking it may be dead end skill with no jobs? I don't have that opinion personally but some dev's definitely do. Especially because jobs in these languages are scarce; if learning curve is small then it could be used even then.
My cynicism shows marketing and perception of a tech stack are equally if not more important than other factors in tech selection in many companies. No one got fired for picking IBM or in this day and age Java?
2. If you’re writing a wrapper to existing java lib maybe
3. Tough to be a particular lisp fanatic I guess.. Clojure helped me to get into lisp big time and all other lisps now feel clunky and inelegant.
For those of us who work for someone else - Clojure is a godsend. What's the alternative? No Lisp at all, and truly weirdly irregular syntax. Show me a single pragmatic and more or less popular language that's being used in the industry for building business apps that has nicer syntax than Clojure.
"Irregular syntax", as in not consistent with itself? Or, with historical LISPs? Some examples would be interesting.
>3. Inexcusable renaming and name collisions on basic Lisp functions.
Given that it isn't a version of common lisp that happens to target the jvm being more superficially similar while actually being substantially different wouldn't be a virtue. It would confuse more than it would illuminate.