Based on interviews from Google, Microsoft, Amazon, Capgemini, etc.
Coding Hacks to help developers write better code
A good programmer does not limit itself to developing code that works but always optimizes code to make it well-formatted so that it is easy to understand and comprehend by anyone else as well.
We reached out to different developers to know their best coding hack that makes their code effective. Here’s what we got to know:
Kunal Purohit Fullstack Developer @Google :
“Be smart enough to ask the dumb questions”
1. I noticed that I grew the most in responsibility and depth of knowledge once I let go of all efforts in trying to look smart in front of my team. Even if you are on the same team for years, there will always be things you don’t know. You may find success learning things solo for smaller tasks, but for projects that have a real impact, you need to reach out to others.
2. I take this approach in all my projects, creating a one-pager of what I need to find out, detailing the information I received, then outlining the work I need to do. In meetings, if someone is discussing a related topic I don’t fully understand I make a dedicated effort to ask for clarity during/afterward.
3. At first, you may think people will think less of you for asking about stuff you think you should already know, and maybe they do! Worst case, your reputation takes a short-term hit, but you still deliver on the project in the end. Slowly, since you are understanding the basic building blocks of your team’s domain, concepts and outlines of tasks will become easier.
Souvik Das Full Stack Developer @ Microsoft :
1) Write Modular Code. Try to follow the “Separation of concern” strategy while writing code. That means trying to write small methods/functions for a specific task or operation.
2) Do not use excessive comments. Better try to declare meaningful variable and method name, Hence no need to add comments. Your code should be descriptive enough.
3) Think about all edge cases while writing code to avoid runtime exceptions.
4) Try to break the big functions into smaller ones. So that it will be easy to understand for others.
5) Try to write descriptive code. Instead of writing complex ternary operators try to write the same using if-else.
Shantanu Kshire Software Engineer @Google :
1. Building Abstractions in code! Not sure whether to call this a hack; however, I think this is a highly effective coding technique. Abstractions make your code much more modular and layered.
2. To optimize code: my pick for an optimization tool goes to Apache JMeter. This is an open-source software focused on load testing Enterprise and dynamic web applications. I have used JMeter to simulate heavy user traffic and analyze (Tomcat/Weblogic) server performance in my professional experience. The tool is highly customizable and a perfect fit for use cases such as –SOAP/REST Web services, Databases, and generating load over TCP/UDP protocols.
3. About Testing code: I think cultivating a habit of writing tests is extremely important for Software Engineering. A rational code testing regime is a path toward building maintainable applications. I like to follow a simple rule
— “Every functional source code change should accompany a unit test”.
During coding, I often implement a Test Driven Development (TDD) process i.e.
1. Write a unit test for a fix/feature which fails
2. Update source code with bare minimum changes to pass the test
3. Refactor code
Ankur Jat Senior Software Engineer @ Microsoft :
There are many but the few best ones are given below:
1. I make a note of code snippets whenever I encountered some best concise code snippets that helped in performance improvement.
2. I keep a cookbook of my own code snippets that gets repetitive. Like file upload code on S3, basic code setup, regex matches, etc.
3. Code review. I keep doing a code review of peers and ask them to do mine. It opens up a new perspective and helps to improve the overall project health.
Akash Bhimani Software Engineering Manager @ Microsoft :
1) Write down what you want to code before you code it.
2) If you are working on others' code, make sure you left it with better quality than before.
3) Makes sure to improve test coverage of the code block you are working upon.
4) Maximize the use of tools to detect and standardize common errors.
Neerav Vyas Bohra Software Developer @ Amazon
1. The tools I use for optimization other than IDE are Mockito and Find bugs for testing.
2. There is no such hack for me, I think thoroughly identifying current and possible future requirements along with significant time given to design make the code significantly effective.
3. So other than Unit tests which run with every build the code gets tested by QA. I usually just do basic sanity testing to fulfill the main requirements.
Antima Pathak Developer @ Capgemini :
The best code hack -would be to include details in your code in a way if you want to use it, what all things would you expect from the code to be doing for you.!! And then the unit test was considering all the scenarios.
Takeaways:
So these are some of the many possible hacks to make your code effective. Eventually, it would come down to your individual preference and environment to decide which habits you can cling to.
As many of the above developers pointed out that improvement is a continuous process so keep practicing and continue to write better code.
What are your favorite Coding hacks? Do you have any thoughts, comments, or questions? Leave a comment below