The debugging method that you described is ideal for a static language such as C ++, but provided that the language is so different, the encoding methods are similar to each other. One of the important very important things in a dynamic language, such as Python or Ruby, is interactive toplevel (what you get by typing, say, python on the command line). This means that executing part of your program is very simple.
Even if you wrote a great program before testing (this is a bad idea), we hope to divide it into many functions. So, open your interactive level, do an import thing (for any thing ), and then you can easily start testing your functions one by one by simply calling them at the top level.
Of course, for a more mature project, you probably want to write down the actual test suite, and most languages โโhave a way to do this (in Python these are doctest and nose , I don't know about other languages). At first, however, when you write something not quite formal, just remember a few simple rules for debugging dynamic languages:
- Start small. Do not write large programs or test them. Check every function when you write it, at least easily.
- Use the top level. Running small pieces of code in a language such as Python is extremely easy: launch the top layer and run it. Compare with writing a complete program and compiling it, say, in C ++. Use the fact that you can quickly change the correctness of any function.
- Debuggers are convenient. But often these are also
print expressions. If you use only one function, debugging with print statements is not inconvenient, and also frees you from dragging and dropping around the IDE.
pavpanchekha
source share