Wednesday, March 15, 2017

That One Optional Property

Soroush Khanlou:

Other code in the view controller switched on the message’s existence to determine which views to allocate, how to lay them out, and so on. The optionality of the property represents more than existence of a simple string. It had implications in the rest of the view controller and the rest of the view layer.

The more essential point here is that the string now no longer represents a string that might be there or might not — it now represents the presentation style or mode that the view controller is in. Was it created in the context of a push notification or through normal browsing? The answer is in this barely related property!

His solution is to replace it with an enum or a promise, both of which have other benefits besides clarity.

Comments RSS · Twitter

Leave a Comment