Groovy coding agreement?

What is the standard coding convention for Groovy?

In Java, the method name is executed using the camel notation.

public void calculateTotal() {} 

In Ruby, which Groovy builds on, underlining is preferred.

 def calculate_total() end 

Which of these two styles will be considered more Groovyist?

Personally, I am more likely to use the Ruby style. Is there a standard standard / general consensus among the Groovy community regarding which is preferable?

+6
source share
1 answer

First. Groovy took a lot from Ruby, but its main goal is a dynamic and powerful language that plays well with Java. Therefore, most Java coding conventions and coding styles apply also to Groovy.

About naming conventions, while I also prefer the underscore_separated_words style for Ruby / Python and others, I believe that sticking to the convention and keeping the environment is much more important than personal preferences in these types of unnecessary questions (there are other things, for example, preferring a functional style over imperative constructions or vice versa, which, I think, is more interesting to discuss :).

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

Finally, here is a diagram of Groovy coding rules . It has no mention of conventions or formatting, but it introduces many of Groovy's strong syntactic additions and explains when they prefer to use them :)

+10
source

All Articles