01 logo

5 tricks to develop the habit of coding

I’ve been in the software industry for the past five years. I’ve worked with good coders as well as bad ones. The dominant quality of a good coder is their ability to improve their code.

By Student MattersPublished 3 years ago 4 min read
1
Source: google.com

We were taught to code to make things work. Beginners mostly focus on output. If their code is working fine, then they consider it done. Some develop this approach as a habit even later in their careers.

Today, I’m going to talk about five techniques to improve your code. These will help beginners as well as more experienced programmers to revamp their coding.

Every programmer codes in a different way. They develop a way to write the code that’s natural to them. It’s like handwriting — it develops with practice. We’ll learn how to improve that process.

1. Spend Most of Your Time in Analysis

Most programmers directly jump into coding after looking at the requirements. This ignorance is pretty common among freshers in the software industry.

They usually believe that coding is a major part of the solution. That’s not true. As one of my senior developers once told me:

Spend 70% of your time in analysis and do the coding in remaining.

This saves you from having to spend time fixing bugs and optimizing your code at the last moment. Most people can code by Googling logic, but an actual programmer knows how to do the proper analysis before rushing toward coding.

How to do it:

Whenever you start working on anything, first analyze the existing code. Run and debug the existing functionality.

Then you have to come up with a solution where you can add your feature without breaking the existing flow of the application. Once you’ve done that, start writing the code.

2. Look for Multiple Solutions to a Problem

Most programmers look for a solution. Once they achieve it, they move to different problems. However, spending more time finding multiple solutions to a problem will have many benefits:

  • Your logical thinking will enhance over time.
  • You have a choice to select the best solution from multiple options.
  • Your approach toward solving a problem will improve.

This method will help you to develop critical thinking as required in later stages of programming. The good programmers are expected to come up with multiple solutions so that the best can be selected based on speed, memory, and other factors.

How to do it:

If you’re unable to find more than one solution, then search online. You will definitely find alternative approaches to your problem on platforms like StackOverflow and CodeProject.

This way, you’ll develop a habit to look out for more solutions to a single problem.

3. Don’t Mind Your Own Business

Well, that’s true in the case of coding at least. You should read other people’s code. Try to do that on regular basis.

As I said, we all have a unique style of coding. Reading other people’s code will give us more insights that can be beneficial for us. I’ve learned a lot from reading other developers’ code on my project team.

This will help you understand the bigger picture as well. If you keep coding for yourself, then you won’t be familiar with other parts of the applications that you haven’t worked on.

How to do it:

Once you have completed your work, then start reading code committed by other developers. This will help you to understand their thought processes and you’ll learn more about your product.

4. Test Your Patience

Unit testing is way more important than most developers realize. Programmers think that the main purpose of unit testing is code coverage, but that’s not true.

Unit testing helps you to eliminate the non-required lines of code. It helps you to improve your code and overall application performance.

How to do it:

Always write unit test cases for your module. Try to achieve as high as 90% code coverage and remove the unnecessary parts during the process. If possible, discuss the scenarios with other developers so you won’t miss out on anything important.

5. Update Yourself Before Updating the Code

If you don’t keep yourself updated with the latest technological features, then how can you make sure your code is up-to-date?

The reason most software dies over time is because of developers neglecting to update the code for optimization. For instance, take a look at below C# code:

// Old approach

If (sampleObject != null)

{

If (sampleObject.result != null)

{

string result = sampleObject.result;

}

}

// New approach

If (sampleObject != null)

{

string result = sampleObject?.result;

}

In the old approach, we first checked whether the object was null or not, and then we checked if a particular value inside that object was available. Only after that did we assign that value to a variable.

In the new approach, we’re using the new C# feature, which was introduced in version 6.0. This lets us directly query the object properties, and in the case where a property has null, then instead of throwing a null reference exception, it returns the null value.

This is one example of how we can simplify and optimize our code with new features in the language.

How to do it:

Follow tech blogs and read the documentation on new features. Use them in your pet projects, and if possible, apply them in your work projects as well.

This helps you stay updated, and you can keep your code healthy and up-to-date.

Source: Medium.com

how to
1

About the Creator

Student Matters

Reader insights

Be the first to share your insights about this piece.

How does it work?

Add your insights

Comments

There are no comments for this story

Be the first to respond and start the conversation.

Sign in to comment

    Find us on social media

    Miscellaneous links

    • Explore
    • Contact
    • Privacy Policy
    • Terms of Use
    • Support

    © 2024 Creatd, Inc. All Rights Reserved.