Fork me on GitHub
#clojure-uk
<
2019-04-24
>
jasonbell06:04:16

I like Java interop. It’s saved me a number of times.

otfrom07:04:22

java interop is what made clojure the only other usable lisp for me (the other one being emacs lisp)

otfrom07:04:02

I'd had a go w/scheme and common lisp but always failed when trying to do the things I needed to do (json, xml, databases, etc). This was a number of years ago tho. Things have probably gotten better.

rickmoynihan07:04:43

Java Interop is ace - a million times better than say FFI in Ruby, Python or anything else…

jasonbell08:04:05

Always makes me smile everyone giving off about Java and Java Interop, then use libraries which are basically wrapping Java code 🙂

maleghast08:04:18

Yeah, I think Interop with Java is basically effing awesome, in terms of what it unlocks. I used Java Interop with JRuby as well before Clojure and got the same impression from some in the Ruby community that I was doing something dirty, but honestly it just made sense.

rickmoynihan08:04:54

Yeah JRuby interop was pretty good too… I did some pretty hairy bi-directional interop things with that about about 15 years ago, but the fact it worked was nothing short of a miracle. Their hands are somewhat tied by Ruby not being designed to do java interop in the first place though.

mccraigmccraig08:04:36

i also have fond memories of jruby interop - it helped us move from a java-based web stack to a mixed jruby/MRI+rails based stack (jruby in prod, MRI for dev, almost never encountered any painful differences) which was something of a breath of fresh air

maleghast08:04:48

@jasonbell showed me how to solve a recent problem of my own using Interop and it was soooooo neat.

maleghast08:04:18

Overall I think that people tend towards the precious and opinionated in order to stand out and "have something to say" more than actually__ having found something onerous or difficult or even not to their taste, but then I am and always have been a settler and a people-pleaser so maybe I am just a pushover 😉

practicalli-johnny08:04:08

You are a cuddly teddy bear and we love you 😀

jasonbell09:04:12

When we are in a position not to reinvent the wheel…. take it.

practicalli-johnny11:04:55

Lots of Clojure code in this next talk for London Clojurians on the 7th May @ SkillsMatter in London. Nathan will give a very practical talk on using Clojure with Blockchain smart contracts and the DAML open source library. I hope you will be able to join us https://skillsmatter.com/meetups/11772-london-clojure-may

Wes Hall11:04:10

We might be being slightly hard on Mr Cutler from the above link re: Java interop. The biggest "problem" with platform interop in Clojure is that it can be a little too easy. I use it quite a lot (often preferring to chat to underlying Java SDKs for things like AWS than work with the existing Clojure abstractions), but you do have to remember that you are dealing with a very different approach to fundamental things like state management. It's quite easy to look at some piece of interop and think, "Hey, this is just like any other Clojure s-exp.... neat...!". Only it's not... and might bite you 🙂

Wes Hall11:04:13

Given that I have done 15 or so years of pure Java development, before coming to Clojure, I feel pretty comfortable working with the Java SDK in a different syntax, but I have seen one or two examples of people who have Clojure as their "first language" (lucky them!!), who definitely find making the cognitive switch to Java's more traditional approach to data structures a bit more difficult to grok.

Wes Hall11:04:50

A general rule of, "If you have done plenty of pure Java before, you'll be comfortable enough with interop. If not, maybe have a quick chat with somebody who has!", is a fairly good one. For my part, I find Java interop easy, but Javascript interop far far far less intuitive, because Javascript is stupid 😉.

practicalli-johnny11:04:29

(js/Date.) is easy... I am still looking for other useful JavaScript interop 🙂

practicalli-johnny11:04:49

Oh, there are rumours of a sponsored bar at our monthly talk in May https://www.meetup.com/London-Clojurians/events/260694744/

Wes Hall11:04:14

@jr0cket It can get fairly fun if you want to include existing JS libraries either via cljsjs packages or direct from scripts. I spent rather a lot of time recently trying to get the GraphIQL react component working properly in Clojurescript. The cljsjs package doesn't seem to work at all (I think it's old), and then there are different ways to pull in the code. Do I add a script tag to my page and use interop to set it all up? What about the foriegn-libs capability of the clojurescript compiler? NPM? All these things work differently, load in different orders etc. Let's just say it's a good thing I am bald already 😉

Wes Hall11:04:26

Also, with respect to state management, clojure is on one extreme of the spectrum and JS is on the other... with Java somewhere in the middle. The prevailing, "Hey! Let's just add everything as a property of the `Window' object! Globals are brilliant and nobody has ever questioned them!", attitude of Javascript really adds to the experience 😉

mccraigmccraig12:04:42

one thing i do like about js-land - the lack of a global namespace forced modules to be first class and to use closures for info hiding - leading to it being largely fine to have multiple versions of a library loaded simultaneously, and a practical solution to the dll/jar-hell problem

dominicm12:04:07

@wesley.hall I disagree regarding the requirement for knowing java to decide whether to interop. I don't know any java and I find interop reasonably fine.

Wes Hall12:04:53

@dominicm I suppose it depends a bit on what you are doing. Quite a lot of the basic classes in the Java SDK are, for example, not thread-safe. This probably doesn't matter too much if you are just instantiating things within functions or calling static methods, but if you go much beyond that. For example, using Java interop in conjunction with things like atoms... you really need to have quite good understanding of the characteristics of the code you are happily chatting away with. While you are using Java interop, you are in the role of, "Java Developer" essentially. You might be using a different syntax but all of the things you would need to know to build reliable software in the Java language apply equally in Clojure. Most Java interop you are likely to write will be extremely simple... but there be dragons if you go much further.

Wes Hall12:04:46

It's worth looking at the Java code side of the Clojure library to get some idea of what it really takes to build a reliable bridge between these two worlds. Rich et al had to build, essentially, a defensive layer over a whole bunch of Java stuff to make the Clojure side of the core library interop behave in a sensible way. You have all the same problems they did when you do any complex piece of interop.

dominicm14:04:16

@wesley.hall my approach to java is to instantiate everything all the time, so I always have fresh classes.