any differences between using gremlin in Java and in groovy?

179 views
Skip to first unread message

fancyerii

unread,
Aug 4, 2014, 8:19:34 AM8/4/14
to gremli...@googlegroups.com
hi all,
    I am not familiar with groovy and want to stick to java. in this wiki(https://github.com/tinkerpop/gremlin/wiki/Using-Gremlin-through-Java),
it says "The best way to integrate Gremlin Groovy into a larger Java project is via Groovy/Java class interactions"
    why for larger java project, groovy is better? development speed or execution speed?
    for now, I am using the method of compiling gremlin:
Graph graph = TinkerGraphFactory.createTinkerGraph();
Pipe pipe = Gremlin.compile("_().out('knows').name");
pipe.setStarts(new SingleIterator<Vertex>(graph.getVertex(1)));
for(Object name : pipe) {
  System.out.println((String) name);
}

Stephen Mallette

unread,
Aug 4, 2014, 8:32:44 AM8/4/14
to gremli...@googlegroups.com
If you don't have specific requirements against groovy, mixing groovy/java works really well.  If you use maven it's really easy to do with gmavenplus plugin or the groovy eclipse compiler.  You can seamlessly have groovy and java code in the same project which allows you to use the flexibility of groovy when needed (e.g. for writing Gremlin natively) while still getting your standard Java that you are more familiar with.  I'd prefer that approach over embedding groovy strings all over your project.  

If all your Gremlin looks like:

_().out('knows').name

then maybe a few strings are not a big deal, but when you get to a "larger" project with really complex traversals, you probably don't want to have a gremlin string 100+ lines long in your code.  I would also assume that dynamic compilation of groovy strings is less performant than compiled groovy, though i don't have numbers to support that offhand.

At the end of the day, not being familiar with Groovy is not a good reason to stick to Java.  To write really concise and idiomatic Gremlin, you will need to know groovy, so you may as well start learning. :)

Stephen


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/5c47a705-4e2b-451b-a7f0-22d084a48bac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Kuppitz

unread,
Aug 4, 2014, 8:49:26 AM8/4/14
to gremli...@googlegroups.com
At the end of the day, not being familiar with Groovy is not a good reason to stick to Java.  To write really concise and idiomatic Gremlin, you will need to know groovy, so you may as well start learning. :)

Full ack. Besides that you can simply rename a .java file into .groovy and it will just work. You only need to use specific Groovy features where it's really needed, e.g. for your Gremlin traversals.

Cheers,
Daniel



fancyerii

unread,
Aug 4, 2014, 9:31:02 PM8/4/14
to gremli...@googlegroups.com
thank you. But I still a little bit confused. As in the introduction of gremlin, it's something like SQL(and blueprint like JDBC). So In my option, no matter what language client use, the query language will be the same. e.g. No matter I am using java or c#, I write the same sql query language and send it by java or c# driver to mysql. 

Stephen Mallette

unread,
Aug 4, 2014, 10:04:12 PM8/4/14
to gremli...@googlegroups.com
Maybe someone else can explain this better than I can....please feel free to expand on my explanation here...

We like to use the analogy of Blueprints being JDBC and Gremlin being like SQL because it helps people understand the different parts of the stack.  However, that does not mean that they can be exactly likened in terms of their operations.  Sure, when you do:

Pipe pipe = Gremlin.compile("_().out('knows').name");

you are writing code in Java, but you are essentially dynamically compiling a Groovy code string to a Pipe.  So, even though you are writing Java code, you are still evaluating a Groovy string.  If you are evaluating a Groovy string then you need to know Groovy to write the string.  If you're going to write a Groovy string, it's probably better to just create a groovy project (or a mixed Java/Groovy project) as you gain intellisense from your IDE, improved performance of your traversals, compile time errors, etc....basically  you will be more productive than dealing with strings of groovy.






Reply all
Reply to author
Forward
0 new messages