other-languages

here be heresies and things we have to use for work
borkdude 2016-10-21T12:38:24.000003Z

@cfleming I read this discussion: https://groups.google.com/forum/#!topic/clojure/Dxk-rCVL5Ss and of course wondered if you’d looked at Frege and/or Scala. Both require writing wrappers of course.

cfleming 2016-10-21T12:38:53.000004Z

@borkdude Frege is out because of laziness.

cfleming 2016-10-21T12:39:19.000005Z

Scala is out because of a) complexity and b) it doesn’t handle nulls from interop well.

borkdude 2016-10-21T12:39:31.000006Z

Scala is also lazy, but in a different way 😉

cfleming 2016-10-21T12:39:47.000007Z

That would be c) then 🙂

borkdude 2016-10-21T12:40:05.000008Z

The compiler is JTL

cfleming 2016-10-21T12:40:14.000009Z

Basically, Kotlin works better for me than Scala

cfleming 2016-10-21T12:40:16.000010Z

JTL?

borkdude 2016-10-21T12:40:21.000011Z

Just Too Late

cfleming 2016-10-21T12:40:27.000012Z

Ah

borkdude 2016-10-21T12:40:40.000013Z

I’m kidding. So, why not Kotlin then?

cfleming 2016-10-21T12:41:27.000014Z

That’s pretty much what I’m doing. The problem is that the more Kotlin I write, the less Clojure I write, and I need to be dogfooding.

borkdude 2016-10-21T12:41:28.000015Z

Btw, most of my null pointers come from misspelling Clojure keywords. But yeah, when you’re doing a lot of Java interop, I can see your problem. But wouldn’t you have those problems in Java as well?

cfleming 2016-10-21T12:42:54.000018Z

This is a discussion I’ve had a couple of times - I don’t believe the NPEs are because I’m using interop. I think it’s more relevant that I’m programming against a large codebase that I don’t understand.

cfleming 2016-10-21T12:43:35.000019Z

And I find that Clojure makes it harder to track down NPEs than Java - in Java the NPEs tend to be closer to the source of the problem.

borkdude 2016-10-21T12:43:48.000020Z

I guess writing against code you don’t understand requires handling ‘Nothing’ cases in other languages as well after the fact?

borkdude 2016-10-21T12:43:53.000021Z

Yes, definitely

cfleming 2016-10-21T12:43:53.000022Z

nil punning in Clojure works against me here.

borkdude 2016-10-21T12:45:22.000023Z

I guess libraries like seesaw would be in the same place

cfleming 2016-10-21T12:45:34.000024Z

Well, in Kotlin that’s implicit. Types that come back from Java are known as “platform types”, and are written as String! (String is non-null and String? is nullable). You can’t write platform types yourself, but when looking at the type of something you’ll see them.

borkdude 2016-10-21T12:45:55.000025Z

that’s convenient

cfleming 2016-10-21T12:46:23.000026Z

You can assign a platform type to either a nullable or non-null Kotlin variable. If you assign it to a non-null one, Kotlin will implicitly add a nullability assertion at that point.

cfleming 2016-10-21T12:46:56.000027Z

So you’ll get an NPE but right at the source (platform types cannot escape the function you made the interop call in).

cfleming 2016-10-21T12:48:25.000028Z

The compiler enforces that you cannot dereference non-null variables, and also uses flow typing to make things easier.

cfleming 2016-10-21T12:48:27.000029Z

So here:

cfleming 2016-10-21T12:49:26.000030Z

String? x = <something>
if (x == null)
  // x is null here
else
  // x is String (not String?) here.

borkdude 2016-10-21T12:50:19.000031Z

Writing some interop macros with assertions does not do the trick?

cfleming 2016-10-21T12:50:48.000032Z

Scala doesn’t have this and it’s really convenient. You’d get something similar with pattern matching over Option, but there’s more ceremony involved.

cfleming 2016-10-21T12:51:26.000033Z

Another nice thing about Kotlin’s null types is that they add no runtime overhead - Option requires more instances to be created every time you make an optional call.

cfleming 2016-10-21T12:51:46.000034Z

Perhaps, but I make a lot of interop calls.

borkdude 2016-10-21T12:52:14.000035Z

I guess rewriting some of the core interop macros would help, but not as fundamental

borkdude 2016-10-21T12:52:41.000036Z

Anyway, I just wanted to hear you on Frege/Scala. Thanks!

cfleming 2016-10-21T12:53:10.000037Z

To answer your earlier question - yes, Seesaw probably suffers from this as would any Clojure code written against a large Java codebase. But this is one of the key use cases for Clojure - not everyone is writing webapps.

cfleming 2016-10-21T12:53:24.000038Z

Interop is supposed to be idiomatic.

borkdude 2016-10-21T12:54:24.000039Z

I guess this is an area that could really be improved. Thanks and see you around at EuroClojure probably.

cfleming 2016-10-21T12:54:38.000040Z

Yes, definitely - looking forward to it!

arrdem 2016-10-21T21:02:10.000041Z

You can't just rewrite the interop macros tho, because you have to figure out the type of the method you're calling (if you can even do that, reflection) then emit each argument, check if it's nil, generate an appropriate empty T for any nil value and then invoke the method.

arrdem 2016-10-21T21:02:12.000042Z

It'd be nuts.