Avoiding primitive obsession in Swift
Alex Curran

While I’ll agree that your intent of making the code more discoverable / readable for new developpers by making functions parameters more explicite is praiseworthy, I’m not quite comfortable about the way you propose to achieve it as I fail to see how adding boilerplate code helps in that regard.

Does it makes that function clearer ? Yes, but it certainly does not make the global code clearer. I think this would rapidly get out of hand in a decent-sized project.

Does it makes that function “safer” ? No.
In my opinion the signature of showDetailsForEmail(withId: String) is already perfectly explicite. If you think a developper could pass a completly innapropriate value to such a function, would you be absolutely certain the same developper wouldn’t construct a struct EmailId with a completly innapropriate value ?

Even the Swjft standard library use primitive types parameters extensively.

Like what you read? Give Jérémy Brault a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.