Important Notice:

Debugging Techniques

Debugging Techniques

49 views 3 min read

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 (कार्य करने की प्रक्रिया) :-

  1. Program लिखें।
  2. जहाँ संदेह हो वहाँ print() Statement लगाएँ।
  3. Program को Run करें।
  4. Output देखकर Variables की Values जाँचें।
  5. यदि कोई गलत Value मिले, तो उसी स्थान पर Error को ठीक करें।

English:

  1. Write the program.
  2. Insert print() statements where you suspect an error.
  3. Run the program.
  4. Check the output and variable values.
  5. Correct the error if an incorrect value is found.

Example 1: Addition Program :-

a = 10
b = 20

print("a =", a)
print("b =", b)

sum = a + b

print("sum =", sum)
 
Output-
a = 10
b = 20
sum = 30

Explanation -

  • पहले a और b की Values दिखाई गई।
  • फिर दोनों का योग (Sum) निकाला गया।
  • अंत में Result Display किया गया।
  • यदि किसी Variable की Value गलत होती, तो print() से तुरंत पता चल जाता।

English:

  • First, the values of a and b are displayed.
  • Then their sum is calculated.
  • Finally, the result is displayed.
  • If any variable had an incorrect value, the print() statements would reveal it immediately.

Example 2: Finding an Error :-

a = 10
b = 20

a = 100

print("a =", a)
print("b =", b)
sum = a + b
print("sum =", sum)
 
Output -
a = 100
b = 20
sum = 120

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 (कार्य करने की प्रक्रिया) :-

  1. Program को Run करें।
  2. जहाँ Error दिखाई दे, उस स्थान की पहचान करें।
  3. Error वाले स्थान से पीछे (Backward) जाएँ।
  4. प्रत्येक Variable और Statement की जाँच करें।
  5. Error का कारण खोजकर उसे ठीक करें।

English:

  1. Run the program.
  2. Identify the point where the error occurs.
  3. Move backward from the error point.
  4. Check each variable and statement.
  5. Find and fix the cause of the error.

Example

a = 10

b = 20

sum = a - b

print("Sum =", sum)

Output

Sum = -10

Error

Program में Addition करना था, लेकिन गलती से + की जगह - Operator का उपयोग कर दिया गया।

Correct Program

a = 10
b = 20

sum = a + b

print("Sum =", sum)

Correct Output

Sum = 30

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 -

a = 10
b = 20
c = 30

sum = a + b + c
avg = sum / 2

print("Average =", avg)
समस्या (Problem)

यहाँ Average गलत निकलेगा।

Output -

Average = 30.0

लेकिन सही Average होना चाहिए: 20.0

हम केवल उन लाइनों को देखेंगे जो avg को प्रभावित कर रही हैं:

sum = a + b + c

 avg = sum / 2

बाकी Lines (a, b, c, print) अभी Ignore कर सकते हैं।

Related Notes