Fetching articles...

Podcast 🤬 dudes

How much do we hate them? Two dudes high-fiving each other while guessing blindly into the blue? Let me tell you a story - don't worry it has a twist in the end.

I was listening to this show about coding, and they were talking about Singletons. Yes, I use them all the time and I know that people don't like them much. But these podcast dudes trying to explain to me why, with a sentiment that they were teachers and everyone else are little children that should know better. It just made me like Singletons even more. How convenient they are! Anytime you want them - there they are. Sturdy little soldiers showing up for duty no matter where or when - raining or in the middle of the night. 

There were two statements, first that singletons are bad since they make it impossible to change one implementation for another. Secondly that Apple's application code is bad since it forces you to use singletons (NSUserDefaults and NSNotificationCenter). 

The example was a logger where you want only some of its logs to be sent to a server, but if you use a singleton that was impossible. But why not just build that functionality in a separate function? Or have different settings. Or just have another class and use it instead!  Just because one singleton exists does not make you forced to use them. It is code we are talking about, there are no limits here.

Alright, these are young people and young people are fun. They dare to stick out their necks - not afraid of petty things like being wrong. But would it hurt to peek into the documentation for 5 seconds? Nowhere does it say you have to use the Singleton - in fact the very second paragraph states that you are free to create your own (here it is: take a peek into NSNotificationCenter). Documentation-wise that is an encouragement.

However, you might wonder why you should break it apart. Except for testing, what is the point of having the loosely coupled listener pattern tightly coupled with a notification center only the concerned parties know about? Then perhaps they could talk directly to each other instead of routing things through this center? (No, probably not, but the question needs to be asked).

The second statement, that Apple is writing bad code, is just simply wrong. Not only do they cater the needs of hipster-dudes needing to spend a couple of work-months re-polishing their notification centres, but they are also giving singletons to the rest of us (who like work when it's done). Two flies - one rock.

I guess this is what it feels like being a woman, men constantly taking air-space and being wrong, mansplaining things (guy-guessing?). Well that was in fact not the realisation these podcast-dudes gave me. 

Actually I think its good that they are guy-guessing and being over confident. The podcasters were wrong - so what? This is the way to learn - put oneself out there and risk being wrong. Young people should feel like they are on top of the world and are its teachers - anything else is against nature. Only grumpy old folks are second guessing themselves all the time.  Also, if you find removing Singletons help you - do it. This is programming, there are usually no clear rights and wrongs, only opinions. We will like different things, and that is a good thing. I would, however, like to see a more clear and easy UIApplication (something that needs to be globally accessible from all controllers) without using Singleton.

Anyhow if you want to listen to the episode here it is: Inside iOS Dev - Why Singletons Are Evil

About

Hello! How nice of you stopping by! ❤️

My name is Olof Thorén, I am an indie developer from Stockholm, Sweden.

I really enjoy creating stuff, and that is the reason why I am doing this. I started working full-time on building apps in 2009.

At the moment my main focus is Feeds, a glorified news and RSS-reader that keeps track of the web for you. I also build Qiozk Solo, white-label magazine apps for (mainly Swedish) publishers. I have published ~75 Solo-apps though most of them are not active today. Aggressive Development has published 15 apps under its own name and many more for other companies.

Please feel free to say hello on twitter @olof_t or email olof@aggressive.se. Don't hesitate to send me comments or feedback on anything I write.