Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I hardly ever reuse variables. I hate to say never, but it is <em>close to never</em>.</p> <h2>Here is why:</h2> <ul> <li><em>Small methods</em> (It's good practice to keep methods and property-getters/setters as concise as possible). <ul> <li>When only one thing is done, <em>no need</em> to reuse variables</li> <li>The var section is always on the screen.</li> </ul></li> <li>The compiler reuses the storage as necessary, so reuse is only a <em>lazy coder crutch</em> with no performance improvements.</li> <li>Newer versions of Delphi have <strong>CTRL+SHIFT+V</strong> to declare a variable if I am feeling lazy.</li> <li>Reusing variables <em>makes debugging more difficult</em> - more time and effort is spent on maintenance then development (for any serious application) so always do things to <em>make maintenance easier</em>, even if it makes development a little harder.</li> <li>Prefer <em>user defined types</em>, so a Account Balance is a specific type, not just a Currency. This means variables are <em>less reusable</em> anyway.</li> <li><strong>For</strong> loop variables (a common reused variable) are used less now that we can use <strong>for in</strong> and <em>skip the iterator</em> all together.</li> <li>My variables have <em>descriptive names</em>, so it would not make sense to use them out of context. </li> </ul> <p>Generally speaking, I like having all the variables at the top for the same reason I like having an interface section on my units. It is kind of like having an abstract on a paper - give me a general idea of what is going on without having to read the whole paper. Delphi could benefit from having the ability to declare variables at "inner scope" like within a <strong>for</strong> loop or other <strong>begin / end</strong> blocks, but I don't know how much that would distract from the cleanliness and readability of Delphi code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload