| by The Lonely Coder | No comments

How to Stay Focused while Coding

Stay focused and on schedule while working

With all the distractions we have at our fingertips, procrastination is a real issue that affects everyone, including me. Over the years, I’ve done my research into the most effective ways to stay focused while coding. Without further ado, here are the ways I stay focused while coding.

1. Remove Distractions

Block Phone Distractions

This one may seem obvious, but chances are you aren’t doing it properly. First of all, take your phone and put it in far away from you. You can put it in a drawer, in another room, or give it to a friend temporarily. This way, you’ll be free from annoying notifications that will distract you from your work. If you’re the type of person who absolutely needs their phone by your side at all times, consider downloading an app like Forest for iOS, or Freedom for Android users.

Block Computer Distractions

The next step you’ll have to do is block distractions on your computer. If you’re coding, you’re gonna need to use your computer, so don’t try to use programs that will shut down your computer. Instead, I recommend programs that either limit or block your access to the internet and games. Cold Turkey is a great option for this because it blocks access to all social media websites and distracting programs. Once you start blocking, it’s impossible to undo the block until the timer is done, which is great if you don’t have very good self-control. It’s totally free, but you can buy the premium version which comes with tons of more features. Improve your code

2. Write Good Code

Good code is essential not only for the computer but also for the developer. Messy, unreadable code makes it impossible to interpret and debug if something goes wrong, and can get you frustrated and distracted. I always like to ask myself this questions when writing code: Could I show this to another developer, and could they somewhat understand the code I’m writing? If the answer is no, then you probably have to clean up your code.

Write Comments

Comments are little snippets of text that are ignored by the compiler and are meant for humans to read. They’re necessary if you want to write readable code. The number one rule of adding comments to code is this: Add comments when, and only when they add value. Adding no comments will leave another developer, or your future self, scratching their head about what they’re reading. Too many comments can make your code cluttered and messy.

Write Readable Code

In general, you should always make your code as readable as possible. To check if your code is readable, try showing your code to another developer. If they look through it and don’t have a clue about what’s going on, your code is probably too messy. You should then look through your code and identify any commonly used variables or methods, and try to improve their names. If your language has a standards sheet, like PEP 8 for Python, you can look through that, and see what you can do to improve your code. Lastly, you could send your code to another developer, and see what they are confused by. If they ask you any questions, be sure to clarify the corresponding part in your code.

If any of these helped you stay focused while coding, be sure to share the article on any social media you might have! Put any questions or comments you have in the comments section, or email them to me.

I can’t wait to see you around!

Leave a Reply


This site uses Akismet to reduce spam. Learn how your comment data is processed.