Making stuff correctly always requires more effort and more actions. Result - always returns to u with nice additions.
Moving this idea into programming opens us to limitless abilities. In this article, I want to describe such an option using one task as an example that I faced recently on the project.
problem
The designer adds an element to the screen which displays some text. Part of this text is interactable - we may tap on it and some actions should be triggered - a kind of hyperlink.
Below is how it’s look:
Think about it. What implementation is on u’r mind?
how to think
Be careful when u decide which way to go. Did u think about localization, different screen sizes, what if the clickable text will be placed in the middle, and if this text changes its color? There are can be much more questions. But at least these few must be answered.
If u think first about label and button - yes, it can work, at least for now. But, in the future, when u receive a change request, u can get a problem. Why not think about this?
Going with label+button for this task is the same for me as using view+label+imageView+gesture instead of a button. Will it works? Yes. Is it a good solution - probable not the worst?
Did u change u’r mind regarding implementation?
To make things a bit more cleaner - below are a few more examples of possible use for this component:
Now, I guess u can see possible variants of the component usage and so possible change requests.
Now what?
I highlighted here an idea - idea of how we should think while we make a decision.
This is not only for this particular case - implementing part of UI, but in general - did u think about every factor, every use case (is it possible? ) during taking a decision?.
I have a conversation related to this topic in my work.
- There is a good principle - YAGNI. We can create something with so much flexibility, but we don’t need it right now. Why just not use label+button. It’s a completely exact as a drawn version of the design.
Do we? It might be hard to answer at first. But do we add functionality that is not needed or do we add flexibility to the design? Do we provide some code that is going to be unused or we can create an extendable component without unused functionalities?
The complete code of the solution
Note: this solution was prepared few years ago, some ideas not mine - grab from web. just adapted for modern swift 5 (was swift 3 :] )
conclusion
My rules are simple:
think about worst cases in which u can use something, which u can meet
handle all of them. If it’s too much - maybe u want to combine a few things at one - divide and conquer.
That’s it - nothing more.
Remember - u, as a programmer, must cover 5% of success cases and 95% of failures. So we are working with errors in most cases. Success - just a small chance, and if everything is done right - everybody uses this 5% ;].