News for hackers. Stuff that matters.
Re:Clojure needs a Rails by mark_l_watson on Saturday July 30, 2022 @01:51PM (#32288782)
On Twitter, PureDanger had a nice comment, something like: it is better style to directly call into a Java library than to write or use a wrapper.

I am not sure if this really answers your comment, but I really liked his comment because I tend to write wrappers and re-evaluated my habits.

Re:Clojure needs a Rails by stingraycharles on Saturday July 30, 2022 @02:07PM (#32288915)
When I started out with Clojure, I was using wrappers everywhere, but after about a year or so realised that they added very little value, hurt performance, and made the code less simple. On top of that, wrapper libraries were often not complete in functionality.

The pivotal moment for me with this was when dealing with Kafka, just using the “raw” Java library ended up being so incredibly much simpler than any of the wrapper libraries.

Re:Clojure needs a Rails by code_biologist on Saturday July 30, 2022 @02:54PM (#32289299)
It's been more than a decade since I've used Clojure so I say this with a big grain of salt.

Where there weren't good wrappers, just a few functions "wrapping" Java libraries for my project's needs always felt lightweight and lispy. The little internal APIs I made almost always passed around the library's raw Java objects, but with more Clojure idiomatic ways to construct them, or slapping some seq on the library outputs.

Re:Clojure needs a Rails by gengstrand on Sunday July 31, 2022 @03:11PM (#32297909)
I have a github repo where I implement a feature identical microservice in various tech stacks. I started that repo with a Clojure version that used community provided wrappers. See https://github.com/gengstrand/clojure-news-feed/blob/master/... as an example of calling Cassandra. Recently, I added another implementation with Clojure that just called the Java drivers directly. See https://github.com/gengstrand/clojure-news-feed/blob/master/... for that version of the same call. In the end, I decided to forego wrappers and make the calls directly because you end up with fewer dependencies and are more likely to be able to use latest versions of everything.
Re:Clojure needs a Rails by janetacarr on Saturday July 30, 2022 @02:02PM (#32288880)
That's surprising. I listed the interop caveats here because sometimes it feels like a bandage intended to bridge some gap until Clojure matures.

But if Alex said that, then maybe it's not. ¯\_(ツ)_/¯

Re:Clojure needs a Rails by didibus on Saturday July 30, 2022 @07:56PM (#32291603)
Really it's not. The interop is a conscious decision core to the language rationale.

https://clojure.org/about/rationale > Customers and stakeholders have substantial investments in, and are comfortable with the performance, security and stability of, industry-standard platforms like the JVM. While Java developers may envy the succinctness, flexibility and productivity of dynamic languages, they have concerns about running on customer-approved infrastructure, access to their existing code base and libraries, and performance

> symbiotic with an established Platform

> VMs, not OSes, are the platforms of the future, providing: [...]

    * Libraries
    * Abstract away OSes
    * Huge set of facilities
    * Built-in and 3rd-party
https://clojure.org/about/jvm_hosted > Clojure is designed to be a hosted language, sharing the JVM type system, GC, threads etc.

> Clojure is a great Java library consumer

Where Clojure had nothing to bring, nothing was implemented, because interop is considered just as good, that's why there's not a lot of IO functions in core, and why math was missing for a long time.

Re:Clojure needs a Rails by eduction on Saturday July 30, 2022 @08:16PM (#32291730)
A good wrapper (like the Clojure version of java-time) can be a real lifesaver for those of us without Java backgrounds who don’t like having to learn deep and often baroque Java apis.

I also use a pretty half baked wrapper someone wrote because I just about lost my mind trying to make sense of the class hierarchy it was wrapping.

I think for people like Rich and Alex wrappers may look pointless because they already have invested in learning many of these APIs, know the patterns already, etc. For people like me from different language backgrounds they keep me from having to learn APIs with mutable state and deep class hierarchies and to me that’s a big win.

(I rewrote this whole comment to hopefully be more concise.)

Re:Clojure needs a Rails by didibus on Saturday July 30, 2022 @08:49PM (#32291954)
Very good point. I have no rebutal, you're absolutely right on that front.

I just don't know how to address this problem. It seems the people in a position to build good wrappers or Clojure implementations are also the people who know Java and Clojure, and maybe came to Clojure from Java. For them, it's easy to interop directly, so they take the path of least effort, and don't bother making a Clojure lib.

In a way, if Clojure couldn't use Java, while it would mean I probably wouldn't be able to use it at my work and would be forced to still work in Java, it would also mean maybe for my personal stuff or for certain companies who'd embrace it anyways, I would and they'd be forced to go ahead and put the effort to build Clojure variants of all these libraries, and that would make it friendlier to people learning Clojure that don't know Java.

I have to admit, I always react a bit defensive on articles like this one, and it's mainly because I don't see the problem, I see people complaining about things that are non-issue for me. But your point hits me in a different way, you make a good point, having to learn a language and a half (all of Clojure and half of Java) is definitely not as good as it should be.

I think normally people come at it like saying how interop is bad, difficult, not idiomatic, or that there's no libraries so they had to use Go-lang, where there were clearly options to use a Java lib from Clojure. But if the article just said, hey, using Java is unapproachable to a lot of folks, learning to understand Java APIs and semantics is a lot of work, and it's turning people away from Clojure otherwise, now that's something worth discussing.

Re:Clojure needs a Rails by eduction on Saturday July 30, 2022 @08:56PM (#32292002)
Ya I hear you and agree with most all of this. I did choose Clojure in part because it had Java interop so on some level I knew I’d need to learn a bunch of Java and APIs to take advantage of that. I think it’s a great design decision but also am actually kind of a fan of wrappers - I think being able to use raw Java is great and sometimes the right choice but I also appreciate even the half baked wrappers sometimes. As to the original article I should probably read it :-) I was jumping into the discussion more to address this chip on my shoulder about wrappers.
Re:Clojure needs a Rails by seancorfield on Saturday July 30, 2022 @08:40PM (#32291890)
Just a nit-pick: clojure.java-time wraps Java's own _immutable_ java.time.* classes and it really doesn't provide much value add. I initially thought it did and introduced it at work but we're taking it out of a lot of our code now and using plain interop -- it's only slightly more verbose, it's already mostly "functional" in style, and it gives us more precise control over conversions between different types of date/time values.

Your main point about interop as a barrier to non-Java people is reasonable -- although if you learn a hosted language, you're going to have to learn stuff about the ecosystem on which it is hosted (so, not Java itself, but some of the JVM stuff and the docs for any libraries you interop with). And this is true of the JS ecosystem supporting ClojureScript (and the .NET ecosystem supporting ClojureCLR).

Re:Clojure needs a Rails by didibus on Saturday July 30, 2022 @08:59PM (#32292026)
> although if you learn a hosted language, you're going to have to learn stuff about the ecosystem on which it is hosted

I thought this at first, but then I thought if you take Python, which is hosted on the OS directly through CPython, so we can say Python is hosted on Windows or Linux.

Well it turns out, most people never need to interop directly with Windows or Linux APIs or any other C interop.

Python seems to have a different mindset here, where most of its value proposition are providing wrappers over C/Windows/Linux/Mac APIs.

Why does so much effort get put in maintaining all these wrappers in Python? Is it just attitude? Is it that those APIs are much worse then Java's enough that even C programmers using Python want to wrap them over using them directly?

Re:Clojure needs a Rails by schmudde on Thursday August 04, 2022 @03:01AM (#32340022)
This is the most illustrative analogy. I suppose the answer is a little bit of both.

Python numeric performance is a really interesting case. Those folks would certainly drop down to C. But my casual observation is that they would build the bridge when they came back above water. A lot of work went into this because Python performance has historically been quite bad for a Data Science/ML language.

Part of this is the size of the community.

But what is we also consider the Common Lisp community? Common Lisp is incredibly performant. A lot of work went into the underlying C libraries. Perhaps most of that was when the community was more vibrant. But still, a casual observation is that CL folk live in CL.

Re:Clojure needs a Rails by eduction on Saturday July 30, 2022 @08:48PM (#32291951)
Thanks, I’ll check out the raw java-time next time I have a minute.

You’re right about needing to learn some of the host in a hosted language. I’ve enjoyed for example Jsoup and I use some of the Math stuff inline with no issue. Even with the java time wrapper I’ve dropped down to the original to do certain things involving locales. I definitely knew going in to Clojure I’d need to pick up some Java.

Where I really like wrappers is where the underlying java API is not great in some way. (Which now that I’ve seen the original puredanger quote seems to be what he’s saying.)

Re:Clojure needs a Rails by janetacarr on Saturday July 30, 2022 @09:50PM (#32292395)
> Really it's not. The interop is a conscious decision core to the language rationale.

I'm aware. I was expressing an opinion to a twitter friend, but I should have foreseen the replies of some people taking my opinions as me promoting fact. That's my fault for not being clear.

Re:Clojure needs a Rails by huahaiy on Saturday July 30, 2022 @06:05PM (#32290821)
Clojure is intended as a hosted language and embracing the host is the philosophy, so interop with the host is never a bandage.

Again, I am curious where you get all these impressions that are contrary to most people in the community take for granted, such as:

* Clojurians prefer libraries over framework, but you said we spent too much effort in developing "big web framework".

* Clojure is intended to be a hosted language, so seamless interop with the host is the norm, but you thought interop is a bandage until Clojure matures.

It's very interesting.

Re:Clojure needs a Rails by mark_l_watson on Saturday July 30, 2022 @02:06PM (#32288906)
Janet, I hope I didn’t misquote him. I save his tweet, and I am going to look for it.
Re:Clojure needs a Rails by mark_l_watson on Saturday July 30, 2022 @02:10PM (#32288956)
“Idiomatic Clojure code calls Java libraries directly and doesn’t try to wrap everything under the sun to look like Lisp… Where Java isn’t broken, Clojure doesn’t fix it.”
Re:Clojure needs a Rails by fmakunbound on Saturday July 30, 2022 @02:55PM (#32289304)
Perhaps that stance has changed over time. In Clojure, there's the clojure.string namespace just functions wrapping java.lang.String methods https://clojuredocs.org/clojure.string
Re:Clojure needs a Rails by casion on Saturday July 30, 2022 @04:06PM (#32289824)
This is much more than "just wrapping". It allows strings to be used more readily with existing Clojure abstractions and/or allows idiomatic use without the need for being on guard to avoid reflection.

Notably, Alex didn't write this library and only has a minor contribution to it.

Re:Clojure needs a Rails by didibus on Saturday July 30, 2022 @08:07PM (#32291675)
There's two cases where you'll see pragmatic wrapping:

1. Higher order usage. When functions would really benefit from being used in a higher order way, passed around as values, you'll see some of the Java methods wrapped so they can more easily be used as such, since you can't use Java methods in a higher order way. This would count as "can do it better", and it's the case for clojure.string.

2. For portability with Clojurescript. This is a more recent thing, but as Clojurescript usage grows, and code reuse between backed and frontend more common, there are certain basic methods Java interop was totally fine with that now benefits from being wrapped. This is the case for clojure.math.

Re:Clojure needs a Rails by moomin on Saturday July 30, 2022 @04:15PM (#32289884)
I think the problem is that if you want to write code portable between clj and cljs, you’re gonna need a lightweight abstraction. With that said, I’m still not sure how exactly the maintainers feel about portable code, having written a portable http library.
Re:Clojure needs a Rails by janetacarr on Saturday July 30, 2022 @02:33PM (#32289156)
Thanks for the quote Mark, it's an interesting perspective.
Re:Clojure needs a Rails by fat_cantor on Sunday July 31, 2022 @09:07AM (#32295250)
I can confirm that a major impediment to learning Clojure is understanding where Java is and isn't broken.
Re:Clojure needs a Rails by puredanger on Monday August 01, 2022 @07:12PM (#32313315)
I think this is insightful and probably an unconscious bias of the core team (who have all used Java for decades) and have a good sense of that.
Re:Clojure needs a Rails by fithisux on Sunday July 31, 2022 @06:18AM (#32294576)
Very good piece of advice if there is no automated way.

For example you hand craft a wrapper for lib-version1. lib-version2 is released but you do not need it any more. So wrapper is outdated.

I prefer recipes to call other language code (or framework) instead of wrappers.

E.g. Call a C library from Dlang instead of waiting??? for some wrapper.

Re:Clojure needs a Rails by hyperhopper on Saturday July 30, 2022 @10:22PM (#32292564)
Why does he say this? I would think the opposite and in a professional environment I've gone in the other direction of regretting not writing _more_ wrappers for external libs.
Re:Clojure needs a Rails by waffletower on Saturday July 30, 2022 @02:04PM (#32288889)
You should take Alex's words contextually, and with a grain of salt. You can easily see his commits in this project, for example: https://github.com/cognitect-labs/aws-api
Re:Clojure needs a Rails by joe-user on Saturday July 30, 2022 @03:04PM (#32289382)
This library doesn't wrap the AWS SDK, explicitly calls out existing Clojure wrappers that do in the README, and none of his commits seem to conflict with the referenced Tweet. Am I missing something?
Re:Clojure needs a Rails by mark_l_watson on Saturday July 30, 2022 @02:05PM (#32288893)
Thanks, point taken!