Just Because You Can Multitask Doesn’t Mean Your Methods Need To

I’m a student at the online coding school Launch School. One of the things I have taken to heart in my short time with the program: a method should do one thing.

Before I came to Launch School I would come up with very lengthy and convoluted methods (or loops), they would be difficult for anyone else reviewing my code to decipher what the main purpose is. Now I know (and am working on making a standard practice) that my methods should be simpler. It is better to have more methods with an easy to understand name, and that does one thing clearly, than a method named ‘x’ that is 30 lines long and does 10 things.

To be fair, just knowing this does not make it happen in your code overnight. You still have to work at it as I am doing in my most recent project. For example, I am currently refactoring my Twenty One Game program, the main issue is that my main loop that runs the code is very long. Yes it is the main loop but the more I go over it the more ways I find to add in small methods to break it down further and further. This adds readability for the next person who works on the project, and for me if I come back to this code in 6 months or even 6 days.

So if you thought that was brilliant, you’re welcome, I hope it helps you with your future projects. If you already knew this, awesome! Hopefully next time I will have something closer to your skill level. I plan to keep coming back with tips/tricks/and concepts that I am learning on my journey at Launch School!

Thanks for sharing the adventure with me, and if you too are learning / teaching yourself to program, don’t give up on yourself. We all struggle, and it gets hard for all of us. But if you keep on pushing yourself you can do it! And remember we all feel like this all the time.