Seriously, don’t try to write unit tests for multithreaded code. It will bite you in the ass later. The reason unit testing code that runs on multiple threads is hard is the fact that you can’t control the order of execution of threads, nor the allocated time per thread – this is an OS decision. […]
Category Archives: Programming
Objective-C: new is dangerous (and old), avoid it at all costs
Using the new factory method might seem appealing: you no longer have to type [[MyClass alloc] init], you no longer need to write custom factory methods to your class, in short less code. And this is not a bad thing, less code to write means less code to maintenance, test, etc. new unfortunately has a […]
When the Coordinator fails for you, hire an Assistant
Update. This approach is no longer valid, an Assistant is basically a Model, as what I wrongly described here was an MVC without the M part. I’ve been lately using the the Coordinator pattern (actually its variation Coordinator+ViewModel), and while the pattern is a very good one in terms of separation of concerns, it does […]
Swift – make your life easier with promises
A while ago I wrote a series of articles about Promises in Objective-C, and described the way promises help us write async code in an async manner, help us pipeline data streams and recover from errors by giving the pipeline another thing to process. Well, time has passed, Swift came along, and promises look better […]
Retrying async functions in Swift via high-order functions
TL;DR; Solution can be also found here. Supposing we’re writing a client-server communication layer, and we want to add support for retrying failed calls for a number of times before giving up and reporting error. A classical example would be updating a user’s profile when pressing a Save button from the UI. A typical function might look like […]
if-let statement in Objective-C
I just found an equivalent to Swift’s if-let construct, and thought to share it 🙂 Swift: Objective-C: You no longer need an extra line to declare the variable, and also the variable is visible only inside the if branch. Just like in Swift 🙂
To manage or not to manage
This article is intended for those of you that you love and abuse the “manager” concept. I know you’re there, don’t try to hide yourself :). The idea of a manager quickly gets into the mind of a developer when he designs a project. Sooner or later, you’ll need a manager that will coordinate some […]
A promise implementation for objective-c: CKPromise
Now that we went through all promise technical details in the past articles: Promises and ObjectiveC: no more callback hell, Promises: basics, and Promises: advanced, it’s time to discuss about one of the available implementations, and for subjective reasons I chose CKPromise. Other good implementations that I know of are PromiseKit and RXPromise. CKPromise focuses only on […]
Promises: advanced
In the previous article we discussed about the basics of promises: what are and how can be used. Today I will bring into discussion the most powerful feature of promises: chaining. But first I just want to take a short detour and mention that as the standard for promises emerged on the Javascript platform, it allows completion […]
Promises: basics
In my previous article, I introduced the concept of promise, a technique that allows us to write async code in a more sync-ish manner. In this article and the following ones I will try to dive into the definition and expectancies of a promise. So what is a promise? A promise represents the eventual result of an asynchronous operation. This […]