Option to "inline" dependencies in generated Java code

87 views
Skip to first unread message

Lukas Eder

unread,
Nov 11, 2012, 8:19:21 AM11/11/12
to xtend...@googlegroups.com
Hello,

I have recently evaluated Xtend as a possible platform for source code generation in jOOQ (http://www.jooq.org), eventually replacing jOOQ's current home-grown code generator. The advantages of using Xtend over simple string concatenation are obvious. Xtend has solved templating really nicely using:

- Multi-line strings
- Expressions within templates
- Conditions and loops within templates
- Elegant whitespace handling

However, Xtend (unfortunately, in my opinion) went much farther than that. The two main reasons why I have not adopted Xtend (so far) are these:

1. Xtend as a language isn't really Java
2. Xtend creates runtime dependencies from generated Java code

Let me explain:

1. Using Xtend in jOOQ's code generator would mean that jOOQ users wanting to change the code generator would have to learn a new syntax which somewhat resembles Java, Scala and Groovy, but is neither one of them. If Xtend would implement much of the JLS, Xtend could be better promoted, IMO. I understand that adding extension methods, lambda expressions, operator overloading, etc. makes Java a better language, long before Java 8. But, without knowing the internals of Xtend, I think that these additions don't have to be done at the cost of writing actual Java. Are there plans of bringing just multi-line strings and templating to Java through "Xtend light", which doesn't drastically change the Java language? Personally, I would love to see this working along the lines of the Java 8 syntax...

2. This would probably be easy to "fix". The runtime library is very slim, wouldn't it make sense to add an option to inline its source code along with the generated artefacts? If Xtend-generated code didn't have any external dependencies, I might re-evaluate adopting Xtend for jOOQ's code generator.

On the other hand, I have started using Xtend to generate the repetitive parts of the jOOQ API. I really have to say again, multi-line string templating has been really well done!

Cheers
Lukas

Sven Efftinge

unread,
Nov 11, 2012, 12:35:57 PM11/11/12
to xtend...@googlegroups.com
Hi Lukas,

On Nov 11, 2012, at 2:19 PM, Lukas Eder <lukas...@gmail.com> wrote:
> Let me explain:
>
> 1. Using Xtend in jOOQ's code generator would mean that jOOQ users wanting to change the code generator would have to learn a new syntax which somewhat resembles Java, Scala and Groovy, but is neither one of them.

I don't know what kind of extension pattern you provide, but your users should be able to just use Java, Scala, or Groovy if they think those langs work better for them. After all you end up with Java classes.

> If Xtend would implement much of the JLS, Xtend could be better promoted, IMO. I understand that adding extension methods, lambda expressions, operator overloading, etc. makes Java a better language, long before Java 8.

and Java 12 ;-)

> But, without knowing the internals of Xtend, I think that these additions don't have to be done at the cost of writing actual Java. Are there plans of bringing just multi-line strings and templating to Java through "Xtend light", which doesn't drastically change the Java language? Personally, I would love to see this working along the lines of the Java 8 syntax…

No plans, but I also don't think that we drastically changed what's in Java. We left some things out and there are four or five real syntactical differences you have to know. But beyond that it's just very useful extensions you don't want to loose again as soon as you got used to it (template expressions being one of them).

> 2. This would probably be easy to "fix". The runtime library is very slim, wouldn't it make sense to add an option to inline its source code along with the generated artefacts? If Xtend-generated code didn't have any external dependencies, I might re-evaluate adopting Xtend for jOOQ's code generator.

We don't have concrete plans in that direction yet, since without the libraries and extensions a lot of the advantages of Xtend would get lost.
For Java 8 some of that functionality will be covered in JDK, so we might come with a slimmer variant then.

If having the additional jars is really so problematic, why don't you just include the classes into your jar?


> On the other hand, I have started using Xtend to generate the repetitive parts of the jOOQ API. I really have to say again, multi-line string templating has been really well done!

I hope you'll enjoy the other features as well some day :-)

Cheers,
Sven

Reply all
Reply to author
Forward
0 new messages