Take Care of Your Code!
Methods can be very useful in programming. They are making our code looks better, if we use it the right way. But some programmers don’t really pay attention to method (the clean way). They just keep doing a lot of stuff in one method. In this article, I will give you an example of messy method vs clean method.
Example : Messy method
This example gives us understanding that writting a messy method is a bad habit. scrollViewDidScroll method do some different things. it’s calculating, and configuring the UINavigationBar appeareance. This is a bad example of a method.
Clean Method Rules
These are some rules which I think the most important :
- Meaningful names
- Object Params (if current Params are too many)
- do one thing!
Example : Clean method
Now you have witness the clean way of using and creating a method. This example makes the reader clarity when trying to understand what is really going on. On the scrollViewDidScroll method, it’s only one thing happend. Instead of doing manything on the method, It’s calling another method to handle other thing, which is have a descriptive name. With this approach, other programmers or maybe non-programmers can undestand easily.
Clean method delivers a clean approach to write and use a method. This approach give a clear statement what method is and what method meant for. If you apply the clean method way, your code will look nice, easy to read and understand by yourself or other programmers in a team, because you are taking care of your code. Keep your method clean and happy coding!