Questions tagged [groovy]

Groovy is a Java-based "next generation" programming language designed to improve Java while adding popular features from Smalltalk, Python and Ruby. Groovy syntax is a super-set of Java which allows Java developers to begin coding in Groovy as they learn it. Groovy is fully object-orientated, dynamic and seamlessly integrates with Java. Market-wise, the success of Groovy is anybody's guess. Main competitors are Ruby, Scala and Closure.

Filter by
Sorted by
Tagged with
1 vote
2 answers
69 views

Test-doubling a file path in Java/Groovy

I am trying to write a unit test for a helper method in my ApiRequestHandler which handles APIGatewayProxyRequestEvent . This class uses an EFS file path, which is where it writes files to. I have ...
Mike Warren's user avatar
2 votes
2 answers
140 views

Is the process of building a model from a dictionary necessarily the builder pattern?

I am working on a tool that scrubs Do-Not-Call (DNC) phone records from a skip-traced CSV file. I have this PhoneModel for child phone entries for each row. It consist of the following fields: isDNC ...
Mike Warren's user avatar
0 votes
0 answers
101 views

Is it a code smell to have to query a dictionary for a key whose value matches some criteria?

I am working on a ChildModelListSheetHandler, that has a childModelListDict. As what you're probably thinking, it maps the foreign keys that are the IDs of the parent models, to the list of child ...
Mike Warren's user avatar
-1 votes
2 answers
187 views

Is it a code smell to put selection strategy concerns in an enum class?

Right now, I have this enum, called MemberCategory, defined to be: public enum MemberCategory { MEMBERSHIP("Membership"), GOLD_MEMBERSHIP("Gold"), SILVER_MEMBERSHIP(&...
Mike Warren's user avatar
1 vote
2 answers
354 views

How to design a process and use the business rules for sending alerts/notifications

Currently working on designing a process which demands me to send alerts like email notifications to the users which meet a business criteria(we can also call business rules). I want to make this ...
Brooklynn99's user avatar
2 votes
2 answers
158 views

Is it clean to place method for comparing 2 objects of same class into that class?

Let's say I have class Car (just for illustration) class Car { ... boolean isRed(); ... } where to place methods which acts with objects of same class, in my example Car, but not just on ...
Július Marko's user avatar
0 votes
0 answers
1k views

Are groovy automatic getters and setter effectively any different to public variables?

To provide a very blunt example (as I am at work and can't currently think of a sensible example). If I write a groovy class like this class Wendy{ byte[] frank String doSomethingWithFrank(){...
WendyG's user avatar
  • 133
1 vote
3 answers
122 views

POLA, Constructor and Getters

As a followup to this question and one I asked a while ago, suppose if I had an Author class structured like this: class Book { private String title; private Set<Author> authorsSet; ...
user avatar
1 vote
3 answers
692 views

Is calling .sort() in the constructor a violation of the guideline that a constructor shouldn't do work?

Suppose I have the following List to hold a list of fruits. Example: def fruits = ["Apple", "Orange", "Grapes"] def fruitsBowl = ["Apple", "Grapes", "Orange"] // Will print false println(fruits....
user avatar
2 votes
2 answers
320 views

Highlighting importance of order when using short-circuited conditions

I was working on a piece of code when I noticed that an if statement could work or crash depending on the order used for the parts connected with and. You can replicate the problem like this: ...
AK_is_curious's user avatar
13 votes
1 answer
1k views

What does 'syntax vinegar' mean

I was reading through Groovy in Action, Second Edition and on a footnote, I found the following text Java pours “syntax vinegar” over such a construct to discourage programmers from using it. What ...
isuru-buddhika's user avatar
1 vote
1 answer
218 views

Does Groovy/Grails have code completion/pre-runtime error detection/find refrences like Java?

I have been using Java for a while and PHP recently. Some things I miss from Java is Code completion suggestions from the IDE Error detection before runtime Find places where a method/function is ...
Can't Tell's user avatar
  • 1,161
1 vote
0 answers
98 views

Updating class property inside the method vs. returning a value from the method

In a large code base, what is a good practice between: Updating class properties inside the method vs. returning a value from the method and updating the property in the place where the call to the ...
Omnipresent's user avatar
29 votes
2 answers
22k views

When to use def in Groovy?

I have been developing in Groovy for a little while now and I'm wondering how often I should be using the dynamic casting def? A co-worker of mine believes we should use it always as it helps Groovy ...
PJT's user avatar
  • 393
-1 votes
1 answer
15k views

Groovy date/time compare [closed]

I have this string got from JIRA as the date/time I need to compare which one is earlier:"21/Sep/12 2:01 PM". How can I do this in Groovy? Thanks Jirong
user1288329's user avatar
2 votes
2 answers
143 views

Method for all objects for checking conditions which also includes method chaining and avoiding variables

(I am currently using groovy but it should apply to most OO languages so I also put the langauge-agnostic tag) I try to program in a function style which also includes method chaining and avoiding ...
valenterry's user avatar
  • 2,429
4 votes
1 answer
6k views

Converting cron schedule to time intervals

I have, on the server, many jobs defined by users and some of those jobs are scheduled using cron expressions. I need to check (I can execute Groovy/Java on the server) if those jobs take longer than ...
Erki M.'s user avatar
  • 141
12 votes
1 answer
9k views

Traits, Inheritance and Interfaces in Groovy, when to use them?

I'm learning groovy and I've just learned about the new feature added in 2.3, which is the addition of Traits. Now to me it seems like Traits allow you to do basically everything a super-class and an ...
Ryan Stull's user avatar
3 votes
2 answers
2k views

Speed difference between VM-based and compiled code [closed]

Not so long ago I was told by a senior academic that, these days, VM-based code could run nearly as fast as compiled code, but my own experience is that compiled code runs several orders of time ...
adrianmcmenamin's user avatar
2 votes
1 answer
366 views

Moving business logic from services to classes?

I have a Grails application with a number of services that are starting to get very large. The flow in the majority of my service methods is Database read (Returns DBCursor from MongoDB) Iterate ...
Travis's user avatar
  • 135
1 vote
1 answer
2k views

Best practice for comments above methods in a grails application?

I'm writing a grails application and am not sure what the best practice is with regard to comments outside of method blocks. I've done a bit of research and there seems to be conflicting views on how ...
Travis's user avatar
  • 135
24 votes
4 answers
12k views

Make methods that do not depend on instance fields, static?

Recently I started programming in Groovy for a integration testing framework, for a Java project. I use Intellij IDEA with Groovy plug-in and I am surprised to see as a warning for all the methods ...
Random42's user avatar
  • 10.4k
76 votes
3 answers
36k views

What is the difference between a Future and a Promise?

What is the difference between a Future and a promise? (In Akka and Gpars.) They look the same to me as both block and return the value of the future when get is called and a promise is to get the ...
Suminda Sirinath S. Dharmasena's user avatar
5 votes
2 answers
1k views

What's the computational complexity of the Groovy unique() method?

Question 1 What's the computational complexity of the Groovy unique() method? Question 2 How could I have figured it out by myself? The unique() method is defined in the class DefaultGroovyMethods. ...
Lernkurve's user avatar
  • 837
4 votes
2 answers
3k views

Testing Java as Groovy

We're looking into improving our testing process for some of our applications, and the idea that's been put forward it to write unit tests in Groovy and automatically run them with Maven. The first ...
FrustratedWithFormsDesigner's user avatar
9 votes
4 answers
3k views

What's special about currying or partial application?

I've been reading articles on Functional programming everyday and been trying to apply some practices as much as possible. But I don't understand what is unique in currying or partial application. ...
Vigneshwaran's user avatar
3 votes
2 answers
441 views

New insights I can learn from the Groovy language

I realize that, for a programmer coming from the Java world, Groovy contains a lot of new ideas and cool tricks. My situation is different, as I am learning Groovy coming from a dynamic background, ...
Andrea's user avatar
  • 5,365
15 votes
4 answers
3k views

Does groovy call partial application 'currying'?

Groovy has a concept that it calls 'currying'. Here's an example from their wiki: def divide = { a, b -> a / b } def halver = divide.rcurry(2) assert halver(8) == 4 My understanding of what's ...
Richard Warburton's user avatar
26 votes
3 answers
36k views

When to write an explicit return statement in Groovy?

At the moment I am working on a Groovy/Grails project (which I'm quite new in) and I wonder whether it is good practice to omit the return keyword in Groovy methods. As far as I know you have to ...
Roland Schneider's user avatar
4 votes
3 answers
204 views

What class structure allows for a base class and mix/match of subclasses? (Similar to Users w/ roles)

I have a set of base characteristics, and then a number of sub-types. Each instance must be one of the sub-types, but can be multiple sub-types at once. The sub-types of each thing can change. In ...
cdeszaq's user avatar
  • 322
0 votes
1 answer
2k views

What's the best practice for rendering a different GSP template based on the type of object in a collection?

Let's say I have a collection that is setup in my controller, named "things." In this collection is a heterogeneous assortment of objects. Let's say some are of type "Thing" and some others are of ...
mindcrime's user avatar
  • 520
15 votes
1 answer
430 views

Does Groovy follow Tennent's Correspondence Principle?

Here's an interesting discussion of Tennent's Correspondence Principle, and a brief description from Neal Gafter: The principle dictates that an expression or statement, when wrapped in a closure ...
Armand's user avatar
  • 6,508
30 votes
5 answers
26k views

Is Groovy going away? [closed]

I am sure this question has been asked many times. However, I like to ask it again with the intention of what is the future of these languages. I was first introduced to Groovy and really liked it. I ...
Amir Raminfar's user avatar
7 votes
2 answers
2k views

How difficult would it be to migrate a Struts/JSP application to Groovy?

I have taken over development of a JSP/Struts application. Right now it's a bit of a mess, and I'm finding the JSP pages with Struts tags to be insanely verbose. Has anyone migrated a Struts ...
kevin cline's user avatar
  • 33.6k
9 votes
5 answers
4k views

Is there a clear leader amongst JVM-based languages? [closed]

What is the current status of these projects, and has any one (or two) emerged as a clear leader? To demonstrate my motives for asking this question, cast your mind back several years. Prototype and ...
rinogo's user avatar
  • 217
12 votes
5 answers
1k views

Pitfalls in the Grails Framework [closed]

What are some of the biggest issues/pitfalls with using the Grails framework? I'm learning the framework now, and I really like it, but I need to know what major issues I may encounter when using it ...
jmq's user avatar
  • 6,068
0 votes
3 answers
3k views

Advantages of Scala vs. Groovy with JAVA EE 6 Applications [closed]

Please let me first emphasize that I am not looking for flame wars. I just want advice from people who have real experiences. I started learning JAVA EE 6 as real newbie and am having a difficult ...
user avatar
8 votes
3 answers
5k views

Jython and JRuby vs. Groovy (and Java) [closed]

I am very interested in Python for programming on the JVM, and I've worked in Java and Ruby (not JRuby) a lot, and to a certain extent in Groovy. What are the limits to the Java-Jython and Java-JRuby ...
Dan Rosenstark's user avatar