Fix Bugs in Your Swift Code

Image for post
Image for post
Photo by David Clode on Unsplash

Get used to it, or bug off!

Deal with the bugs (Approaches)

Clean your area

One way to make your code bug-free is to avoid writing them in the first place!

  • Modularity
  • Simplicity and clarity

Don’t ignore warnings

Warnings are there for a reason and should not be suppressed (Ok, you can suppress some without consequence). Using a linter helps to point out your errors before they grow and become real problems that can stop a release or mean that you’ll be working late into Friday night.

Do it once — do it right.

I’m sure this won’t be a problem to you, but of course you’d never ignore a warning in the first place, would you? Some even put their own errors in their code

Consider ignoring your problems

It seems counter-intuitive, but you can ignore some of your problems and hope they go away. Unprofesssional? Sure. Not-recommended? This is tricky.

Use an issue tracker

There are many different offers of issue trackers for use in teams and organisations. This enables the issues to be triaged and organised into tiers of importance and urgency so the most urgent and important issues get checked first.

Check under assumptions

One of the most important things in coding is checking that the ideas you have and the way that you think things should work is accurate. This can seem simpler to say than to do and the long term strategy is to understand the technology you are working with from the capabilities to the implementation of the same. In the short term some light rubber duck debugging.

Block of the nest (narrow down the problem)

Most IDEs give you some idea of what might be going on in your code. You can step through any given problem using breakpoints and perhaps even more features that can help you find out where the problem is in your code.

Go back to when everything was fine (version control)

You are using GIT, right? If not you have some method of version control? So when did this issue first appear? When you can narrow down when the problem appeared you can can use this to enhance your investigation. Since you know something about the origin of the error you can use this to help you find the solution. Make a new branch and then add back in code at will. You’ll hunt this down, and get the solution right!

Create a MVP

Create a test program to reproduce the error. This might work where you (unfortunately) don’t have modular testable code. You can then separate out the code that is likely to have made the issue, and then add sections back into the program until the problem manifests. This would mean that you’ve found out the original issue and can go and fix it!

Check the underlying design

This one is perhaps the most painful conclusion. The project has not been built on good foundations, and perhaps the whole initial design is not suitable for the project. This can also happen when the project is changed during the implementation stage and then, essentially, can be said to not be the programmers fault.

Recording Bugs

Even if you follow the approaches detailed above, you are still likely to run into problems and issues (and, dare we say it, bugs) in your code.

  • Severity: How important is it that the bug be fixed?

When all is lost (Strategies)

One of the greatest problem solving strategies is the following:

  • have a stress-free sleep

Bugs away (Conclusion)

We all should write perfect code, all of the time. There should never be any bugs, and the software should conform to the requirements and pass User Testing at the first time of asking.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store