Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groovy coding conventions? [closed]

Tags:

java

ruby

groovy

What is the standard coding convention for Groovy?

In Java the method naming is done using camel case notation.

public void calculateTotal() {}

In Ruby on which Groovy is based, underscores are preferred.

def calculate_total()
end

Which of the above two styles would be considered more Groovyist?

Personally I'm more inclined to use the Ruby style. Is there a standard document/general consensus among the Groovy community as to what is preferable?

like image 779
Kshitiz Sharma Avatar asked Jan 26 '13 06:01

Kshitiz Sharma


People also ask

What are closures in Groovy?

A closure in Groovy is an open, anonymous, block of code that can take arguments, return a value and be assigned to a variable. A closure may reference variables declared in its surrounding scope.

What does == mean in Groovy?

Behaviour of == In Java == means equality of primitive types or identity for objects. In Groovy == translates to a. compareTo(b)==0, if they are Comparable, and a. equals(b) otherwise.

Is Groovy a Camelcase?

What is the standard coding convention for Groovy? In Java the method naming is done using camel case notation. In Ruby on which Groovy is based, underscores are preferred.

Is Groovy faster than Java?

Generally speaking, Groovy will be slower. You can avoid that by switching to Groovy++ which offers most of the features of Groovy, but can be statically compiled and has performance comparable to Java.


1 Answers

The first one. Groovy took a lot from Ruby, but its main focus is to be a dynamic and powerful language that plays well with Java. Therefore, most Java coding conventions and coding styles apply to Groovy as well.

About naming conventions, while I also prefer the underscore_separated_words style of Ruby/Python and others, I think sticking to convention and being consistent with the surrounding environment is much more important than personal preference in these kind-of-superfluous matters (there are other things, like preferring a functional style over imperative constructs or vice versa, that I think are more interesting to discuss :).

So, always use camelCasing for Groovy methods. The Groovy documentation uses them; all the methods from the standard library use them.

Finally, here's a nice Groovy coding conventions guide. It doesn't do any mention about naming conventions or formatting, but it introduces many of Groovy's nice syntactic additions and explains when it's preferred to use them :)

like image 170
epidemian Avatar answered Oct 04 '22 09:10

epidemian