Live data from Hacker News

Manifold: Java Type-Safe Metaprogramming, Structural Typing, Extension Methods

github.com

11–20 of 44 posts

Re: Manifold: Java Type-Safe Metaprogramming, Structural Typing, Extension Methods

#11
post #8

I thought I knew all about Java, but this thing makes me feel like I haven't got a clue! How can it achieve this stuff by just being in the classpath?? No Java agent can be involved, no codegen during the build?! This shouldn't be possible, or??

Ok just checked this deeper. The [docs](http://manifold.systems/docs.html) actually show this is a javac plugin (I didn't know about the `-Xplugin` flag, but you ALSO need to pass that to javac for Manifold to work)... you also need the `tools.jar` file (which includes the JavaCompiler) on the runtime classpath... so suddenly, there's no magic... it's a bit misleading to say this does not require a build step, it clearly does, but as it integrates with javac itself, it "feels" seamless...

Re: Manifold: Java Type-Safe Metaprogramming, Structural Typing, Extension Methods

#12
post #8

I thought I knew all about Java, but this thing makes me feel like I haven't got a clue! How can it achieve this stuff by just being in the classpath?? No Java agent can be involved, no codegen during the build?! This shouldn't be possible, or??

See my earlier comment re javac plugin API, Manifold uses that as a means to hook into the compiler.

Probably the most interesting aspect of Manifold is its role as a type name resolver for the compiler. Manifold provides an API to dynamically resolve types corresponding with, well anything, but mostly with resources like JSON files, GraphQL schemas, SQL, DDL, CSV, scripting languages, you name it. So from the compiler's perspective it has no idea what is going on beyond normal type name resolution, but the source files it's loading up are coming from deep, dark places ;)

But yeah, no code generation step in your build, no agents, no custom class loaders, etc.

Re: Manifold: Java Type-Safe Metaprogramming, Structural Typing, Extension Methods

#13
post #11
post #8

I thought I knew all about Java, but this thing makes me feel like I haven't got a clue! How can it achieve this stuff by just being in the classpath?? No Java agent can be involved, no codegen during the build?! This shouldn't be possible, or??

Ok just checked this deeper. The [docs]( http://manifold.systems/docs.html ) actually show this is a javac plugin (I didn't know about the `-Xplugin` flag, but you ALSO need to pass that to javac for Manifold to work)... you also need the `tools.jar` file (which includes the JavaCompiler) on the runtime classpath... so suddenly, there's no magic... it's a bit misleading to say this does not require a build step, it c…

There's a significant difference between a code gen build step and what Manifold is doing with javac. Resource files are virtual source files, this represents a leap in terms of dev productivity.

Re: Manifold: Java Type-Safe Metaprogramming, Structural Typing, Extension Methods

#14
post #11
post #8

I thought I knew all about Java, but this thing makes me feel like I haven't got a clue! How can it achieve this stuff by just being in the classpath?? No Java agent can be involved, no codegen during the build?! This shouldn't be possible, or??

Ok just checked this deeper. The [docs]( http://manifold.systems/docs.html ) actually show this is a javac plugin (I didn't know about the `-Xplugin` flag, but you ALSO need to pass that to javac for Manifold to work)... you also need the `tools.jar` file (which includes the JavaCompiler) on the runtime classpath... so suddenly, there's no magic... it's a bit misleading to say this does not require a build step, it c…

Note tools.jar is needed only for Java 8, and only for compile-time, unless you use Manifold's dynamic loading feature. The JREs for Java 9+ bundle what used to be called tools.jar.

Re: Manifold: Java Type-Safe Metaprogramming, Structural Typing, Extension Methods

#16
post #11

Earlier quoted context omitted.

Ok just checked this deeper. The [docs]( http://manifold.systems/docs.html ) actually show this is a javac plugin (I didn't know about the `-Xplugin` flag, but you ALSO need to pass that to javac for Manifold to work)... you also need the `tools.jar` file (which includes the JavaCompiler) on the runtime classpath... so suddenly, there's no magic... it's a bit misleading to say this does not require a build step, it c…

There's a significant difference between a code gen build step and what Manifold is doing with javac. Resource files are virtual source files, this represents a leap in terms of dev productivity.

Yes, I agree... just wished they made it clearer how they achieve that!

Re: Manifold: Java Type-Safe Metaprogramming, Structural Typing, Extension Methods

#17
post #7

This is what I wanted all my life! I wonder what kind of dark magic makes this go and how this will come back to bite me if I use it?

Manifold hooks into the Java compiler via the javac plugin API. This is similar to the way annotation processors work, but without the overhead of additional passes (or rounds) in the compiler. The plugin route also provides access to earlier stages of the compiler, for example this is how Manifold's string interpolation feature works. The overall details are a bit deep and dark for a comment, however ;)

I've played with the compiler's API before and found it incredibly difficult to work with... and completely undocumented... how did you manage to get through that? Great job!

Re: Manifold: Java Type-Safe Metaprogramming, Structural Typing, Extension Methods

#18
post #6

At that point, why not just use another jvm language with these features like Kotlin?

the main feature of this allows you to transparently use structured data as types in your code like type providers in .net. I love kotlin but it can't do anything remotely like that.

Yep, I'm wondering if this actually works in Kotlin as well. I'm thinking it may probably play nice with this as is since Kotlin can interact with Java classes. However, the compiler plugin might be a problem. If so, this would be an awesome thing to add to Kotlin.

Re: Manifold: Java Type-Safe Metaprogramming, Structural Typing, Extension Methods

#19
post #16

Earlier quoted context omitted.

There's a significant difference between a code gen build step and what Manifold is doing with javac. Resource files are virtual source files, this represents a leap in terms of dev productivity.

Yes, I agree... just wished they made it clearer how they achieve that!

The documentation is a bit handwavy on how it works indeed. Just drop a jar file in the code doesn't quite tell the whole story. However, I'm impressed with how amazingly awesome this stuff is. A lot of the stuff it does is already in Kotlin but being able to use json and property files without boiler plate code is nice. I'd like to be able to do that in Kotlin as well.
Post reply on HN