so place local method variables?
a question of style, i'm lacking in department.
(one of many bonuses coming being self-taught).
at moment seem place definition of local method-variables anywhere in vicinity of i'll first use them. idea of course being declaration , use of said variables should close each other possible. leads code being easier decipher, code isn't neat/clean looking like. therefore starting reconsider approach.
i considering placing definitions possible in method should give nice , quick overview of local variables going used. should tidy code well.
comments/alternatives/thoughts?
i can give personal experience.
started style of putting variables @ top of method. did thinking if reading code , see variable, need @ top of function find out it's type. kept variables in alphabetical order. go far deferring initialisation until after local variable declarations able maintain alphabetical ordering. ... no wonder ended librarian. 
don't anymore. when started refactoring, found easier able move code around if variable declaration close first use. having been coding long enough have go read (typically undocumented) old code, found have have been easier if variable declared close it's use. found myself jumping , forth top of method.
now...
not of issue, either way. keep methods short , sweet possible. no method more 20 lines, it's easy see , understand whole method @ once. if method grows big, stop , reassess methods trying do. if it's trying much, refactor in smaller methods.
, tend use style of variable usage learnt functional programming. avoid ever reassigning variable, treat variables read only. find debugging enormously. , basic data-flow analysis reuse registers , stack locations, optimisations it's doesn't use more memory.
Forums iPhone, iPad, and iPod Touch iOS Programming
- iPhone
- Mac OS & System Software
- iPad
- Apple Watch
- Notebooks
- iTunes
- Apple ID
- iCloud
- Desktop Computers
- Apple Music
- Professional Applications
- iPod
- iWork
- Apple TV
- iLife
- Wireless
Comments
Post a Comment