Should I declare a variable or access object method? [on hold]












6














Which is the better practice and why?



Declare a variable:



exampleFunction(requestData: Object) {
const username = requestData.username;

doSomething(username);
}


Or access the object property directly?



exampleFunction(requestData: Object) {
doSomething(requestData.username);
}


What if the code I use is over 50 lines long and the variable is used multiple times. Should I use the variable 'username' multiple times or use 'requestData.username' multiple times?










share|improve this question















put on hold as primarily opinion-based by Heretic Monkey, Faisal, Alejandro, Bergi, Moira 2 days ago


Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.















  • If you are asking for an opinion: It depends, and it is a preference.
    – Maihan Nijat
    2 days ago










  • I'm wondering which one of these options is the better practice.
    – Blasty
    2 days ago






  • 2




    In above context, access object property is better, I think. There is no need to declare a variable to hold it. And if you are using a better IDE like, it will suggest to use second, in the above context.
    – Maihan Nijat
    2 days ago












  • I'm not sure if there is a best practice, but for sure requestData is too broad. What does requestData contains ?
    – Florian
    2 days ago












  • I would go for the second option. Its much cleaner this way.
    – Kevin van Schaijk
    2 days ago
















6














Which is the better practice and why?



Declare a variable:



exampleFunction(requestData: Object) {
const username = requestData.username;

doSomething(username);
}


Or access the object property directly?



exampleFunction(requestData: Object) {
doSomething(requestData.username);
}


What if the code I use is over 50 lines long and the variable is used multiple times. Should I use the variable 'username' multiple times or use 'requestData.username' multiple times?










share|improve this question















put on hold as primarily opinion-based by Heretic Monkey, Faisal, Alejandro, Bergi, Moira 2 days ago


Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.















  • If you are asking for an opinion: It depends, and it is a preference.
    – Maihan Nijat
    2 days ago










  • I'm wondering which one of these options is the better practice.
    – Blasty
    2 days ago






  • 2




    In above context, access object property is better, I think. There is no need to declare a variable to hold it. And if you are using a better IDE like, it will suggest to use second, in the above context.
    – Maihan Nijat
    2 days ago












  • I'm not sure if there is a best practice, but for sure requestData is too broad. What does requestData contains ?
    – Florian
    2 days ago












  • I would go for the second option. Its much cleaner this way.
    – Kevin van Schaijk
    2 days ago














6












6








6







Which is the better practice and why?



Declare a variable:



exampleFunction(requestData: Object) {
const username = requestData.username;

doSomething(username);
}


Or access the object property directly?



exampleFunction(requestData: Object) {
doSomething(requestData.username);
}


What if the code I use is over 50 lines long and the variable is used multiple times. Should I use the variable 'username' multiple times or use 'requestData.username' multiple times?










share|improve this question















Which is the better practice and why?



Declare a variable:



exampleFunction(requestData: Object) {
const username = requestData.username;

doSomething(username);
}


Or access the object property directly?



exampleFunction(requestData: Object) {
doSomething(requestData.username);
}


What if the code I use is over 50 lines long and the variable is used multiple times. Should I use the variable 'username' multiple times or use 'requestData.username' multiple times?







angular typescript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago







Blasty

















asked 2 days ago









BlastyBlasty

818




818




put on hold as primarily opinion-based by Heretic Monkey, Faisal, Alejandro, Bergi, Moira 2 days ago


Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.






put on hold as primarily opinion-based by Heretic Monkey, Faisal, Alejandro, Bergi, Moira 2 days ago


Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.














  • If you are asking for an opinion: It depends, and it is a preference.
    – Maihan Nijat
    2 days ago










  • I'm wondering which one of these options is the better practice.
    – Blasty
    2 days ago






  • 2




    In above context, access object property is better, I think. There is no need to declare a variable to hold it. And if you are using a better IDE like, it will suggest to use second, in the above context.
    – Maihan Nijat
    2 days ago












  • I'm not sure if there is a best practice, but for sure requestData is too broad. What does requestData contains ?
    – Florian
    2 days ago












  • I would go for the second option. Its much cleaner this way.
    – Kevin van Schaijk
    2 days ago


















  • If you are asking for an opinion: It depends, and it is a preference.
    – Maihan Nijat
    2 days ago










  • I'm wondering which one of these options is the better practice.
    – Blasty
    2 days ago






  • 2




    In above context, access object property is better, I think. There is no need to declare a variable to hold it. And if you are using a better IDE like, it will suggest to use second, in the above context.
    – Maihan Nijat
    2 days ago












  • I'm not sure if there is a best practice, but for sure requestData is too broad. What does requestData contains ?
    – Florian
    2 days ago












  • I would go for the second option. Its much cleaner this way.
    – Kevin van Schaijk
    2 days ago
















If you are asking for an opinion: It depends, and it is a preference.
– Maihan Nijat
2 days ago




If you are asking for an opinion: It depends, and it is a preference.
– Maihan Nijat
2 days ago












I'm wondering which one of these options is the better practice.
– Blasty
2 days ago




I'm wondering which one of these options is the better practice.
– Blasty
2 days ago




2




2




In above context, access object property is better, I think. There is no need to declare a variable to hold it. And if you are using a better IDE like, it will suggest to use second, in the above context.
– Maihan Nijat
2 days ago






In above context, access object property is better, I think. There is no need to declare a variable to hold it. And if you are using a better IDE like, it will suggest to use second, in the above context.
– Maihan Nijat
2 days ago














I'm not sure if there is a best practice, but for sure requestData is too broad. What does requestData contains ?
– Florian
2 days ago






I'm not sure if there is a best practice, but for sure requestData is too broad. What does requestData contains ?
– Florian
2 days ago














I would go for the second option. Its much cleaner this way.
– Kevin van Schaijk
2 days ago




I would go for the second option. Its much cleaner this way.
– Kevin van Schaijk
2 days ago












5 Answers
5






active

oldest

votes


















4














V8 Javascript Engine performs some optimization pre-processing the code and checking if some variable can be deleted or if there's some regular pattern in the code, in order to reduce the execution payload.



For this reason, there are no memory issues in using a form or another, at least using V8 engine (for example, Chrome or NodeJS).



Even if this optimization isn't performed, it's just a pointer or a primitive variable, so it won't cost more than few bytes.



It's different if we talk about the cost of transmitting code. We know that JavaScript isn't a compiled language and it needs to reach the client's computer to be executed, so every space, indentation, semicolon, will cost in order of time used to transfer.



To reduce this cost, you can uglify and minify your code, but usually this type of optimization isn't performed.



Finally, it's impossible to think a scenario where it can make a difference, so I advise you to use the form that you think it's more readable and no matter of other parameters.






share|improve this answer























  • Nicely explained!
    – xyz
    2 days ago










  • I think my answer needs some source, I'm going to add something later
    – Cristian Traìna
    2 days ago



















4














By refactoring of Martin Fowler is a technique (Replace Temp with Query).



after that you will go to second variant



cloneFullProject(requestData: Object) {
doSomething(requestData.username);
}


But it is smell too (Middle Man).



As a conclusion in this example, it is better to remove this method altogether :)



However, there are cases when is preferable first example. For instance:
you have several methods that take requestData.username parameters.



exampleFunction(requestData: Object) {
const username = requestData.username;

doSomething1(username);
doSomething2(username);
...
}


And in this case temporary variable is justified






share|improve this answer































    3














    First option pros:




    1. Readable code

    2. You can debug and validate value before passing to another method


    First option cons:




    1. It will create unnecessary variables and consume more memory






    share|improve this answer



















    • 3




      You should never use let instead of const.
      – Florian
      2 days ago










    • My bad let me update answer
      – Ans Bilal
      2 days ago



















    2














    First of all you are referencing an object, not cloning it.
    The right way of cloning is throug Object.assign() or lodash (or similar) _.cloneDeep(), or spread operator or whatever.



    Please refer to typescript - cloning object for more info about cloning.



    Coming to the question, when you have a single variable to work both has the same readability in a such short method.



    Just because the method is so short I would prefer the latter one, as reading a single line of code explain what property of the object I'm passing to my method instead of reverse-reading the code.



    For my own taste and general opinion destructuring is the cleanest way another programmer would expect from your code:



    const { username, var1, var2 }  = requestData;





    share|improve this answer























    • What if he does not need to clone it and need a reference instead of deep copying the object?
      – Maihan Nijat
      2 days ago










    • This is a small example. The actual code I'm working with is about 60 lines of code where the variable is used more than once.
      – Blasty
      2 days ago






    • 1




      I pointed out this only because the code mock is not clear about it and cloneFullProject is pretty semantic but can be misleading
      – Antonio Buelli
      2 days ago










    • If variable are used more than once you can use destructuring, which is even more clear: `const {username, var2, var3, var4} = requestData;'
      – Antonio Buelli
      2 days ago












    • The function name is not relevant right now, I'm not sure if you understood the question.
      – Blasty
      2 days ago



















    1















    Primarily, it is an opinion based question. So, the answer given below is my point of view.





    • In the first case, you need an extra variable which is not actually required as you don't process it further in the same block. So, I recommend the second one with direct property access in your scenario & is more readable too.

    • If you have a scenario where your actual code is over 60 lines long (or so) and the variable is used multiple times in different places, you can use the first case with an extra variable, so that you'll find it easy to process it with less/ safe typing.






    share|improve this answer






























      5 Answers
      5






      active

      oldest

      votes








      5 Answers
      5






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4














      V8 Javascript Engine performs some optimization pre-processing the code and checking if some variable can be deleted or if there's some regular pattern in the code, in order to reduce the execution payload.



      For this reason, there are no memory issues in using a form or another, at least using V8 engine (for example, Chrome or NodeJS).



      Even if this optimization isn't performed, it's just a pointer or a primitive variable, so it won't cost more than few bytes.



      It's different if we talk about the cost of transmitting code. We know that JavaScript isn't a compiled language and it needs to reach the client's computer to be executed, so every space, indentation, semicolon, will cost in order of time used to transfer.



      To reduce this cost, you can uglify and minify your code, but usually this type of optimization isn't performed.



      Finally, it's impossible to think a scenario where it can make a difference, so I advise you to use the form that you think it's more readable and no matter of other parameters.






      share|improve this answer























      • Nicely explained!
        – xyz
        2 days ago










      • I think my answer needs some source, I'm going to add something later
        – Cristian Traìna
        2 days ago
















      4














      V8 Javascript Engine performs some optimization pre-processing the code and checking if some variable can be deleted or if there's some regular pattern in the code, in order to reduce the execution payload.



      For this reason, there are no memory issues in using a form or another, at least using V8 engine (for example, Chrome or NodeJS).



      Even if this optimization isn't performed, it's just a pointer or a primitive variable, so it won't cost more than few bytes.



      It's different if we talk about the cost of transmitting code. We know that JavaScript isn't a compiled language and it needs to reach the client's computer to be executed, so every space, indentation, semicolon, will cost in order of time used to transfer.



      To reduce this cost, you can uglify and minify your code, but usually this type of optimization isn't performed.



      Finally, it's impossible to think a scenario where it can make a difference, so I advise you to use the form that you think it's more readable and no matter of other parameters.






      share|improve this answer























      • Nicely explained!
        – xyz
        2 days ago










      • I think my answer needs some source, I'm going to add something later
        – Cristian Traìna
        2 days ago














      4












      4








      4






      V8 Javascript Engine performs some optimization pre-processing the code and checking if some variable can be deleted or if there's some regular pattern in the code, in order to reduce the execution payload.



      For this reason, there are no memory issues in using a form or another, at least using V8 engine (for example, Chrome or NodeJS).



      Even if this optimization isn't performed, it's just a pointer or a primitive variable, so it won't cost more than few bytes.



      It's different if we talk about the cost of transmitting code. We know that JavaScript isn't a compiled language and it needs to reach the client's computer to be executed, so every space, indentation, semicolon, will cost in order of time used to transfer.



      To reduce this cost, you can uglify and minify your code, but usually this type of optimization isn't performed.



      Finally, it's impossible to think a scenario where it can make a difference, so I advise you to use the form that you think it's more readable and no matter of other parameters.






      share|improve this answer














      V8 Javascript Engine performs some optimization pre-processing the code and checking if some variable can be deleted or if there's some regular pattern in the code, in order to reduce the execution payload.



      For this reason, there are no memory issues in using a form or another, at least using V8 engine (for example, Chrome or NodeJS).



      Even if this optimization isn't performed, it's just a pointer or a primitive variable, so it won't cost more than few bytes.



      It's different if we talk about the cost of transmitting code. We know that JavaScript isn't a compiled language and it needs to reach the client's computer to be executed, so every space, indentation, semicolon, will cost in order of time used to transfer.



      To reduce this cost, you can uglify and minify your code, but usually this type of optimization isn't performed.



      Finally, it's impossible to think a scenario where it can make a difference, so I advise you to use the form that you think it's more readable and no matter of other parameters.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited 2 days ago

























      answered 2 days ago









      Cristian TraìnaCristian Traìna

      2,07911523




      2,07911523












      • Nicely explained!
        – xyz
        2 days ago










      • I think my answer needs some source, I'm going to add something later
        – Cristian Traìna
        2 days ago


















      • Nicely explained!
        – xyz
        2 days ago










      • I think my answer needs some source, I'm going to add something later
        – Cristian Traìna
        2 days ago
















      Nicely explained!
      – xyz
      2 days ago




      Nicely explained!
      – xyz
      2 days ago












      I think my answer needs some source, I'm going to add something later
      – Cristian Traìna
      2 days ago




      I think my answer needs some source, I'm going to add something later
      – Cristian Traìna
      2 days ago













      4














      By refactoring of Martin Fowler is a technique (Replace Temp with Query).



      after that you will go to second variant



      cloneFullProject(requestData: Object) {
      doSomething(requestData.username);
      }


      But it is smell too (Middle Man).



      As a conclusion in this example, it is better to remove this method altogether :)



      However, there are cases when is preferable first example. For instance:
      you have several methods that take requestData.username parameters.



      exampleFunction(requestData: Object) {
      const username = requestData.username;

      doSomething1(username);
      doSomething2(username);
      ...
      }


      And in this case temporary variable is justified






      share|improve this answer




























        4














        By refactoring of Martin Fowler is a technique (Replace Temp with Query).



        after that you will go to second variant



        cloneFullProject(requestData: Object) {
        doSomething(requestData.username);
        }


        But it is smell too (Middle Man).



        As a conclusion in this example, it is better to remove this method altogether :)



        However, there are cases when is preferable first example. For instance:
        you have several methods that take requestData.username parameters.



        exampleFunction(requestData: Object) {
        const username = requestData.username;

        doSomething1(username);
        doSomething2(username);
        ...
        }


        And in this case temporary variable is justified






        share|improve this answer


























          4












          4








          4






          By refactoring of Martin Fowler is a technique (Replace Temp with Query).



          after that you will go to second variant



          cloneFullProject(requestData: Object) {
          doSomething(requestData.username);
          }


          But it is smell too (Middle Man).



          As a conclusion in this example, it is better to remove this method altogether :)



          However, there are cases when is preferable first example. For instance:
          you have several methods that take requestData.username parameters.



          exampleFunction(requestData: Object) {
          const username = requestData.username;

          doSomething1(username);
          doSomething2(username);
          ...
          }


          And in this case temporary variable is justified






          share|improve this answer














          By refactoring of Martin Fowler is a technique (Replace Temp with Query).



          after that you will go to second variant



          cloneFullProject(requestData: Object) {
          doSomething(requestData.username);
          }


          But it is smell too (Middle Man).



          As a conclusion in this example, it is better to remove this method altogether :)



          However, there are cases when is preferable first example. For instance:
          you have several methods that take requestData.username parameters.



          exampleFunction(requestData: Object) {
          const username = requestData.username;

          doSomething1(username);
          doSomething2(username);
          ...
          }


          And in this case temporary variable is justified







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 days ago

























          answered 2 days ago









          Konstantin OkhotnickKonstantin Okhotnick

          1,228820




          1,228820























              3














              First option pros:




              1. Readable code

              2. You can debug and validate value before passing to another method


              First option cons:




              1. It will create unnecessary variables and consume more memory






              share|improve this answer



















              • 3




                You should never use let instead of const.
                – Florian
                2 days ago










              • My bad let me update answer
                – Ans Bilal
                2 days ago
















              3














              First option pros:




              1. Readable code

              2. You can debug and validate value before passing to another method


              First option cons:




              1. It will create unnecessary variables and consume more memory






              share|improve this answer



















              • 3




                You should never use let instead of const.
                – Florian
                2 days ago










              • My bad let me update answer
                – Ans Bilal
                2 days ago














              3












              3








              3






              First option pros:




              1. Readable code

              2. You can debug and validate value before passing to another method


              First option cons:




              1. It will create unnecessary variables and consume more memory






              share|improve this answer














              First option pros:




              1. Readable code

              2. You can debug and validate value before passing to another method


              First option cons:




              1. It will create unnecessary variables and consume more memory







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 2 days ago

























              answered 2 days ago









              Ans BilalAns Bilal

              413216




              413216








              • 3




                You should never use let instead of const.
                – Florian
                2 days ago










              • My bad let me update answer
                – Ans Bilal
                2 days ago














              • 3




                You should never use let instead of const.
                – Florian
                2 days ago










              • My bad let me update answer
                – Ans Bilal
                2 days ago








              3




              3




              You should never use let instead of const.
              – Florian
              2 days ago




              You should never use let instead of const.
              – Florian
              2 days ago












              My bad let me update answer
              – Ans Bilal
              2 days ago




              My bad let me update answer
              – Ans Bilal
              2 days ago











              2














              First of all you are referencing an object, not cloning it.
              The right way of cloning is throug Object.assign() or lodash (or similar) _.cloneDeep(), or spread operator or whatever.



              Please refer to typescript - cloning object for more info about cloning.



              Coming to the question, when you have a single variable to work both has the same readability in a such short method.



              Just because the method is so short I would prefer the latter one, as reading a single line of code explain what property of the object I'm passing to my method instead of reverse-reading the code.



              For my own taste and general opinion destructuring is the cleanest way another programmer would expect from your code:



              const { username, var1, var2 }  = requestData;





              share|improve this answer























              • What if he does not need to clone it and need a reference instead of deep copying the object?
                – Maihan Nijat
                2 days ago










              • This is a small example. The actual code I'm working with is about 60 lines of code where the variable is used more than once.
                – Blasty
                2 days ago






              • 1




                I pointed out this only because the code mock is not clear about it and cloneFullProject is pretty semantic but can be misleading
                – Antonio Buelli
                2 days ago










              • If variable are used more than once you can use destructuring, which is even more clear: `const {username, var2, var3, var4} = requestData;'
                – Antonio Buelli
                2 days ago












              • The function name is not relevant right now, I'm not sure if you understood the question.
                – Blasty
                2 days ago
















              2














              First of all you are referencing an object, not cloning it.
              The right way of cloning is throug Object.assign() or lodash (or similar) _.cloneDeep(), or spread operator or whatever.



              Please refer to typescript - cloning object for more info about cloning.



              Coming to the question, when you have a single variable to work both has the same readability in a such short method.



              Just because the method is so short I would prefer the latter one, as reading a single line of code explain what property of the object I'm passing to my method instead of reverse-reading the code.



              For my own taste and general opinion destructuring is the cleanest way another programmer would expect from your code:



              const { username, var1, var2 }  = requestData;





              share|improve this answer























              • What if he does not need to clone it and need a reference instead of deep copying the object?
                – Maihan Nijat
                2 days ago










              • This is a small example. The actual code I'm working with is about 60 lines of code where the variable is used more than once.
                – Blasty
                2 days ago






              • 1




                I pointed out this only because the code mock is not clear about it and cloneFullProject is pretty semantic but can be misleading
                – Antonio Buelli
                2 days ago










              • If variable are used more than once you can use destructuring, which is even more clear: `const {username, var2, var3, var4} = requestData;'
                – Antonio Buelli
                2 days ago












              • The function name is not relevant right now, I'm not sure if you understood the question.
                – Blasty
                2 days ago














              2












              2








              2






              First of all you are referencing an object, not cloning it.
              The right way of cloning is throug Object.assign() or lodash (or similar) _.cloneDeep(), or spread operator or whatever.



              Please refer to typescript - cloning object for more info about cloning.



              Coming to the question, when you have a single variable to work both has the same readability in a such short method.



              Just because the method is so short I would prefer the latter one, as reading a single line of code explain what property of the object I'm passing to my method instead of reverse-reading the code.



              For my own taste and general opinion destructuring is the cleanest way another programmer would expect from your code:



              const { username, var1, var2 }  = requestData;





              share|improve this answer














              First of all you are referencing an object, not cloning it.
              The right way of cloning is throug Object.assign() or lodash (or similar) _.cloneDeep(), or spread operator or whatever.



              Please refer to typescript - cloning object for more info about cloning.



              Coming to the question, when you have a single variable to work both has the same readability in a such short method.



              Just because the method is so short I would prefer the latter one, as reading a single line of code explain what property of the object I'm passing to my method instead of reverse-reading the code.



              For my own taste and general opinion destructuring is the cleanest way another programmer would expect from your code:



              const { username, var1, var2 }  = requestData;






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited yesterday









              Dion Williams

              7025




              7025










              answered 2 days ago









              Antonio BuelliAntonio Buelli

              515




              515












              • What if he does not need to clone it and need a reference instead of deep copying the object?
                – Maihan Nijat
                2 days ago










              • This is a small example. The actual code I'm working with is about 60 lines of code where the variable is used more than once.
                – Blasty
                2 days ago






              • 1




                I pointed out this only because the code mock is not clear about it and cloneFullProject is pretty semantic but can be misleading
                – Antonio Buelli
                2 days ago










              • If variable are used more than once you can use destructuring, which is even more clear: `const {username, var2, var3, var4} = requestData;'
                – Antonio Buelli
                2 days ago












              • The function name is not relevant right now, I'm not sure if you understood the question.
                – Blasty
                2 days ago


















              • What if he does not need to clone it and need a reference instead of deep copying the object?
                – Maihan Nijat
                2 days ago










              • This is a small example. The actual code I'm working with is about 60 lines of code where the variable is used more than once.
                – Blasty
                2 days ago






              • 1




                I pointed out this only because the code mock is not clear about it and cloneFullProject is pretty semantic but can be misleading
                – Antonio Buelli
                2 days ago










              • If variable are used more than once you can use destructuring, which is even more clear: `const {username, var2, var3, var4} = requestData;'
                – Antonio Buelli
                2 days ago












              • The function name is not relevant right now, I'm not sure if you understood the question.
                – Blasty
                2 days ago
















              What if he does not need to clone it and need a reference instead of deep copying the object?
              – Maihan Nijat
              2 days ago




              What if he does not need to clone it and need a reference instead of deep copying the object?
              – Maihan Nijat
              2 days ago












              This is a small example. The actual code I'm working with is about 60 lines of code where the variable is used more than once.
              – Blasty
              2 days ago




              This is a small example. The actual code I'm working with is about 60 lines of code where the variable is used more than once.
              – Blasty
              2 days ago




              1




              1




              I pointed out this only because the code mock is not clear about it and cloneFullProject is pretty semantic but can be misleading
              – Antonio Buelli
              2 days ago




              I pointed out this only because the code mock is not clear about it and cloneFullProject is pretty semantic but can be misleading
              – Antonio Buelli
              2 days ago












              If variable are used more than once you can use destructuring, which is even more clear: `const {username, var2, var3, var4} = requestData;'
              – Antonio Buelli
              2 days ago






              If variable are used more than once you can use destructuring, which is even more clear: `const {username, var2, var3, var4} = requestData;'
              – Antonio Buelli
              2 days ago














              The function name is not relevant right now, I'm not sure if you understood the question.
              – Blasty
              2 days ago




              The function name is not relevant right now, I'm not sure if you understood the question.
              – Blasty
              2 days ago











              1















              Primarily, it is an opinion based question. So, the answer given below is my point of view.





              • In the first case, you need an extra variable which is not actually required as you don't process it further in the same block. So, I recommend the second one with direct property access in your scenario & is more readable too.

              • If you have a scenario where your actual code is over 60 lines long (or so) and the variable is used multiple times in different places, you can use the first case with an extra variable, so that you'll find it easy to process it with less/ safe typing.






              share|improve this answer




























                1















                Primarily, it is an opinion based question. So, the answer given below is my point of view.





                • In the first case, you need an extra variable which is not actually required as you don't process it further in the same block. So, I recommend the second one with direct property access in your scenario & is more readable too.

                • If you have a scenario where your actual code is over 60 lines long (or so) and the variable is used multiple times in different places, you can use the first case with an extra variable, so that you'll find it easy to process it with less/ safe typing.






                share|improve this answer


























                  1












                  1








                  1







                  Primarily, it is an opinion based question. So, the answer given below is my point of view.





                  • In the first case, you need an extra variable which is not actually required as you don't process it further in the same block. So, I recommend the second one with direct property access in your scenario & is more readable too.

                  • If you have a scenario where your actual code is over 60 lines long (or so) and the variable is used multiple times in different places, you can use the first case with an extra variable, so that you'll find it easy to process it with less/ safe typing.






                  share|improve this answer















                  Primarily, it is an opinion based question. So, the answer given below is my point of view.





                  • In the first case, you need an extra variable which is not actually required as you don't process it further in the same block. So, I recommend the second one with direct property access in your scenario & is more readable too.

                  • If you have a scenario where your actual code is over 60 lines long (or so) and the variable is used multiple times in different places, you can use the first case with an extra variable, so that you'll find it easy to process it with less/ safe typing.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 2 days ago

























                  answered 2 days ago









                  Tushar WalzadeTushar Walzade

                  1,46421430




                  1,46421430















                      Popular posts from this blog

                      1300-talet

                      1300-talet

                      Display a custom attribute below product name in the front-end Magento 1.9.3.8