I caught myself saying this the other day and it made me think about how do I deal with bugs in my program.

Bad code gave me cancer

Let’s be honest: if you’re like most of the developers, your code probably has tons of bugs caused by many reasons. So, in this article, we’re going to discuss some practices to avoid bugs while developing software or program…

1. Keep reviewing your own code

Before the code is tested you’ve to look at it a few times. Sometimes you can see some hidden code bug. Every professional software developer knows that a code review should be part of a serious development process. The way to review is self-examination (self-checking your own code), mutual checking, experienced programmers or team leaders to check your code. Also, you can upload your code to GitHub to reviewed by the community.

2. Keep looking at the Logs

This is the part of software development that not all developers take seriously. It is best to take a little time and see the Logs. Useful Logs can provide the developer with tremendous help when trying to understand what the code actually does. Logs like the error, info, and warnings ensure you a good amount of info in your code, you should be easily able to trace what has happened by looking at the Logs.

Programming log review

3. Keep codebase separate that contains problems

Code is the enemy; the more you have the slower you go. And as the code grows the number of Bugs grow even faster. Therefore you have to split the code up, so the Bugs in one part of the code doesn’t affect the other areas. You need to depend on versions artifacts from other modules instead of depending on the source of other modules and provides the Isolation.

Versions artifacts dependencyAdvantages of Version Artifacts

  • Isolation
  • Decoupling
  • Faster Builds

Disadvantages of Version Artifacts

  • Dependency hell
  • No continuous Integration
  • Hard to make global changes

For more info, see Agility Require Safety presentation.

4. Keep writing unit Test

The importance of Unit Test cannot be overemphasized. It’s an excellent way to test your own code. The Unit Test gives developers the peace of mind to change code without worrying about the functionality. It must be written in a serious and responsible manner and try to cover the main business problem. The mistake that is often made in writing the Unit Test is that because of urgency to change Bug and forgetting to change the Unit Test at the same time.

If there are too many Bugs in development stages, it will affect the progress of the task. This is what managers don’t want to see.

Unit Test Image

5. Keep looking at compiler Warnings

Are there new compiler warnings..? That’s the question I ask myself every time before pushing the code on Git. Compiler warnings are very helpful to identify the Bugs in your code. Yes! I know they are too many of them but once every tenth of compiler warnings or so, the compiler actually has a point. We do sometimes write code that compiles successfully but does something odd that we didn’t intend.

Compiler warnings meme

6. Keep a focus on Development

In the era of social media, we’re always disturbed by various information like Instagram, Facebook, Tinder, Whatsapp etc. If we’re constantly interrupted by various things, wait for us to return the original when things are found. So, make sure you’ve no assumptions about your module the existing dependent module and the other modules to be dependent. Try and achieve an interface level agreement among all stakeholders.

7. Keep it simple & Stupid (KISS)

Avoid fancy coding and avoid fancy language features. The more complicated the code, the more likely there’s a bug. Avoid long lines. Instead of writing this:

val launchMissileStatus = missile.getLaunchMissileObject(
            prepareConfiguration().getConfig().confidId,
            getSecureSSHKey(getAdmin().adminId),
            getConnectivityManager()
        ).launchcMissile()
if (launchMissileStatus)
  println("Missile successfully launched")

write

val config = prepareConfiguration().getConfig()
val configId = config.configId
val adminId = getAdmin().adminId
val sshKey = getSecureSSHKey(adminId)
val connManager = getConnectivityManager()
val launchMissileObject = missile.getLaunchMissileObject(configId,sshKey,connManager)
val launchMissileStatus = launchMissileObject.launchMissile()

if (launchMissileStatus)
     println("Missile successfully launched")

It would be way easier to debug and find bugs.

8. Keep using existing Libraries

I’m sure all of you read this line “Don’t reinvent the wheel“. If there are well-tested libraries that do the same function that you’re planning to do then you should use the specific library. You don’t get paid to do what’s already done. I think the following quote is good for this:

The good programmers write code; great programmers steal code.

Alright, this concludes some practices to avoid bugs while programming. If you like what you read please share the knowledge with the community.

What’s next

Ten Simple Rules For Best Programming Practices

Thank you for being here and keep reading…

Author

I’m a mobile product devsigner (i.e. I consider myself as both a developer and a designer) and user experience/interface engineer. I’m an expert on the Android platform and have been recognized as it by the community.

1 Comment

Write A Comment