Quality Coding

Category Archives for iOS Architecture & Design

Emoji: Mind Blown (Exploding Head)

Mental Block? This Is One Weird Trick for Improving Your Code — Really

You face a problem with your code. Maybe something is bugging you about the design approach. Or maybe you’re just plain stuck. What can you do to break through a mental block?

During one job interview, I remember asking how the candidate approached problem solving. That candidate’s answer has stuck with me over the years:

I stop the car. I get out of the car and walk around it. I get back in the car.

This really is “one weird trick,” and surprisingly effective. It acknowledges that repeating the same thing without change will probably yield the same result. So, stop.

You see, once I’ve decided on a tentative approach, my mind digs in. It really wants to push through until that approach yields a solution. But if the approach doesn’t work, my mind keeps digging deeper — digging and digging until ruts form.

I need ways to dislodge my thinking out of that rut. I need to get access to different points of view. There’s one meta-trick, but here are 5 different ways to apply it:

Continue reading

Emoji: Female Factory Worker

Need Feedback Now? Quickly Hack a Spike Test


You’re building a new network call to a server. The thing that will actually use this call isn’t ready. But you’re anxious to see the call work in a full round-trip to the actual server. Basically, you want to know: does this part of the code work? How can you get the feedback you need?

Answer: Quickly hack together any way that works.

The agile workflow is to build, validate, and adjust course. Extreme Programming teaches us to use many feedback loops. And fast feedback is the primary benefit of TDD. …But TDD isn’t the only way I’ve gotten feedback on my Marvel Browser:

  • I did a spike solution to learn how to do request authentication for the Marvel Comics API.
  • Having TDD’d that authentication, I wrote an acceptance test to ensure that it works.

This time, I want to combine these two approaches. It’s a hybrid for which I don’t have a name. Maybe a “spike test”?

[This post is part of the series TDD Sample App: The Complete Collection …So Far]

Continue reading

Value Objects: AppCode’s Code Generation to the Rescue

A Value Object is a handy way to combine multiple values in a single object. It sounds simple — you just make each value a property, right? Well, there’s usually more to it than that. There’s even an entire objc.io article about Value Objects. …So how do you define a new Value Object?

I believe in laziness. Let’s do as little work as possible!

Continue reading

Emoji: Desert Island

Request Model: How to Architect Web Service Apps

Objects are like horses. The less they know about their chaotic surroundings, the easier it is to control them. We don’t want our objects to be spooked when there’s a lot going on. So let’s give our horses blinders, by building ignorance and isolation into our systems.

But how? We typically write mobile apps with these things at the center:

  • Communication with web services
  • User interface
  • Object persistence

These frameworks bore into our apps like warts with deep roots. Web-centric, UI-centric, and persistence-centric knowledge spreads through our apps, making our code tightly coupled. And then we wonder why it’s hard to write unit tests!

Is there an alternative?

Robert Martin’s Clean Architecture offers a different way. Instead of being at the core, things like web communication and even the UI can become plug-ins. They live at the edges of the app. Use cases and business logic become the center of the app.

[This post is part of the series TDD Sample App: The Complete Collection …So Far]

Continue reading

Emoji: Compass

Spike Solutions: 7 Techniques You Can Use


When you’re hiking and don’t know which way to go, what should you do? Stop. Get your bearings.

The same applies to Test-Driven Development; sometimes you need to stop doing TDD, and get some answers.

Those answers can come by switching from clean code to a style of quick-and-dirty hacking called a “spike solution.” I explained the basic idea in How to TDD the Unknown with a Spike Solution.

But what does it look like in practice?

Continue reading

Emoji: Crystal Ball

How to TDD the Unknown with a Spike Solution

So you want to try Test-Driven Development — great! But that requires expressing the intent of the code-to-be in automated tests. Where should you start if you don’t even know what the code should do? What should you do if you’re not confident about a particular approach?

You drive a spike through it!

Continue reading

My Dependency Injection Article in the objc.io Testing Issue

objc.io is a monthly online magazine, with an editorial team. Each issue focuses on a particular subject, and Issue #15 is about Testing. I’m honored to be a contributor with my article “Dependency Injection”.

Continue reading

Kent Beck Inspired Video: Oh, the Methods You’ll Compose!


In the spirit of Dr. Seuss, this video begins,

Dr. Seuss's book, "Oh, The Places You'll Go!"

When a coder sits down to start banging out code,
the first thing to start crowding his cognitive load
is whether his program will do what it should.
“Correctness,” he says, “is what makes my code good.”

But it goes on to explain why clean, readable code matters, and ways to get there…

For such a short video, it has a lot of meat. And I love that last sentence! I really should get a copy of the Kent Beck book that inspired it, Implementation Patterns. (Disclosure: This book link is an affiliate link. If you buy anything, I earn a commission, at no extra cost to you.)

Question: What did you think of the video? Leave a comment below.

Emoji: Shuffle Tracks Button

Refactoring: What If a Book Taught How to Improve Existing Code?

Refactoring book
What would you give to be able to improve your existing codebase with complete safety?

Disclosure: The book links below are affiliate links. If you buy anything, I earn a commission, at no extra cost to you.

The Refactoring book completely changed the way I code.

In 2001 while searching for information on design patterns, I discovered the original wiki, and stumbled on Extreme Programming. This led me to a software development conference in 2002 called SD West. There I attended a session by Martin Fowler, and knew that I had to pick up his Refactoring book that day.

How could I resist a book that promised to teach me about “improving the design of existing code”?

Continue reading