-
In lesson 4, we declare the
Why not declare a state variable instead to avoid code duplication if we are going to use this multiple times? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Yes @r3lik ,Making them as state variables will require them to store in storage which costs gas...An alternative is that you can make them constants or immutable which will again save your gas and make it less repetitive |
Beta Was this translation helpful? Give feedback.
-
@r3lik The intentions at this point were to discuss how to get price and version from data feeds that's why you are seeing Patrick had passed address even direct here in string form. Later Patrick moved it to the Factory constructor and make it a state variable and passed the address from helper files, you will see those things further. |
Beta Was this translation helpful? Give feedback.
-
@r3lik You are correct, it does not follow the DRY (Do not repeat yourself) principle. But as this is an introductory lesson, do not sweat it. Patrick takes care of that in the future. All the best! The best solution to minimize gas and follow this principle is to make it of type Hope this helps! |
Beta Was this translation helpful? Give feedback.
@r3lik You are correct, it does not follow the DRY (Do not repeat yourself) principle. But as this is an introductory lesson, do not sweat it. Patrick takes care of that in the future. All the best!
The best solution to minimize gas and follow this principle is to make it of type
constant
-- and if it has to be initialized via a constructor, then aimmutable
type.Hope this helps!