Static Wins! RAH RAH!

Warning: This is a bit of a rant; you’ve been warned.

Recently, the Swift team published this blog: What Happened to NSMethodSignature?

This is the first thought that went through my head:

Or which one of you, if his son asks him for bread, will give him a stone?

Matthew 7:9

Seriously, someone asks for the functionality for dynamic dispatch and you say you can do the same thing with static code! No, you cannot. You can mimic the behavior.

Instead, you showed someone how to build a static registration table. Then you make the statement that it’s “type-safe” while using Any as the arguments to the public API for dispatch and using type coercion… that’s not type-safety. And let’s be honest, it’s really not that different then the validation one does for dynamic dispatch either.

To make matters worse… no one writes that type of code for long without using MACROs because you end up with soooooo much duplicated, boiler plate code. But of course, Swift doesn’t support MACROs. Now you have two choices:

  1. Copy-paste for all the registration items.
  2. Build a custom tool to create the code from some metadata.

You see, and this is the trade-off that you never mention. You paint an extremely biased position without covering the full gambit of what is really needed to build and maintain a system like you are proposing. The reality, it sucks.

And that’s what really irked me about the post: you state the static registration table as the right and better way to solve the problem but speak to none of the drawbacks.

I’ve built systems using both static dispatch tables and dynamic invocation. I cannot say that I’m looking forward to building those same systems in Swift today.

Static Wins! RAH RAH!