Saturday, 15 February 2014

Groovy : Closures or Methods -


I have found a habit of using the closure in the regular place, even when I do not need to free the variable If access, I will use it:

def addNumbers = {left, right -> Left + right}

.. instead:

def addNumbers (left, right) {left + right}

Is this bad behavior? I like the extra power so far, when I use closures on the methods, and I like the syntax.

Thanks

I only use those closures where I need them , That is, I use methods by default. I do this because

  • The methods are easy to close. Closures have a representative, one owner can use the variable that was created in their local area (which you call "free variable")

  • the owner of the closure < / Li>
  • Closure Representative
  • / li>

But this sequence can be changed to runtime, and a closest representative can use any Object can also be changed.

Combined, some of the factors can make code that uses the closure, it is very difficult to groke, so if you do not need this complication then I would rather use one method I like to end it

  • A Class file every groove I have absolutely zero evidence to support the claim that there is more demonstrative than a regular system shutdown, but I doubt it. At the very least, in many sections you may have reason to get out of Permjen's memory space - it used to be repeated to me as long as I extended my marine location to approximately 200m

I have no idea what practice I am advocating (by using methods by default and when you need them) is widely considered "best practice", then I am curious to hear it Have There are not that what other people think.


No comments:

Post a Comment