+ 1

Can anyone tell how to solve errors wisely????

How do you people actually solve the errors and debug the code , give me tips and tricks

26th Jun 2024, 4:22 PM
john bhasha
john bhasha - avatar
4 Respuestas
+ 5
Learn to read error messages . Or to google for the important parts of the error message. install lsp and linters that can provide helpful hints while writing the code. Be fluent in the language you are using. Syntax errors is a result of not using the language correctly. Understand your data and your goal. Your program might run but not produce what you want. Your method is wrong, or how you use your data is incorrect. Now you have a bug that does not throw an error. Logic errors can only be solved by having a clear understanding on what your program is doing.
27th Jun 2024, 12:21 AM
Bob_Li
Bob_Li - avatar
+ 6
I'm a professional and bug/errors are things you get to deal with for the rest of your life, assuming writing code is constant. However, these are the method that normally help in preventing and reducing my increasing my chance of writing error free codes 1. Always write test for your programs. I have admitted the procedure called "test driven development". I wrote my tests, unit test mostly and sometimes doctest.... Then I write a function that pass the test. 2. Use IDE debugger: I checked my info on my premium CLion IDE and the debugging tools has saved me 4821 times in the month of June. That is a whole lot
26th Jun 2024, 4:30 PM
Mel
+ 4
You'll want get an X-ray view of your program's inner workings to verify that it does what you had planned. Development environments have built-in debugging tools to let you observe those details. Sometimes peppering your code with print statements is a simple way to see what is happening. Print out variable values. Print messages to show which parts of the code get executed. Depending on the language and type of error, it can be good idea to flush the output stream after every print to ensure the message is not withheld in a buffer if there is a program crash. Printing to a log file would be the next level with this approach. It can become a useful permanent feature with configurable levels of detail. Error messages are sometimes inaccurate to determine the root cause. If you are sure the error is not on the reported line, you can try commenting out suspected portions of code until the error no longer occurs.
27th Jun 2024, 3:50 PM
Brian
Brian - avatar
+ 3
Beware of the dreaded Heisenbug. Named after the Heisenberg Uncertainty Principle in physics, the Heisenbug is a bug that moves, or changes its nature, or hides when you try to locate it. Sometimes compiling a different way or just using a debugger is enough to make this skittish bug hide or run to a new location, but it's not gone. It will wait until you think it's fixed and then come right back! If you repress it in one place, it resurfaces another way with completely different symptoms. It's a hard one to outsmart. Usually it is caused by memory mismanagement.
27th Jun 2024, 6:23 PM
Brian
Brian - avatar