5 reasons to be addicted to simplicity

Norberto Gil Vasconcelos
Swift Sailing
Published in
5 min readFeb 3, 2017

When I first started out, I was all over the place. I wanted to build amazing apps with the limited knowledge I had. All it led to was over-complicated ways of making things work.

If I could go back and give myself some advice, I’d tell myself to simplify.

KISS (Keep it simple stupid)

— A good friend

Wanna know the key to simplicity? (and the first reason on the list!)

Reason #1 — Modularity

The use of individually distinct functional units, as in assembling an electronic or mechanical system.

— Dictionary.com

Same as Frankenstein’s monster, your app should be created from different and distinct parts. Let’s say you remove FM’s arms. Yeah no more hugs, but all his other parts are functional.

Where is he going with this?

What this means is you can add and remove features from your app without breaking it! That in itself is awesome, but wait! There’s more! Your code is now suddenly cleaner and reusable.

With modular code your initial investment in the code is higher. It takes time to build correctly, however in the long run it simplifies your projects so much, you will wonder why you never did it.

When to do it and why though? Next reason!

Reason #2 — Reusability

Are you copying code from one side to another of your project? Guess that means your app reuses certain features, or has similar features. Whatever the case, that bit of code should be modular. You should be able to feed it some info, and have it, spit out the result where you intended. Let me break it down with some code!

It can be something as simple as formatting a date. Let’s say throughout your app, dates are always shown in the same format:

 dd MMM yyyy

We receive a date, in a JSON, from the server. It’s format is the following:

yyyy-MM-dd’T’HH:mm:ssZZZZZ

How do we convert it to match the formatting of the rest of the app?

Non-reusable code:

// String date from server
let dateString = “1996–12–19T16:39:57–08:00”
// DateFormatter, to transform the string into a date
let dfToDate = DateFormatter()
dfToDate.dateFormat = “yyyy-MM-dd’T’HH:mm:ssZZZZZ”
// Date from server
let d = dfToDate.date(from: dateString) // “Dec 20, 1996, 12:39 AM”

Now we need to convert it to the format we want.

// DateFormatter, to transform the date into the format we want
let dfToString = DateFormatter()
dfToString.dateFormat = “dd MMM yyyy”
// Formatted string from date
dfToString.string(from: d!) // “20 Dec 1996”

Works… but it’s at least 6 lines of code you will have to recreate throughout your app.

Reusable code:

You can make the formatting reusable with a quick extension to the Date and String structs.

extension Date {   func toString() -> String {      let dfToString = DateFormatter()
dfToString.dateFormat = “dd MMM yyyy”
return dfToString.string(from: self)
}}extension String { func toDate() -> Date? { let dfToDate = DateFormatter()
dfToDate.dateFormat = “yyyy-MM-dd’T’HH:mm:ssZZZZZ”
return dfToDate.date(from: self)
}}

Then all you need to do, to format your dates, is the following:

// String to Date
dateString.toDate()
// Date to String
date.toString()

Awesome right? You just cut date formatting down to a couple of lines 😊

Reason #3 — Maintainability

It’s easy to overlook maintainability…

Future me can deal with that!

— Past (scumbag) me

But by taking the time to create modular, reusable code, you are automatically making it easier to maintain your project. For example, going back to the date formatting. Let’s say you decide to change the format in which you display dates, from:

dd MMM yyyy

to:

yyyy, MMM dd

Because the date formatting is all handled in a single place, which is the extension, all you need to do is edit it:

extension Date {   func toString() -> String {      let dfToString = DateFormatter()
dfToString.dateFormat = “yyyy, MMM dd
return dfToString.string(from: self)
}}

Not only was time saved, by not having to dig through code looking for every implementation of a formatted date, but you guaranteed none were overlooked. That means possible errors were avoided!

Another big bonus of modular code is it’s easy to test. Some developers even apply apply TDD (Test Driven Development) to their projects, to “force” themselves into creating modular code right from the get go.

Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: requirements are turned into very specific test cases, then the software is improved to pass the new tests, only. This is opposed to software development that allows software to be added that is not proven to meet requirements.

— Wikipedia

Reason #4 — Consistency

Consistency is one of the hardest aspects to maintain in an app. Especially if more than one person is contributing to the project. Unless all the reasons to ensure simplicity, mentioned above, are applied, keeping the app’s consistency will be a huge challenge.

There are various layers to keep consistent, from design, to front-end code, to back-end code. This is the reason why patterns are invented, a designated way to do things. A pattern will help you, not only to program, or design, in a consistent manner, but will help any one else picking up your work, to quickly dive in and understand what’s going on.

As an iOS developer, you can pick from a wide array of patterns, which I won’t go into at this point, but I’ll leave you with a useful link:

Reason #5 — Readability

Last but not least, readability. Every developer should strive to have clear and readable code. Your aim shouldn’t be Shakespeare, it should be Beatrix Potter (famous children’s author). The point isn’t to have hidden meanings, connotations or possible multiple interpretations. Straight to the point, clear as day is the aim.

One of Beatrix Potter’s illustrations

Once you start striving for simplicity, these reasons will become addictive. You will question every step of development, wondering if there isn’t a simpler way to do what you are doing — Is it modular? Reusable? Consistent? Readable? Maintainable?

Don’t just get the task done, get it done right. 😊

Simplicity is the ultimate sophistication.

— Leonardo da Vinci

I hope this was useful! If you enjoyed it and maybe want more, show me some love ❤

--

--