optimization - Creating temporary variables to enhance readability -
I would like to know if there is a significant loss to make a floating variable for a price,
Example:
filep-> Route [rp- & gt; Leg [j]]. ID
or
(* (filep- & gt; route + filep-> nroutes - 1)) - & gt; Numbers are a recent example of the project where I was able to improve my skills with Sea Points (it was painful) to avoid virtually any simplification for variable references. Done Although the habit seemed to stick, I feel as much as I try to implement the variable to simplify my code (readability and typing volume), it becomes more confusing, it remembers every new variable references To be cured. I have just reviewed my code in an educational setting, and I would like to know what else is easy to digest and where the business of display is (if any).
When a value is specified that many arithmetic functions are needed to calculate memory address, due to the performance reasons, its own variable is beginning? Does this make a difference, which is done once in the loop? What about once in the nested loop? Regarding the value to be assigned to its variable in a loop, but then what can be reached in an internal loop?
How will this change in an interpreted language? Ask in PHP (please excuse syntax errors, I'm new to PHP): $ employees [$ i] [$ phone] ['home'] ['number'];
vs
$ home = $ employee [$ i] [$ phone] ['home'] ['number'];
And in the end, if this is not even subjective (the code should not be readability!), Which is considered the best practice for writing a readable code? I write the code which is as self-documenting as possible, but if variables are too much complicated and sometimes referred to, then I will assign them my variable. However, this may be the job for me that I have used in my style.
There is a good chance that any decent compiler will detect common sub-expressions and Will optimize them for.
However, I choose the option for a temporary variable now if this readability improves my code, despite the fact that it started additional storage (though at least ).
I think the maintenance of code is much more important than a small storage hit (customized) through the example, I would probably replace a lot of things:
< Code> items [last_item-1] .id = 14860; Item [last_item-1] .name.first = "pax"; Item [last_item-1] .name.last = "Diablo";
Calls with:
tItem lastItem = & amp; (Items [last_item-1]); Previous entity-> id = 14860; ::: // And so on.
In the form of interpreted languages, I have less information on it. I know a lot about optimizing assembly code (though it is not so much that the composers write demododes Is close, so I usually leave it to them). I have a little less information about virtual machines running mostly in interpreters.
But I'll code for now readability, I will $ employees [$ i] [$ phone] ['home'] ['number']
I do not want to see a billeteload of snippets stuck in my code. I'll add
$ homePhone = $ employees [$ i] [$ phone] ['home'] ['number'] instead;
Use $ homePhone
from just that point somewhere else.
Comments
Post a Comment