Code

What Bugs Are and How to Avoid Them

What Bugs Are and How to Avoid Them

Learn: The DevOps Engineer Profession

Learn More

A well-known story about a software bug that led to tragic consequences concerns the American Patriot missile defense system. This system is designed to track objects moving along a predetermined trajectory. However, due to a code error, the calculation error increased with each minute the system was running. At one base, the system was active for 100 hours, which eventually led to a complete failure. An incorrectly calculated course for an attacking missile resulted in an impact on the base, killing 28 people. A patch to fix the error was released only the following day. This situation highlights the importance of thorough software testing and regular security updates.

NASA has also encountered problems due to software bugs. One of the most famous incidents involved the Mars Climate Orbiter satellite, which was lost in space. This was caused by a simple but critical error: the contractor failed to convert feet and pounds to the metric system. The control center sent commands specifying forces in newtons, while the software interpreted these data as pounds-force. As a result, the $125 million apparatus flew too close to the surface of Mars and failed. The mission ended in failure, highlighting the importance of precision in engineering projects and programming.

We've collected helpful stories from professional developers and prepared a brief guide to help you minimize the likelihood of errors in your code and protect against their potential consequences. By applying best practices and tips, you can improve the quality of your software and improve its stability.

How to complicate code so that no one can understand it

Alexey Nekrasov is the leader Python Program Director at MTS and Program Director for Python at Skillbox. With his experience and expertise, he plays a key role in the development of Python as one of the most in-demand programming languages ​​in the modern IT sector. Alexey actively participates in training and supporting professionals seeking to master Python, which contributes to the professional development and expansion of students and professionals in this field.

Early in my career, I became fascinated with functional programming and decided to apply this paradigm to solve a new problem. At the time, an object-oriented model had already been implemented on the project. The problem I faced was the following:

When developing the solution, everything seemed clear enough. However, a month later, my manager asked me to look into the code. We spent about 30 minutes trying to understand its logic and identify the error. Comments in the code would have significantly facilitated the process, as I would have remembered my intentions faster. Unfortunately, there were none. Ultimately, I had to rewrite the entire code.

Here are some tips that may be useful. First, it is important to always set clear goals and objectives. This will help you focus on the main thing and avoid distractions. Second, regularly analyze your actions and results to understand what is working and what is not. This will allow you to make necessary adjustments and improve your strategies. Also, don't forget the importance of self-education. Continuously developing your skills and knowledge will help you stay competitive in a rapidly changing world. Finally, surround yourself with people who inspire and support you. This will create a positive atmosphere and help you achieve your goals.

  • Try to maintain a consistent style, otherwise your project will eventually become a mess.
  • Don't show off your coolness by using complex solutions—after a while, you won't be able to read your own code. And if there are other developers nearby, it will be completely uncool.
  • Don't engage in premature optimization.
  • Give variables clear names: after three months, it's hard to remember what exactly a variable is supposed to do.

How to waste two days searching for a bug because of haste

Mikhail Korneev is a team lead at BestDoctor and the author of the popular YouTube channel "Cunning Python." He shares his experience in software development and teaches viewers the basics of Python programming. His channel features numerous useful video tutorials that will help both beginners and experienced developers improve their skills. Mikhail actively shares his knowledge and best practices, making his content a valuable resource for anyone interested in IT and programming.

I was developing a prototype for a project and made a typo in an inconspicuous place. This minor error led to two days of intensive debugging, as my application began periodically disconnecting. I had to dig deep into the Python code and nginx server settings to identify and fix the problem.

To reduce the time spent troubleshooting, it would have been wise to break the code into smaller blocks and test each one before going into production. However, this wasn't my primary focus, and I was focused on creating a prototype as quickly as possible. As a result, I had to spend a lot of time identifying the source of the error, as it manifested itself at the intersection of several different systems.

How to protect yourself from such problems:

  • Remember that errors will always be there, so you need to write your code in a way that makes it easier to find problem areas later.
  • Understand testing and be sure to write tests.
  • Check how the code works: for example, whether it runs or not. Most errors are typos. If you have tests, you will see them. But if you don’t, and you still run the check, you will surely find other problems. I have repeatedly seen a novice developer close a task without checking the code - in the end, it simply does not work.
  • Be sure to submit the project for code review. This is a useful practice.
  • If you program in Python, you should understand typing. And remember that explicit is better than implicit. This will allow you to catch some errors while you are still writing the code.
  • Make backups of the database and different versions of the code in case everything breaks. And this happens quite often. If something goes wrong, but you have a backup, nothing bad will happen. A recovery plan is a must for any project.

How to Bring Big Losses to a Company Without Speaking

Alexey Firsov is the head of Python practice at S7 TechLab. In his role, he is responsible for the implementation and development of Python technologies within the company's projects. Alexey has extensive experience in Python programming and actively shares his knowledge with the team, which contributes to the improvement of development quality and the implementation of modern solutions. Under his leadership, S7 TechLab uses Python to create efficient and scalable applications, allowing the company to remain competitive in the technology market.

I worked in the billing department at a well-known company, where one of the tasks was to create a program for calculating bonus percentages. We discussed a possible solution, and the developer began implementing it. However, while completing his task, he made a change to one of the modules of the old code without notifying the team. As a result, the testers focused exclusively on checking the new code, which led to unexpected errors and flaws in the system. This case highlights the importance of team communication and a careful approach to code changes, as even small edits can significantly impact the functionality of the product.

While editing the old module, the programmer made an error by using the float data type. The use of floating-point arithmetic for monetary calculations is unacceptable, leading to higher-than-normal bonuses and, consequently, significant financial losses for the company. Two people are responsible for this situation: the developer who failed to notify the team of code changes and the manager who neglected the review process. To reduce the risk of such errors, programmers should document code changes so that the QA team can fully test all new system components. This will not only improve code quality but also help avoid unnecessary losses in the future.

Dangerous bugs arise from two main factors. The first is due to shortcomings in the development process, when programmers fail to consider all possible software use cases. The second is due to insufficient testing, which can lead to some bugs remaining undetected until they begin to cause serious problems. These bugs can negatively impact product functionality, data security, and user experience. To reduce the risk of dangerous bugs, it is necessary to implement high-quality development and testing processes, as well as regularly update the software.

Among the common, though less critical, bugs, there are often problems related to sudden network outages. For example, the security department once disabled internet access without notifying the team. As a result, a required service could not be launched at the scheduled time. Such bugs are usually quickly identified and easily resolved. Incidents like these highlight the importance of clear communication within the team and regular monitoring of the network infrastructure. Errors in systems often arise during the integration process and can be easily fixed by rolling back or changing the code. For example, when integrating our service with payment systems that do not provide a test environment, we were unable to test the code in advance. As a result, testing was conducted directly in the production environment. In such situations, it is important to develop a strategy in advance to avoid injecting traffic into the system during testing, which will help minimize risks and ensure stable service operation. Architectural errors can arise during software development. In one of my projects—a startup without a dedicated quality assurance team—we developed a bot that performed actions according to a predetermined script. After each step, the next step had to be specified. When we launched the project in production, it turned out that the script referenced itself, leading to an infinite loop. As a result, the system stopped functioning. Such architectural bugs highlight the importance of thorough testing and script logic review before launching a project.

DevOps Engineer Profession

You will learn to administer Linux, configure web servers, and master the DevOps methodology: you will automate the development of complex IT products. Get support from the Career Center and become a Junior Specialist in 7 months. This course is suitable for you, even if you have never worked in system administration or programming.

Find out more