Make your life easier with Generics
updated over 1 year ago
This proposal has been withdrawn...
Within an iOS-development team there are two inevitable competing interests:
- the interest of the individual developer to write nifty code
- the interest of the team (represented through a team lead or the company) that the code which gets written is easy to maintain, easy to reuse and that it can be understood by other iOS-developers as well
In theory this is easy and straight forward. However, for a company that does not develop their own products and systems, reality is far away from that. Instead, we have the nagging situation between our projects there is a high degree of similarity. However, the business logic of our different customers constitutes that rather small percentage which breaks the 'easy to bundle and reuse' aspect referred to by the theory. So, where does this leave us at?
'Copying' the code and adapting it to each project or extracting only very rudiment parts and constructs, resulting in frameworks which are not very specific and thus require us to re-implement lots of code repetitively in the projects?
Therefore, we took at closer look at Generics .... - [🙄 a voice from offstage: 'but wait, didn't you say it should be easy to understand????!!!' 😳 ]
Yes, I did say so - and I meant it.😌 There are two aspects to this:
- If you wrapped your head around Generics once and really understood them they are not as complicated as it seems at first glance. In Swift, Apple took some design decisions which on the one hand site make Generics less obvious and explicit (or 'exclaiming' - which means they disturb and distract the flow to a less degree when reading the code). On the other hand they took other decisions which make them even harder to grasp (
PATs - Protocols with Associated Types😱).
- We, as team, arrived at a point where we had different libraries and approaches in lots of our apps which made it even more complex to wrap our head around all those different constructs. This was resulting from the fact that we did not have a valid and sufficient approach on which to build. That invited for experimentation and resulted in the interest of the individual developer beating the interest of the team.
In this talk I want to talk about Generics and PATs, how they can help to write frameworks that can be reused more widely and more flexibly. Based on an example I will show how Generics allow for solutions which some might consider elegant - and of course - I want to offer this approach as an opener for a discussion.
And as uikonf is about the us - people developing with Swift - and about the community: 🤗
How this can free up resources to be able to spend more time on interesting topics on iOS development instead of implementing the next variant of the code we already have written so many times. 🙃