For the Optics code-gen plugin, is there a reason ...
# arrow
s
For the Optics code-gen plugin, is there a reason for not using something like KotlinPoet today? I found some talk around KotlinPoet here in 2017, wondering if that's been revisited. I think it could make the generated code a little more human-readable by at least using imports instead of fully qualified names all over. https://kotlinlang.slack.com/archives/C5UPMM0A0/p1504594831000271
s
Oof, back to 2017 😅 Since no-one felt porting it to KotlinPoet is probably the shortest answer 😅 There has always been the ambition to turn it into a nice compiler plugin, with K2 finally stabilising it's finally a possibility but large-ish task to take on.. Seems peeks of something like this in the language have been mentioned so.. 🤞
s
Since no-one felt porting it to KotlinPoet is probably the shortest answer 😅
That's what I suspected. 😅
There has always been the ambition to turn it into a nice compiler plugin
I can see why that might be tempting, but I fear it'll make debugging more difficult. Part of why I personally want the generated code to be nicer is because I'm in there fairly often to see what's actually been generated.
s
Great point! Totally agree, but I wouldn't 1-on-1 port it, that would indeed not be worth it but the goal was to remove all allocations, and supporting more powerful DSLs i.e. for collections, etc.
a
I've had a look at it, but KotlinPoet does not provide any specific help for building the body of a function (https://square.github.io/kotlinpoet/code-control-flow/), which is the hardest part in this case as Simon has mentioned, our goal has always been to make it a compiler plugin once we see that K2 has stabilized
s
Yeah, the compiler plugin APIs definitely look more tailored to generate function bodies. But not being able to inspect the generated code would be a little annoying, at least for me.
Not that I don't trust the generated code to be correct, it's more that I want to understand how it's made so I can do similar things manually.