Data independence is key to robust architecture and non-fragile unit tests

I have an 8-year old girl who rides the school bus to go to her school every morning. So we’ve waited for the school bus together on the sidewalk. But some day I drove behind a school bus and had to stop when the bus stopped to allow the kids cross the street safely.

With nothing to do, I looked at the school bus and noticed something. It has a different vehicle number than the route number. My girl remembers her route number on the very first day of school. But we never knew there’s also a vehicle number.

And there’s a reason for that, and a lesson to learn. The vehicle number is for the mechanics, whereas the route number is for the students. The same bus is presented to the mechanics and the students differently, so that the information is useful, and not a hindrance.

We can apply this simple HIG from the real world to our code.

Continue reading →

Should you check in your dependencies?

No matter the platforms you develop on, any sane developer knows it’s prudent to use a source code repository and check in their commits when progress is made. This is just common sense among us. But what about your dependencies?

Should you also check in your dependencies? In the iOS world, that means CocoaPods or Carthage.

The short answer is yes. You should always check them in.

For the longer answer, …

Continue reading →

How to add reactive-ness to Clean Swift

I answered different forms of this same questions many times in emails, comments, and my mentorship program. I understand why people ask this question. They’ve seen MVVM, ReactiveCocoa, RxSwift, and want to see if Clean Swift can handle this model-view update automatically.

My answer is always the same. You don’t need it. You don’t need to add yet another dependency just to do this simple thing.

Your interactor can invoke a method of the presenter multiple times, and/or invoke multiple methods of the presenter.

The following is taken directly from a discussion in my mentorship program.

Continue reading →

Organizing source code files by type vs intent

All of us have certainly seen source code files being organized by types. There’s a group named View Controllers, a group named Models, a group named Views, and so on. But organizing by types like this may not be a sound strategy.

Such code organization doesn’t provide any useful context about why you group some files together, while keeping others separate.

It is also redundant. PostsViewController.swift already tells you it’s a view controller. PostView.swift already tells you it’s a view. Putting a view controller file inside a View Controllers group, and a view file inside a Views group isn’t going to help you learn anything new. It feels so redundant just by reading it. Isn’t it?

It doesn’t scale well. When your app is in its infancy with just 5 view controllers, it’s manageable. But when it grows to have 35 view controllers, you’ll have 35 files listed under the View Controllers group.

As programmers, we know vertical screen real estate is at a premium. And most of us are allergic to scrolling. Constant expanding and collapsing groups is just not very productive.

Continue reading →

Full routing analysis

Last time, we looked at the route from the ListOrders scene to the ShowOrder scene in details. This time, we’ll examine all the routes from all the scenes in the CleanStore app, so that you can see how the new and improved router handle other situations.

Routing in Clean Swift is a simple 3-step process:

  1. Getting a hold on the destination
  2. Passing data to the destination
  3. Navigating to the destination

Every route goes through these 3 steps. Step 2 is optional if you don’t have any data to pass. Step 3 is also optional if you use storyboard segue. So routing can be even simpler than this 3-step process.

In other words, if your route is based on storyboard segue and you don’t need to pass data, you can skip steps 2 and 3. If you skip them, that means you don’t need the destination references, and you can skip step 1 too. You don’t have to do anything!

Continue reading →