Skip to main content
Tweeted twitter.com/StackSoftEng/status/874232941873856512
Question Protected by gnat

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? A co-worker of mine believes we should use it always as it helps Groovy in some way I don't understand.
Currently

Currently, when declaring method return types and arguments, I like to deliberately state which objects should be taken in and spit out (for code readability and I come from a Java background it makes sense to me) example:

String doSomething(String something){   //code } // vs def doSomething(def somthing){  //code } // vs def doSomething(somthing){  // code } 

So I guess my question is it just a preference of when to use def or is there a real advantage to using it all the time? (I added the last example because I felt it fits in with the question as a viable option for 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 in some way I don't understand.
Currently when declaring method return types and arguments I like to deliberately state which objects should be taken in and spit out (for code readability and I come from a Java background it makes sense to me) example:

String doSomething(String something){ //code } //vs def doSomething(def somthing){ //code } //vs def doSomething(somthing){ // code } 

So I guess my question is it just a preference of when to use def or is there a real advantage to using it all the time? (I added the last example because I felt it fits in with the question as a viable option for 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 in some way I don't understand.

Currently, when declaring method return types and arguments, I like to deliberately state which objects should be taken in and spit out (for code readability and I come from a Java background it makes sense to me) example:

String doSomething(String something){   //code } // vs def doSomething(def somthing){  //code } // vs def doSomething(somthing){  // code } 

So I guess my question is it just a preference of when to use def or is there a real advantage to using it all the time? (I added the last example because I felt it fits in with the question as a viable option for Groovy)

Source Link
PJT
  • 413
  • 1
  • 4
  • 6

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 in some way I don't understand.
Currently when declaring method return types and arguments I like to deliberately state which objects should be taken in and spit out (for code readability and I come from a Java background it makes sense to me) example:

String doSomething(String something){ //code } //vs def doSomething(def somthing){ //code } //vs def doSomething(somthing){ // code } 

So I guess my question is it just a preference of when to use def or is there a real advantage to using it all the time? (I added the last example because I felt it fits in with the question as a viable option for Groovy)