dhblah
dhblah

Reputation: 10151

How much overhead creates making many functions in groovy

I'm writing a small script in groovy, that takes items from source database, then checks if that item is in destination database. Then it takes item from the source database, checks it's attributes, depending on it performs some modifications on item and then stores in destination database.

I need to make some validations before putting data into database. But I can't put all validations into one separate function, because, different validations should be made at different points (I'll illustrate it). The question is, how much resources it consumes, to make many small functions? Making functions significantly ease code readability.

The sample:

def changeItem(id) {
 boolean putToDB = checkInDestDatabase(id);
 item = sourceDatabase.get(id);
 putToDB &= checkIfApple(item);
 Apple apple = (Apple)item;
 Tree tree = apple.getTree();
 putToDB &= checkIfTreeWasCut(tree, apple);
 putToDB &= checkThisAppleIsAlreadyOnAnotherTree(tree, apple);
 putToDB &= checkIfAppleIsRotten(apple);
 if (putToDB) {
  destDB.put(apple)
 }
}

I can't inline that checking functions because they'll take a lot of space and code will become unreadable.

So, does making many functions consumes a lot of resources in jvm?

Upvotes: 1

Views: 122

Answers (1)

tim_yates
tim_yates

Reputation: 171114

No, it shouldn't do.

You can always check with jvisualvm

And it's worth whatever cost it may cause, as your code will end up more readable, maintainable, and refactorable

Upvotes: 2

Related Questions