News for hackers. Stuff that matters.
Re:How much can a Clojure developer do alone? by klibertp on Tuesday March 30, 2021 @01:34PM (#26637619)
> There is no other language that places such an emphasis on programming directly with plain and naked data literals.

Counterexamples: Erlang and Elixir. Arguably also Prolog. Also Lua. Many Schemes, and Racket. Of course, REBOL and Red. TCL probably, too.

I can't help but think that people making claims of "no other language has X" are in most cases wrong, and should study a bit more before making them.

There's a lot of hype in the article, I don't want to diminish the value of REPL-based workflows or conciseness[1] of the language, but the overall message that any fresh graduate can become a 10x programmer in under a month... Well, there's at least nothing humble about it, despite the article touting "humility" as a virtue of prospective Clojurists.

[1] Why aren't we all writing in APL/K/J if it matters that much?

Re:How much can a Clojure developer do alone? by FPGAhacker on Tuesday March 30, 2021 @02:00PM (#26637994)
I haven’t written any Clojure for a few years now. So my knowledge and technique is out of date, but I have a contrary opinion on “repl driven” development vs many Clojure advocates. In short: your repl compiled code is state that you now have to track in your head.

Yeah, great, you can compile a single function and it hot loads. It’s pretty awesome for experimenting and debug, but the longer your repl session is open and the more you change and compile, the more likely you are going to end up with a mixed state in memory that does not reflect how your program would behave if run from scratch.

You are going to forget to save a change or your manual tinkering with a data structure will leave it inconsistent. These errors accumulate, like navigation error with an IMU.

It’s got use cases for sure, and I miss hot reloading when I’m debugging in other languages, but it is far from being the ultimate feature a language can have.

Re:How much can a Clojure developer do alone? by sli on Tuesday March 30, 2021 @02:35PM (#26638482)
I was very productive in Clojure for some number of years and never once, not a single time, found benefit in REPL-driven development. I've used it here and there just to test little snippets, but never actually used it for real.

Frequently I found it unnecessary, anyway. Clojure just made it way to easy to get things right that I rarely had to dive in and figure out why something was wrong.

These days I prefer types over Lisps for that, but people change.

Re:How much can a Clojure developer do alone? by blandflakes on Tuesday March 30, 2021 @06:58PM (#26641573)
Totally agree. I found Clojure to be an amazing, well-designed language. I found the REPL to be secondary to really great immutable data structures and pragmatic escape hatches.
Re:How much can a Clojure developer do alone? by Jtsummers on Tuesday March 30, 2021 @03:27PM (#26639195)
I think this gets to the issue that there are two different ideas of "REPL driven".

In one, you're using the REPL frequently in production. In the other you're using it during development. Those are two different scenarios and result in different perspectives.

Just like many (most?) organizations have gone to (varying degrees of) infrastructure as code versus tweaking each server manually, REPL-in-production is similarly problematic. As you noted, you end up in a position where you aren't actually sure of the system state (both what it is and how it got there). This is a use of the REPL that should be minimized (if you're using it to actually change the system state versus trying to understand the system state, especially).

However, when working on a new system you may tweak a single or small cluster of servers manually and build out your automation scripts based on that experience. Similarly, the REPL during development is a way to quickly prototype, experiment, and test code but needs to end up committed to actual source files for deployment.

Re:How much can a Clojure developer do alone? by huahaiy on Tuesday March 30, 2021 @02:18PM (#26638221)
If you write your code the correct way, there wouldn't be any states in your namespaces for you to keep track in your head. That only happens if your code is full of `(def some-state (atom {}))` or something like that.

You are basically illustrating my point about "You probably cannot learn Clojure all by yourself". You need a mentor to show you how to do Clojure correctly, or you have the humility to learn the proper Clojure way. Sadly, most people would rather just try something and jump onto conclusions immediately.

Re:How much can a Clojure developer do alone? by adamkl on Tuesday March 30, 2021 @04:21PM (#26639913)
Function definitions and vars are a form of state that can accumulate in a REPL session. Its not just atoms.

This can lead to issues where you decide to refactor and rename a var (Clojure is all about concise and expressive names, so its not uncommon to do this.. At least not for me) but you might not catch every place the old var name is being used. Because both vars are still exist in the state of your REPL, everything seems to work, but once you compile your uberjar or whatever, things are broken.

A REPL isn't a replacement for good unit tests, and there are techniques for reloading your REPL state on save, but the issue of needing to keep the "REPL state in your head" is real, and not an artifact of doing things wrong. Just something that the developer needs to be aware of as a potential hiccup in the REPL experience.

Re:How much can a Clojure developer do alone? by klibertp on Tuesday March 30, 2021 @02:36PM (#26638500)
> If you write your code the correct way,

Then you don't need a REPL. This is a very weak argument, overall: there are programming techniques to compensate for any deficiency in the environment. The fact that you need to use them is already worse than not having to worry about it at all.

> Sadly, most people would rather just try something and jump onto conclusions immediately.

Just a gentle reminder, you're not talking to "most people" here. Nevermind me, we [EDIT: cut out the irrelevant details] I just want to say that assuming good faith and informed criticism are the better defaults for this forum.

Re:How much can a Clojure developer do alone? by 8note on Tuesday March 30, 2021 @03:53PM (#26639537)
Repl development is great for exploration, when you don't quite know the right representation of your problem yet.

The alternatives isn't changing your development environment, it's writing on a white board

Re:How much can a Clojure developer do alone? by huahaiy on Tuesday March 30, 2021 @03:00PM (#26638841)
Nobody said you "need" REPL. Doing REPL driven programming is just more productive, hence it is considered the right way in the Clojure community. Heck, you don't even "need" any higher level languages, you can write code in machine code, but that's besides the point.

Your boast about your Lisp credentials is exactly the kind of things I caution against in the article. Your pride has prevented you from properly learning Clojure, which has a very different programming style from other Lisps.

You are basically illustrating my point live, again.

Re:How much can a Clojure developer do alone? by klibertp on Tuesday March 30, 2021 @03:16PM (#26639049)
> Nobody said you "need" REPL.

Well, you did, quoting the article:

> Yes, if you are not using the REPL, you are not doing Clojure right.

or should I understand this another way?

> but that's besides the point.

True. I'm saying that if you need to code in a particular way to make good use of the REPL, then it's already worse than being able to use the REPL well without any special coding style. Erlang and Elixir are great examples of that.

I also have a problem with you believing there even is one correct way to use any language, but that's bearable. You being so sure that you're the only one qualified to know anything about that correct way is much worse.

EDIT: I just saw so many "revolutionary ways to write code" which were being pushed hard by people absolutely sure their methods are so much better, and which ultimately amounted to little more than a few percent improvement in productivity in the real world - in the best case. It makes me suspicious of any such claims.

> Your boast about your Lisp credentials

My? I said:

> Nevermind me, but [...]

So you're putting words in my mouth; further, I said nothing about my knowledge of Clojure, so this:

> Your pride has prevented you from properly learning Clojure

Is completely unwarranted. And offensive. Could you please stop?

Re:How much can a Clojure developer do alone? by huahaiy on Tuesday March 30, 2021 @04:30PM (#26640036)
Then it is actually far worse than what I guessed. You know next to nothing about Clojure, but somehow feel that you are qualified to have an opinion about it. That doesn't look good, does it?
Re:How much can a Clojure developer do alone? by klibertp on Tuesday March 30, 2021 @04:42PM (#26640175)
What opinion about Clojure?! Where? You're jumping to conclusions without any basis, while trying to caution others not to jump to conclusions?

I'm talking about the general ease of use of features in programming languages. If you need to code in a particular way to use a feature, then it's harder to use than if you didn't have to do this. Is that wrong? Could you provide any argument on why is it wrong? And yes, I use Clojure's REPL as an example, and give Erlang as a counterexample. Do you know Erlang? Are you able to compare? If yes, why don't you write about how you see that comparison?

Instead of, you know, childishly fixating on things I never said. For your information, I do know more than "next to nothing" about Clojure. But you won't believe me either way, will you?

Re:How much can a Clojure developer do alone? by klibertp on Tuesday March 30, 2021 @02:28PM (#26638383)
I think this is caused because of the disconnect between the source in files and an environment in a REPL. There are alternatives:

You can keep your source inside your environment, like in Smalltalk. Whatever state you modified, it stays modified as long as you use the same image.

You can ignore hot reloading and have short-lived REPL sessions for testing and debugging. This works with Scala, OCaml, Idris, and similar. You don't need to track state too much, as it's frequently reset to known-good defaults.

Erlang allows hot reloading, but of whole modules only. You can only evaluate expressions in the REPL, not definitions. It's a good strategy, because the state in Erlang is rarely shared across modules, and having to reload the whole module ensures that it's always initialized correctly.

I think Clojure model is very close to what Racket has: you can switch between modules in the REPL and mutate their namespaces without ever reloading them from disk. Common Lisp is also close, the difference being that CL is image based, so there's a way for persisting the state changes... even if it's not the best of ideas :)

I like the Erlang model, but they all have advantages if used correctly. Pervasive immutability and sane reloading strategy help a lot, but even without those, you can use the REPL effectively. On the other hand, "living in the REPL" all the time is maybe going too far.

Re:How much can a Clojure developer do alone? by sdfsfsf3kjdf on Tuesday March 30, 2021 @02:57PM (#26638798)
> but the longer your repl session is open and the more you change and compile, the more likely you are going to end up with a mixed state in memory that does not reflect how your program would behave if run from scratch.

I've seen this happen multiple times including during live Clojure talks at conferences. I also never found REPL driven development all that beneficial outside of quickly toying with trivial pure functions and that's possible in basically every popular language these days.

Re:How much can a Clojure developer do alone? by Tcepsa on Tuesday March 30, 2021 @02:37PM (#26638505)
TL;DR -- Possibly it has to do with the style that I use, but those things doesn't actually happen to me very often, and when they do it's not a big deal. For me, the benefits of REPL-driven-development far outweigh occasionally having to deal with these issues.

Two things. First, I've been bitten by this myself, but it's pretty much always been something like "Oops, I renamed a function and forgot to update a reference to it, but the code still worked because the old definition was still there... until I reloaded the REPL." It's always been a trivial fix for me, since when I try to re-evaluate the buffer containing the outdated function reference it throws a "cannot find function definition" error. I currently consider the advantages of REPL-driven development to outweigh that occasionally happening.

Second thing: maybe others do it differently, but I don't think I generally make manual changes to the state while things are running. If the state doesn't look the way it should, I either start iteratively tweaking functions (by modifying my .clj file and eval-ing them) and re-running with fresh state to understand and resolve the problem, or I work with a separate, similarly-shaped piece of state and run it through functions in a sort of "manual unit testing" to tweak and fix whatever's wrong, and then I re-run everything from scratch to make sure it worked. I don't adjust the state, evaluate a code path, and then continue on if it works (because yeah, I can totally see how that would lead to the sort of situation you describe, which sounds unpleasant)

Re:How much can a Clojure developer do alone? by jimbokun on Tuesday March 30, 2021 @03:00PM (#26638847)
To me, that's similar to waiting to save your Word document until you have finished editing your document.

REPL should be used for rapid experimentation, but then the code should be transferred to a source file and saved before moving on to the next thing.

Re:How much can a Clojure developer do alone? by kgwxd on Tuesday March 30, 2021 @04:30PM (#26640030)
When doing REPL dev with clojure, I usually never type directly in the REPL, it's connected my editor and there are shortcuts for evaluating forms already typed in there (e.g. form under cursor, form before cursor, outer most form, entire file) and it outputs the results right after the form (as a temporary display or can even be output the text into the file).

There's also the handy "comment" function that lets you do something like (comment (+ 1 1)) in your code file that won't get compiled but keeps all the editing benefits (syntax highlight, structural editing) that you wouldn't get if an expression was commented out using comment syntax.

Re:How much can a Clojure developer do alone? by mustermannBB on Wednesday March 31, 2021 @02:20PM (#26650962)
That is my understanding of REPL driven development, too.
Re:How much can a Clojure developer do alone? by gorjusborg on Tuesday March 30, 2021 @10:56PM (#26643042)
This comment reveals a view of REPL for non-image based languages.

In clojure, we usually add forms (like functions) to the editor then eval them to update the namespace hosted by a separate REPL running in background.

Often the file is already saved before

Re:How much can a Clojure developer do alone? by jolux on Tuesday March 30, 2021 @02:19PM (#26638232)
>Why aren't we all writing in APL/K/J if it matters that much?

In all seriousness I think writing more code in APL would probably cut down on bugs, but array-oriented languages are so far beyond how most programmers think about programming, and look so obscure, that I don't think there's any hope of them seeing widespread adoption. Most people loathe point-free Haskell, so I can only imagine what they'd think of the APL family.

Re:How much can a Clojure developer do alone? by dTal on Tuesday March 30, 2021 @05:24PM (#26640742)
Not really; a direct descendent of APL is very widely used, and it's called Numpy. It's just that array-orientation, while great (especially for numerics), is insufficiently general to comfortably express arbitrary algorithms. You can write "APL" in many modern languages, but people still prefer to use traditional control flow for many purposes; hell, even APL provides this "escape hatch" (though it looks bolted-on).
Re:How much can a Clojure developer do alone? by jolux on Tuesday March 30, 2021 @05:49PM (#26641014)
Numpy is definitely not as powerful (read: concise) as APL, and you really can’t write “APL” in most modern languages. The operators are rank-polymorphic, for one.
Re:How much can a Clojure developer do alone? by renox on Tuesday March 30, 2021 @04:32PM (#26640054)
Well I've had a few lesson in APL a long time ago and what I remember is that APL is a write-only language. So I doubt that it would 'cut down on bugs'
Re:How much can a Clojure developer do alone? by jolux on Tuesday March 30, 2021 @04:46PM (#26640224)
>Well I've had a few lesson in APL a long time ago and what I remember is that APL is a write-only language.

This is not how everyone who writes APL feels about it. It is recognized that it takes quite a while to really internalize how the operators work and compose, though. One advantage of APL stated by Aaron Hsu is that because the code is so small, if you find it confusing, you get in the habit of rewriting it frequently, and at least for him, it gets clearer over time. I have only dabbled myself (Primarily an OCaml and Elixir/Erlang programmer), but what understanding I have about empirical studies of software engineering suggests lines of code is more or less the only consistent predictor of defect count.

Re:How much can a Clojure developer do alone? by Jtsummers on Tuesday March 30, 2021 @04:45PM (#26640206)
It becomes less "write-only" as you build up experience. It's just not as readily learnable (if you're already a programmer) as most other languages. I mean, procedural and OO languages seem to have largely adopted a variation of Algol or C syntax with roughly comparable semantics to others in the same family. A programmer in C, Java, JavaScript, Fortran, Ada, Pascal, Go, Rust, Python, Ruby, etc. can mostly jump to the others and be able to at least read the program without much difficulty, though learning to write and extend the program (especially idiomatically) will take more time.

APL's syntax and semantics are much different so it has a larger barrier for getting to the level of reading or extending programs written in it, but it's not impossible to reach that level with a bit of practice. I spent a few months doing APL for 2-3 hours a week in the evenings and I was able to develop a reasonable level of competence in it (though not so much I'd drop it on my CV), I can still read it pretty easily now a couple years later and without really touching it since then.

Re:How much can a Clojure developer do alone? by bobthechef on Tuesday March 30, 2021 @01:45PM (#26637788)
I also thought the bit about fresh graduates having no pride rather blanket. There are plenty of prideful fresh graduates with the kind of pride that experience hasn't yet tempered to produce a humble respect for the fact that you will die knowing next to nothing. Sadly, even some old timers never catch on to that.
Re:How much can a Clojure developer do alone? by jimbokun on Tuesday March 30, 2021 @02:58PM (#26638812)
> [1] Why aren't we all writing in APL/K/J if it matters that much?

Because most programmers aren't nearly as productive as we could be.

And because "concise" should be measure in the number of tokens needed to achieve certain functionality, not by excessive use of single character tokens.

Re:How much can a Clojure developer do alone? by CraigJPerry on Tuesday March 30, 2021 @03:28PM (#26639219)
I wonder if there’s a sweet spot for verbosity or if it doesn’t really correlate with bugs or productivity. I end up thinking about this pretty regularly.

For example Kdb/q has always fascinated me, my initial reaction was that encoding meaning into fewer symbols surely causes cognitive overload and promotes programmer failure, and yet i saw some python code written by a quant converted to q by a kdb developer. The original python was well written, it relied on pandas and numpy but all fairly garden variety stuff.

The q had exactly the same behaviour except some small changes for data ingestion. Around 500 lines of python, 16, not a typo, 16 lines of q. The performance comparison was absurd too.

Re:How much can a Clojure developer do alone? by arabelladonna on Tuesday March 30, 2021 @03:50PM (#26639497)
> The q had exactly the same behaviour except some small changes for data ingestion. Around 500 lines of python, 16, not a typo, 16 lines of q. The performance comparison was absurd too.

I think this comes down to every symbol having a defined behavior that can be optimized around, rather than building a framework for creating your own symbols (functions). Dyalog APL has some similarly insane "beating C"-type benchmarks.

However, if you were to branch out into the more traditional constructs in Dyalog APL or J (K/Q have less of them due to being much, much less generalized), you'd probably see some significant performance decreases simply because they're more generalized. Eg. I doubt that Dyalog APL objects are as optimized as C++ objects.

Note: I have no experience designing languages or building compilers/interpreters. I just wanted to put my two cents in, rather than leave this on the somewhat vague and "mystical" note.

Re:How much can a Clojure developer do alone? by anonu on Tuesday March 30, 2021 @03:58PM (#26639608)
This has been my experience as well. 10x factor reduction in LOCs and increase in performance when moving to kdb/q
Re:How much can a Clojure developer do alone? by roninhacker on Tuesday March 30, 2021 @03:34PM (#26639278)
>And because "concise" should be measure in the number of tokens needed to achieve certain functionality, not by excessive use of single character tokens.

I am totally nitpicking here, but as a longtime Clojure programmer, I do have a bit of APL envy. Aaron Hsu (noted APL guy) made the point that brevity (in the linear, #-of-characters sense) let's you decrease complexity by avoiding indirection---when the body of a function is shorter than any name you might give it, you can just...write it...rather than writing it somewhere else and calling it.

I don't plan to switch away from Clojure any time soon, but I definitely want to play around with the APLs.

Re:How much can a Clojure developer do alone? by mlochbaum on Tuesday March 30, 2021 @03:51PM (#26639522)
You may be interested in April[0], a version of APL embedded in Common Lisp so that it can be called as part of a CL program. Also, my own language BQN[1] is a rework of APL that comes much closer to Lisp in that it has first-class functions and closures. It's self-hosted (using a compiler that follows Aaron's strategy), allowing it to be embedded in other languages with relatively little effort, but currently poor performance. There are Javascript and C VMs with another programmer working on one in Erlang; Clojure could definitely be a possibility.

[0] https://github.com/phantomics/april

[1] https://mlochbaum.github.io/BQN/

Re:How much can a Clojure developer do alone? by roninhacker on Tuesday March 30, 2021 @04:04PM (#26639690)
Wow, this is totally cool, thank you!
Re:How much can a Clojure developer do alone? by philwelch on Wednesday March 31, 2021 @04:04PM (#26652385)
> And because "concise" should be measure in the number of tokens needed to achieve certain functionality, not by excessive use of single character tokens.

That makes me wonder how this would shake out differently if we didn’t use Latin-based writing as the foundation of our programming languages. If you had a programming language that used Chinese characters, would that be fundamentally more usable, assuming that you understood Chinese characters to begin with?

Re:How much can a Clojure developer do alone? by arabelladonna on Tuesday March 30, 2021 @03:55PM (#26639566)
> And because "concise" should be measure in the number of tokens needed to achieve certain functionality, not by excessive use of single character tokens.

What's the difference if the symbols were meant to have specific mathematical meanings and are really meant to be the only representation?

Plus, readability is subjective.

Re:How much can a Clojure developer do alone? by blacktriangle on Tuesday March 30, 2021 @02:01PM (#26638007)
I think it goes further than the language's support of data literals to the culture of the language itself. The Clojure community takes programing with data literals to, what I would call, a pathological extreme. It's as if nobody wants to write actual code, just data structures to be interpreted, regardless of how general those data structures are. The problem is everybody gets hung up on code is data but doesn't realize that data is not code. At some point that data has to be interpreted, and passing around custom data literals trusting they'll be understood correctly elsewhere in your program turns into its own challenge.
Re:How much can a Clojure developer do alone? by huahaiy on Tuesday March 30, 2021 @02:26PM (#26638342)
You are contradicting what your parent post is saying and agreeing with the OP. So you agree that Clojure is the most data-oriented programming language, but you feel like it is too extreme?
Re:How much can a Clojure developer do alone? by blacktriangle on Tuesday March 30, 2021 @02:28PM (#26638379)
That sums it up. I think Clojure is the most data-oriented programming language there is, but it gains that title not through features which other languages have as well, but through its general developer culture. And also, I do feel that the Clojure community often takes data-oriented programming too far.
Re:How much can a Clojure developer do alone? by klibertp on Tuesday March 30, 2021 @02:52PM (#26638726)
REBOL and TCL are languages which go at least as far as Clojure in data-centric programming. Both feature incredibly elegant DSL for a variety of tasks, like constructing parsers or defining GUIs. Personally, I don't have an opinion on whether they (including Clojure) take it too far, but it's true that even that culture is not unique to Clojure :)
Re:How much can a Clojure developer do alone? by huahaiy on Tuesday March 30, 2021 @03:07PM (#26638939)
I don't know about REBOL, but I did program TCL extensively in my graduate school years. I agree TCL has a lot of similarity in term of treating code as data like in Lisp, but I do not think it has such an emphasis on data oriented programming like in Clojure. That's just not true.
Re:How much can a Clojure developer do alone? by klibertp on Tuesday March 30, 2021 @03:22PM (#26639138)
It might not be immediately clear, but the "data oriented programming" discussed in this subthread is about using code as data to be interpreted. That TCL has way less primitive data structures and even less syntax for them doesn't mean it doesn't treat a lot of the code as data. REBOL[1] and Red, on the other hand, do have a comparable collection of data structures along with literal syntax for them.

[1] https://en.wikipedia.org/wiki/Rebol#Dialects

Re:How much can a Clojure developer do alone? by nojito on Tuesday March 30, 2021 @02:49PM (#26638676)
F# is a cleaner example of putting data first.
Re:How much can a Clojure developer do alone? by CraigJPerry on Tuesday March 30, 2021 @03:34PM (#26639288)
Does F# not put types first and data second?

Would it be idiomatic to do clojure style maps where the map keys end up being treated like pure functions that return a value.

Re:How much can a Clojure developer do alone? by jolux on Tuesday March 30, 2021 @04:25PM (#26639972)
>Does F# not put types first and data second?

The F# and ML view of the world is, roughly, that data and types are not separable in any way that's useful. Types are just how programmers make sense of data, and they exist in every language. The difference is whether or not the compiler will use them to help you make sense of your data as well, or whether you have to do your own manual type-checking.

As for programming with maps the way it's done in Clojure, I would say generally no, that's not idiomatic F#, and it's a big blind spot for F#. OCaml has row polymorphic records, which would be a better fit for the treat-everything-as-a-map style of programming in a static language.

Re:How much can a Clojure developer do alone? by klibertp on Tuesday March 30, 2021 @02:55PM (#26638759)
Yes; I didn't mention it because, while they are technically literals, you are expected to write your own types and use your own constructors. But yes, F#, OCaml, Haskell, Idris, Elm, etc. are also very data-centric.