Exploring FP: Nomad's Monoid

What is a Monoid? Monoid is a property of a system which satisfies these three laws: Has identity Is composable and the order of composition doesnot matter: i.e. composition is associative The result of composing 2 such system produces similar system. i.e Closure property or endomorphism. Well, that sounds a bit abstract. Indeed. Well, is this any useful in programming? You bet it is. This post is entirely about understanding what a monoid is, with ideas we (OOP) programmers already know.

Read More

Monadic Computation in Swift. Why?

I won’t go into the details of what a Monad is and what exactly it solves. What we will do here is try to come up with a monadic type to encapsulate network result. We will do a side by side comparison with the traditional/classical/imperative and the functional (monadic) approach. In the end you should be able to appreciate and hopefully use the monadic style of wrapping network result without being bothered about the nitty gritty details of what a monad is?

Read More

Refactoring MassiveViewController

When to refactor legacy code? Last few releases, I was working on a fairly old code. I was required to implement a small new feature in an item list controller. The controller maintains list of items in horizontal collection view. We were using this controller to show remote items and last seen items (local). Now the new feature was to use another API URL and then transform the received data into appropriate items.

Read More

Functor: Mapping over things!

Prelude Specialization is the key to mastery; functional programming specializes only on function. Thats all there is. The mastery with FP is to reduce complexity, which is what software engineering is all about. Don’t get me wrong, Software engineering is also about delivering product not only over engineering. Delivering real world products used to be the stressful part about functional programming. Not anymore. Specialization on functions creates a whole new paradigm.

Read More

Testing Network Calls with URLProtocol

URLProtocol and Unit Testing An NSURLProtocol object handles the loading of protocol-specific URL data. The NSURLProtocol class itself is an abstract class that provides the infrastructure for processing URLs with a specific URL scheme. You create subclasses for any custom protocols or URL schemes that your app supports. The main point is: All you have to do is define your protocol class and call the registerClass(_:) class method during your app’s launch time so that the system is aware of your protocol.

Read More

Backend As Service from Scratch

Parse was a great initiative. Sadly it went down. It was a fantastic solution for those who want to quickly get their app done and backend was just a breeze. Things changed. However, not all is lost. Parse became open source. The source for Server and Dashboard are both out in the open. I had a mobile app that used Parse heavily . Parse shutdown was really hard for me. I went through all the alternatives but none got me more interested than actually running the infrastructure on my own dedicated linux server.

Read More

Precision Timing in iOS & Swift

Time is what we want most, but what we use worst. -William Pen Timestamp is a very important issue we deal with in every single iOS/OSX project. Unlike timestamp, sometimes we want to measure method performance. Practically, i would use it for fun exploration. However, there are cases especially in games development where the precise time helps maintain consistent gameplay with scores. I explored a bit on how we can leverage the systems provided APIs to just get the current time stamp as precisely as possible.

Read More