Right Click

February 19, 2021

So, all of a sudden my mouse starts acting funky. I can sort of click on things, but I can’t double click. Sometimes when I click, I get a menu, sometimes not. I can’t right click. I can drag things but I can’t drop them. I can’t open stuff with my mouse at all. Some apps seem to work, others don’t respond.

Fine, whatever Mac. You wanna be like that, I’ll restart you and while I do it, I’m gonna think angry thoughts about cheating with Windows.

I restart, same deal.

Now I’m just getting frustrated. I unplug my track pad, turn it off. Same deal. I turn off my wireless mouse. I clean my keyboard (🤷, could be related). I turn off everything. I try using just my laptop trackpad, but it’s doing the exact same thing.

Now I’m getting nervous. I start thinking about rebooting into safe mode, unplugging all my monitors, whatever, really hoping it’s not something Apple needs to fix via snail mail.

But then I have an idea! (yes, these happen… occasionally)

I have a gaming mouse I use sometimes. Maybe it will work. I reach over and pause, only to see it’s already glowing. On it is one of my test devices, an iPad Mini, laying directly on the right mouse button.

Routing in SwiftUI

June 3, 2020

I probably should have waited for the next iteration, but I was starting a new side-project and, well, there was that checkbox to use SwiftUI staring at me, taunting me, luring me in with the sweet promise of unending UI layout bliss. So I scrunched up my face, clicked the box, waited a minute for the trumpets to die down, and then created the project.

This is not a thoughts post on SwiftUI. It’s too early for that. Besides, there’s plenty of posts out there on the interwebby thing if you want an opinion. Plus, I want to wait until version “2” comes out for, you know, when Apple has had a chance to take their beta and turn it into a real boy.

Instead of creating a “thoughts on SwiftUI” post, I’m going to wrap my current thoughts on SwiftUI into what I hope is a somewhat comprehensive — or maybe just an acceptable — discussion on one piece of architecture: Routing. That’s safe, right? It’s not like SwiftUI isn’t going to suddenly change their whole paradigm this year.

Okay, enough with the disclaimers; let’s talk about Routing.

Read More

Thoughts on React Native

April 30, 2020

I’ve been a native (emphasis mine) mobile developer for many years, having learned on iOS 31; and ever since, I’ve been a staunch supporter and firm believer in native-only development. Cross-platform development? Eww, gross, and language please; those words are dirty. No thank you, sir. I’m a clean developer, a master craftsman who actually cares about their work. I don’t slop things together in whatever language. No, I use objective-c Swift. Native-first, native-only, hoo-rah (fist pump)! I breath rarified air from a bag.

Until I don’t.

  1. Or maybe 4? I know I released my first app on iOS 4, but I can’t recall if I actually started in iOS 3. Let’s just say 3, cause it sounds better, right? Also, that fish I didn’t catch because I don’t fish was at least 80 lbs. 

Read More

Interface Design

January 20, 2018

One of the key pillars of good architecture revolves around Interface Design. The reason for this is deceptively simple: software is complex and we want to do everything we can to make it as simple and easy as possible. Part of the entire point of OOP (Object Oriented Programming) is to abstract complicated code into objects and then hide that complexity behind a simplified interface. That way programmers don’t need to know what’s going on behind the scenes, and instead can deal with the abstraction. The interface should be the only thing someone needs to know about that object to use it. The only time someone should even consider the implementation is when they’re modifying it. This is an essential tool in battling the complexity of a codebase.

Read More

Maintainable SRP

March 21, 2017

Most developers have heard of the Single Responsibility Principle (SRP). It is one of the principle pillars of SOLID and frequently touted as a core principle that all developers should strive for when designing their code. It is also one of the least understood principles I’ve ever seen. Most developers will agree that it’s really important, but these same developer will have a hard time defining SRP means in concrete terms. They have an even harder time translating the amorphous concept into their code.

This became painfully clear to me when we had a particularly bright 1 developer create a Rest API Client for our app 2. He was an enthusiastic proponent of SRP and sought to employ the principle in all of his code. Unfortunately, he left soon thereafter for a better job, because to this day, I do not understand what he wrote. His client spanned across 10 different classes and so fully conformed to the SRP principle that no one in our team ever managed to understand how all the pieces came together. Whenever it came to modifying the client to fix a bug or add functionality, that task became one of the few tasks no developer wanted to take up 3. In the end, I recreated the API client as a single class that contained one fifth the original code 4. The experience was eye opening to me. I thought I was a proponent of SRP until he showed exactly how far I hadn’t taken the concept.

Often, complicating a class is simpler than abstracting it out. Except, of course, when it’s not.
Read More

Architecture: The Wrong Discussion

January 3, 2017

Over the past few years, I’ve seen an increasing interest in software architecture as an important, perhaps now even an integral, part of software development. While this may seem obvious now, it’s still surprising to me just how much architecture is considered as an afterthought by many developers. At least in the mobile space, it’s taken a long time for architecture to enter the foreground of the conversation for software development. But even as the discussion about software architecture grows, I’ve noticed that the conversation tends to center on individual architectures as a solution to specific problems inherent in software development. You can see detailed descriptions of VIPER, MVVM (and it’s variants), the ubiquitous MVC as well as a scattering of others for app development. While each of these solutions do address specific set of problems 1, what they do not do is teach developers how to create their own architectures to address problems specific to their own development. As such, many developers will try to use an existing architecture to solve the wrong problem, or else failing that, to forget about architecture altogether and hobble along as best as they can.

While I have been pleased to see the conversations on software architecture, I think to a certain extent they are the wrong discussion. We’ve been discussing the benefits/drawbacks of individual architectures someone else created. What we should be talking about are the principle of architecture that allow us to create the architectures we need.

Read More

A Deeper Look at Handlers

October 10, 2015

Now that I’ve spent quite a bit more time implementing a “handler” based development approach, I’m finding that there’s quite a bit I like about it. I still have some frustrations with it, and some unresolved questions, but overall I think this approach has some serious merits that warrant consideration as an Architecture approach to handling complex dependencies.

To give some perspective, I’ve been using this approach to construct a transport layer client for a messaging service. The service is not simple, with concepts of multiple messaging types, rooms, user, orgs, members, a “mentioning” system, markdown-like parsing, etc. It’s responsible for communicating with a TL layer (via a socket), persisting data, managing sync, updates, etc. As you can imagine, there is a lot of interdependencies doing on here, many of which can only resolve asynchronously via network calls. For example, A Member is a User and and an Org. So before you can have one, you must ensure you have the others. This results in a lot of what I call “asynchronous interdependent behavior” among the various machinations in the code. The reason I turned to a handler-based approach was that I found that these interdependencies were so numerous and varied that attempting a protocol based approach would end in a proliferation of single-use protocols. Moreover, Swift has limitation on protocols that I’m not quite pleased with. This is not to say I don’t use protocols. The TL client exposes itself to the rest of the app (it’s a module) via several protocols. But internally, that was not the right approach.

What I’ve realized is that this approach is extremely useful to a specific set of requirements, but the approach is not useful in all situations. To me, this is a new “tool” I’ve learned… a conceptual model and practical approach useful to a circumstances and requirements I’ve commonly come into contact with. It’s an architectural model useful to solve certain problems but definitely not all problems.

Read More

Handler-based Development

August 15, 2015

Lately I’ve been writing a Swift module for a project at work. I decided to branch out a little bit by utilizing a different design philosophy than I’ve used in the past. While Apple sits around and pretends that protocol based development is actually something new and exciting, I’ve been much more interested in the functional abilities that Swift seems to endow us with. To that end, I decided to escew protocols and instead define the dependencies in my objects using handlers1 instead. This means instead of defining a protocol and requiring an object that conforms to this protocol, I simply require the specific behavior itself. An example of a simple handler might be:

	typealias GetUserForID = (userID: String) -> User

A protocol, instead, might look something like this:

	protocol UserRetrieval {
		func getUserFor(id: String) -> User
	}

At first glance these really look similar, except perhaps the the protocol is a little more verbose, which might not actually be a bad thing. I’ve noticed a trend with Swift devs (myself included) to be overly concise with their code which disturbs me because in the end it simply creates short code that’s impossible to read.

  1. Or callbacks, functors, whatever… I’m going to stick with the term “Handler” because it seems to implicate the dependency, like I’m depending on someone else to “handle” the dependent behavior I need. If you want, feel free to copy this and do a search & replace for callback or functor or another term you feel more comfortable with. 

Read More

View Controllers and Routers

February 19, 2015

If you read my Architecting Complexity post, you know I feel pretty strongly about the need for Software Architecture 1 in software development in general, but especially in “app” development. So far, I’ve not gone in to very much detail into my approach to applying Software Architecture to software development. To be fair, I’m going to focus only on app development, but many of the principles here apply much more broadly. It just happens that developing apps is something I do a lot, so I’ve developed a consistent strategy regarding it.

I can’t put all this in one post, so I’ll be splitting it out into several posts.

  1. Yes, it should always be capitalized. 

Read More

Functionally Taming Optionals

February 15, 2015

There are a lot of blog posts and probably even more opinions about Swift. I will continue this short, but certainly worthy trend.

One common opinion I keep hearing is about how the Optional system kind of sucks, and is perhaps better in theory than in practice. I would like to take a brief, slightly inebriated moment to defend Swift’s optional system and provide some tricks I have found that greatly help to tame the optional system and provide a path out of “if-let nested hell”. 1

But first, let’s talk about why Swift’s Optional is truly great. Many other peopld have spoken of this and Apple itself has loudly proclaimed the benefits. The shell of the nut, though, is this: Optionals force you to deal with the possibility that a value doesn’t exist. If there is a variable (or parameter) and it’s not an optional, you can be sure that variable exists. If it is an optional, the only way to access that variable is to account for the possibility that the value doesn’t exist. After working with my own frameworks and creating apps for client in Swift I will say this: it works. Yes, it may be annoying to deal with at times, but after creating an app in Swift I found there were several types of bugs and crashes that simply did not exist. All of my bugs were functional in nature2. I never had a bug where I thought I was dealing with one Type but instead it was another. Not once did my app crash because an object was nil. Whatever difficulty the Optional system might entail, it is well worth the price of admission, IMHO.

  1. It should always be presented in qoutes, necessary to impart the proper gravity of the situation. 

  2. I’ve also had bugs with the Swift compiler (not to mention the extremely irritating SourceKit Editor crash). But this is improving a lot. I’ve been playing around with Swift 1.2 and it’s convinced me that Apple really is serious about Swift. 

Read More

Protocol Based Software Development

February 6, 2015

When I first started developing software, I made very limited use of protocols. I would occasionally model my software from what I’d seen Apple do with delegates, but once blocks came out I mostly abandoned delegates for callbacks, which I much prefer despite the inherent risks of reference cycles and the weak dance. Because really, why would I want to write my interface in a completely separate file when I already have a convenient “header” file right here. And yet, as I’ve continued to build software and especially as I learn more about software architecture, I find my eschewing interface files and depending on protocols more and more. Let’s just say I’ve become a convert to “protocol based software development”. What exactly do I mean by this?

Well, obviously, it means you use protocols, and I mean use them more than for just delegates. What I mean is that you abstract your interface away from your actual class definition, avoid putting anything in your interface except that it adheres to protocol x, y, etc. Essentially, you construct your interface by conforming to one or more protocols. Here are some “rules”1 for protocol based software development:

  1. Or precepts… or loosely based guidelines 

Read More

Architecting Complexity

January 30, 2015

As a contractor, I come across a lot of other people’s projects and may I just say, there’s a lot of crap out there. And I mean that. Not just “Oh, this developer could have done better here and there”, but more alone the lines of “Sorry, I can’t work with this. Your best option is to rewrite the whole damn thing.” To be clear, I’m not necessarily talking about a person’s coding skills. Certainly, I’ve come across some questionable code and downright stupid approaches to solving problems, but this is not what I’m talking about. I’m talking about a complete lack of any kind of architecture to the codebase. Too often I come across projects that seem to be trying to typify the “anti-design pattern”, usually by stuffing quite literally everything into the View Controllers.

So I want to explain here why Software Architecture is important and, if you’re a developer, why you should be learning it or, if you’re a client, why you want it in your project.

Read More

In Need of Some Conventions

January 24, 2015

There are three things I told myself I would not do when I started developing in Swift:

  1. I would never bang an optional. I think the optional system, though sometimes annoying, is a great idea. Banging optionals is dangerous… as I’m sure my wife would agree.
  2. I would never use an emoji for a variable. Seriously, just because you can do it doesn’t mean you should. Not even the poop emoji. It’s only funny once and then you have to copy and paste the shit all over the place and no one likes that.
  3. I would avoid custom operators for the sake of anyone else that might look at my code.

Unfortunately, I’ve only managed the first two, even though Xcode persistently insists on banging all of my @IBOutlets. And seriously, why? Why do they do that? For the life of me I can’t think of a single reason aside from sheer laziness. I’ve often used the same View Controller for several different Wireframes, many of which don’t have the same views or configuration… thus, ! is stupid and dangerous. It always is and always will be in Swift… don’t use it.

Arg… I got sidetracked. Damns bangs.

Read More

Functional Gibberish

January 21, 2015

My wife used to come home and jokingly complain that I’d sat around all day typing in gibberish into a computer screen. Well, of course it’s gibberish to the uninitiated plebeian. We call it a “language” for a reason. You’ve gotta study and learn the language; you’ve gotta speak it and immerse yourself for the jumble of random characters to magically transform themselves into a document full of meaning and, if you’re really good, perhaps even profundity.

Except that sometimes I stop and stare at the documents I write and think: God, it really does look like gibberish doesn’t it? It doesn’t actually make any sense at all.

Read More