File: how_to_develop_and_debug_code.rst

package info (click to toggle)
neuron 8.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,760 kB
  • sloc: cpp: 149,571; python: 58,465; ansic: 50,329; sh: 3,510; xml: 213; pascal: 51; makefile: 35; sed: 5
file content (62 lines) | stat: -rw-r--r-- 2,072 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
.. _how_to_develop_and_debug_your_own_code:

How to develop and debug your own code
======================================

Rule I: Don't write a bunch of code (or create a bunch of GUI windows) all at once, and then expect everything to work the first time you try it.
-------------------------------------------------------------------------------------------------------------------------------------------------

Algorithm for developing code that works:

    1. 
        First, break the problem into a sequence of small tasks that can be implemented and tested, one at a time.
    
    2. 
        Pick the first task.

    3. 
        Write the code, or create the GUI tool, that accomplishes this task.
        If this involves anything that you aren't absolutely sure about,
        read the relevant entries in Programmer's Reference, 
        and/or use the GUI on a toy problem to make sure you know what you're doing.

    4. 
        Repeat. Test your program to see if it works. If it doesn't work, re-read the Programmer's Reference and revise the code (or work with the GUI tool) until your program works.

    5. 
        If no more tasks remain, your job is done.
        Otherwise, pick the next task and go to step 3.


Rule II: Learn how to debug your own code.
------------------------------------------

Algorithm for debugging code:

    1. 
        Try to break the code into chunks that accomplish a sequence of small tasks.

    2. 
        Comment out all of the code except for the little bit that accomplishes the first task.

    3. 
        Repeat.  
        Test the code to see if it works.
        If it doesn't work, re-read the Programmer's Reference, then revise the code
        until the code works.

    4. 
        If no more chunks of code remain, your job is done.
        Otherwise, uncomment the next chunk of code, and go to step 3.


The Python Debugger: pdb
-------------

NEURON models implemented in Python may also be examined using `Python's built-in debugger pdb <https://docs.python.org/3/library/pdb.html>`_.