Debugging Techniques (डिबगिंग तकनीकें) :-
Program में मौजूद Errors (त्रुटियों) को खोजने और उन्हें ठीक करने की प्रक्रिया को Debugging कहते हैं।
English:
Debugging is the process of finding and fixing errors in a program.
1. Brute Force Method (ब्रूट फोर्स विधि) :-
Brute Force Method, Debugging की सबसे सरल तकनीक (Technique) है। इस विधि में Program के विभिन्न स्थानों पर print() Statements लगाकर Variables की वर्तमान (Current) Values और Program के Flow को देखा जाता है। इससे पता चलता है कि Program किस स्थान तक सही चल रहा है और कहाँ Error आ रही है।
English:
Brute Force Method is the simplest debugging technique. In this method, print() statements are inserted at different points in the program to display the current values of variables and the program flow. This helps identify where the error occurs.
Working (कार्य करने की प्रक्रिया) :-
English:
Example 1: Addition Program :-
Explanation -
English:
Example 2: Finding an Error :-
Explanation-
यहाँ शुरुआत में a = 10 था, लेकिन बाद में a = 100 कर दिया गया। यदि print("a =", a) नहीं लगाया जाता, तो Value बदलने का पता नहीं चलता।
English:
Initially, a = 10, but later it is changed to 100. Without print("a =", a), it would be difficult to notice that the value has changed.
2. Backtracking Method (बैकट्रैकिंग विधि) :-
Backtracking Method, Debugging की एक प्रभावी तकनीक है। इस विधि में Program के उस स्थान से जाँच शुरू की जाती है जहाँ Error दिखाई देती है और फिर पीछे (Backward) जाकर प्रत्येक Step की जाँच की जाती है। इससे Error के वास्तविक कारण (Root Cause) का पता लगाया जाता है।
English:
Backtracking Method is an effective debugging technique. In this method, debugging starts from the point where the error appears and moves backward step by step to identify the actual cause of the error.
Working (कार्य करने की प्रक्रिया) :-
English:
Example
a = 10
b = 20
sum = a - b
print("Sum =", sum)
Output
Error
Program में Addition करना था, लेकिन गलती से + की जगह - Operator का उपयोग कर दिया गया।
Correct Program
Correct Output
Explanation :-
Output -10 आया, जबकि सही उत्तर 30 होना चाहिए था। इसलिए Debugging Output से शुरू की गई और पीछे जाकर देखा गया कि sum = a - b लिखा है। Operator को + करने पर समस्या हल हो गई।
English:
The output is -10, but the expected output is 30. Debugging starts from the incorrect output and moves backward to find that sum = a - b was used instead of sum = a + b. Replacing - with + fixes the error.
3. Cause Elimination Method :-
इस विधि में Error के सभी संभावित कारणों (Possible Causes) की सूची बनाई जाती है और उन्हें एक-एक करके जाँचकर हटाया जाता है, जब तक कि वास्तविक कारण (Actual Cause) न मिल जाए।
English:
In this method, all possible causes of an error are listed and eliminated one by one until the actual cause is found.
उदाहरण (Example)
मान लीजिए Login Program काम नहीं कर रहा।
संभावित कारण (Possible Causes)
Username गलत है
Password गलत है
Database connection नहीं है
Internet/Network समस्या है
Server बंद है
अब इन कारणों को एक-एक करके जाँचेंगे।
4. Program Slicing
Program Slicing एक ऐसी Debugging Technique है जिसमें Program के केवल उस हिस्से (Part of Code) की जाँच की जाती है जो Error या गलत Output से संबंधित हो।
English:
Program Slicing is a debugging technique in which only the portion of the program related to the error or incorrect output is examined.
Example -
यहाँ Average गलत निकलेगा।
Output -
Average = 30.0
लेकिन सही Average होना चाहिए: 20.0
हम केवल उन लाइनों को देखेंगे जो avg को प्रभावित कर रही हैं:
sum = a + b + c
avg = sum / 2
बाकी Lines (a, b, c, print) अभी Ignore कर सकते हैं।