OCR H446, section 2.2.1 (e)
An Integrated Development Environment (IDE) is a program that combines the tools a programmer needs in one place: for writing, running, testing and debugging code. Examples include Visual Studio Code, PyCharm, IDLE, Visual Studio and Eclipse.
Features for writing code
| Feature | What it does |
|---|---|
| Code editor | Where you type the code |
| Syntax highlighting | Colours keywords, strings, comments and numbers, so mistakes stand out |
| Auto-complete / code suggestions | Offers names and commands as you type, saving time and typos |
| Auto-indent and bracket matching | Keeps layout correct and pairs brackets and quotes |
| Line numbers | Match error messages to the right line |
| Code folding | Collapses blocks so that you can focus on one part |
| Templates and snippets | Insert common code structures |
| Refactoring tools | Rename a variable everywhere, or extract code into a subroutine safely |
| Linting / error underlining | Spots syntax errors and likely mistakes as you type |
| Documentation lookup | Shows what a command does and which parameters it takes |
| Search and replace | Find or change text across many files |
| Project management | Organises many files and libraries together |
| Version control | Tracks changes to code, and lets you go back (for example Git) |
Features for running code
- A translator (interpreter or compiler) built in, so that the program can be run with one click.
- Output windows and a console for input and output.
- Error messages that give the type of error and the line where it occurred.
- Build tools and libraries managed for you.
Features for debugging
Debugging means finding and fixing faults (bugs). The IDE's debugger helps by letting you control and watch the program as it runs.
| Debugging tool | What it does |
|---|---|
| Breakpoint | Marks a line where the program pauses, so you can inspect it at that point |
| Single-stepping | Runs one statement at a time, to follow the flow |
| Step into / step over | Step into goes inside a subroutine. Step over runs the subroutine in one go |
| Variable watch | Shows the current values of chosen variables as the program runs |
| Variable / memory inspector | Shows all variables in scope, and their values |
| Call stack view | Shows which subroutines are active, and the order they were called |
| Conditional breakpoint | Pauses only when a condition is true (for example i == 50) |
| Error diagnostics | Shows the line where an error occurred, and its type |
Types of error
| Error | Description | Example |
|---|---|---|
| Syntax error | Breaks the rules of the language; the program won't run | A missing colon or bracket |
| Runtime error | Happens while running; the program crashes | Divide by zero, index out of range |
| Logic error | The program runs but gives wrong results | Using > instead of >= |
Syntax errors are found by the translator and shown by the editor. Logic errors are the hardest to find, and the debugger and trace tables help here.
Using a debugger: a method
- Reproduce the bug with a known input.
- Predict what should happen.
- Set a breakpoint before the suspicious code.
- Step through and watch the variables.
- Find the first point where a value is different from what you expected.
- Fix it, then re-run the tests to check the fix and that nothing else broke.
Worked example
Task: this function should return the average of a list, but average([2, 4, 6]) gives 2.0 instead of 4.0. Explain how you would use the IDE to find the fault.
def average(nums):
total = 0
count = 0
for n in nums:
total = total + n
count = count + 2
return total / count
Steps:
- Breakpoint on the line
return total / count. - Run with
[2, 4, 6]. The debugger pauses there. - The variable watch shows
total = 12(correct) andcount = 6. It should be 3. - Single-step through the loop with
countin the watch. It goes 2, 4, 6, so it goes up by 2 each time. - Fix: change
count + 2tocount + 1. - Re-run to check the result, 4.0.
This was a logic error: the program ran with no error message but gave a wrong answer. The IDE's syntax checker would not have found it, but the debugger did.
Exam tip: name the feature and say what it does ("a breakpoint pauses the program at a chosen line so that the values of variables can be inspected"). Link each feature to developing (writing) or debugging (finding faults). Know the three types of error.
Check yourself
What is an IDE?
An integrated development environment: a program that combines the tools needed to write, run, test and debug code in one place.
Give two features of an IDE that help when writing code
Any two of: syntax highlighting; auto-complete; error underlining; auto-indent; code folding; templates; refactoring; documentation lookup; version control.
What is a breakpoint?
A marker on a line of code where the program pauses during debugging, so that variables and the state of the program can be examined.
What is the difference between stepping into and stepping over a subroutine?
Stepping into goes inside the subroutine, one line at a time. Stepping over runs the whole subroutine in one go and stops at the next line after the call.
Which type of error is the hardest to find, and why?
A logic error, because the program runs without an error message but gives wrong results.