r/iOSProgramming • u/quellish • Mar 06 '16
Article 9 Anti-Patterns Every Programmer Should Be Aware Of
http://sahandsaba.com/nine-anti-patterns-every-programmer-should-be-aware-of-with-examples.html15
u/boboguitar Mar 07 '16
10) Using unnecessary 3rd party libraries.
9
u/DeepDuh Mar 07 '16
11) Mistaking "No premature optimisation" for "don't ever think about performance until the software is complete".
1
u/20InMyHead Mar 07 '16
It's the "Outer Platform Effect." You see it all the time, wrapper on GCD, wrapper on NSSession, wrapper on whatever...
1
u/boboguitar Mar 07 '16
My current frustration- seeing a wrapper on another wrapper because the first wrapper had a bunch of bugs in it.
0
u/chriswaco Mar 07 '16
I tend to like God classes, but only to avoid distributing application-specific code throughout the project. That is, write a ton of generic, reusable classes and then one puppetmaster class to control them all. Almost everything is reusable except the puppetmaster and maybe a few app specific classes. There are many tasks, like saving/restoring state, analytics, properly ordering operations, version management, device management, handling push and background notifications, themes, etc, that are best invoked by one class that knows what the user is up to at all times.
I don't think it should be a true God class, but more of a demigod with a few minion helpers and then a bunch of completely reusable slave classes that know nothing about the particular app. I would never put the raw low-level networking or analytics code in it, but might invoke the code from it.
If you have app-specific functionality spread throughout 100s of classes, it's harder to reuse code.
2
u/quellish Mar 07 '16
There are many tasks, like saving/restoring state, analytics, properly ordering operations, version management, device management, handling push and background notifications, themes, etc, that are best invoked by one class that knows what the user is up to at all times.
For all of the use cases you mention here there are certainly viable alternatives that conform to well known best practices. For example, for analytics it is common to use the chain of responsibility pattern. For version or device management it would be common to use an abstract factory (i.e. iPad gets one implementation, iPhone 5 another, etc.).
If you want to use a "God class" that's up to you, but you should be very well aware of the engineering tradeoffs involved.
0
u/chriswaco Mar 07 '16
"Best practices" is such a ridiculous buzzword. I've seen so-called "best practices" change time and again over the years, sometimes for the better, but just as often not. The goals of any code should be reliability, efficiency, reusability, understandability, debugability, affordability, etc. If I can reuse 100 classes and only have to rewrite 1 to create a new application, that's a huge victory. If a new programmer can open the project file and figure out how everything works in an afternoon, that's a huge victory. If we can add a feature without having to modify a whole bunch of different classes and files and methods, that's a huge victory. (In the old days, portability was one of our biggest concerns, but for iOS apps we tend to write OS specific code).
Distributing complexity across many classes often makes life more complicated, not less.
2
u/quellish Mar 08 '16
"Best practices" is such a ridiculous buzzword.
OK, let me rephrase it. "Don't screw yourself or the next person to maintain the code".
If we can add a feature without having to modify a whole bunch of different classes and files and methods, that's a huge victory.
And that is the objective of using good design and leveraging existing design patterns. For example, if your design uses a good level of abstraction you should not have to modify much at all to implement new functionality. Open for extension, closed for modification, all that good stuff. If you're rewriting a class to use it in a new application I would say something might be wrong there.
Distributing complexity across many classes often makes life more complicated, not less.
I don't think anyone ever said that the solution was to distribute complexity over many classes - even though with some programming communities that is certainly the case. Many Java developers will drown a project in unnecessary classes, for example.
2
u/shotgunsparkle Mar 07 '16
I think you should be looking at the inversion of control and dependency injection paradigm
4
u/[deleted] Mar 07 '16
Writing your own crypto.