Question on Programming Style for iPhone App Development
Which would be a better approach (with reference to the iPhone processing capabilities & memory management)
Creating 5-10 more files (classes & view controllers) for a particular operation ?
开发者_如何学运维or
Adding a LOT of
if & else
statements and a LOT of code with the existing resources for the same operation ?or
Are they the same ?
I'd always go with approach 1. If nothing else it's probably at least a lot easier to do unit testing this way.
Should take the same as far as the platform is concerned. Even if it weren't, I'd still go with the solution that is easier to read and maintain, unless profiling shows a very noticable difference between the two version. And even then, lots of comments would explain why the code is more complex than it should be.
Code for simplicity of reading and maintaining first and always.
I would tend to lean towards the multiple file approach. Once its complied, number of source files don't matter.
With if-else staqtements there could be some performance loss depending on how much processing has to occur to evaluate those statements.
And lastly cramming all the code into one file will be more difficult to maintain.
I would say it definitely depends on the program. I would tend to to go with number 1, because it would be way easier to maintain.
But option 2 could be viable depending on which kind of operations you are doing, if they are a-like operation then it would be better to have them on the same file. If they are completely different operations it makes a lot more sense to have them on a separate file.
Also this is premature optimization.
精彩评论