UPI Study › Courses › System Analysis and Design › Free lessons › Lesson 7.3 Free with a free account
Programming Essentials: Writing, Testing, and Debugging Code
System Analysis and Design · Chapter 7: Implementation, Testing, and MaintenanceSection 7.3 · lesson 48 of 699 min · free with a free account
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of System Analysis and Design.
Lesson complete
Earn the 3 college credits for System Analysis and Design
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: Integration Testing: Combining Modules and Validating Their Interactions Step by Step →← Writing It Down: Documentation and Communication Best PracticesNext lesson: Integration Testing: Combining Modules and Validating Their Interactions Step by Step →
In this lesson
Coding standards, structured and modular code, quality, unit tests, and debugging.
- Explain why coding standards matter, and what they cover
- Explain structured and modular programming
- Identify markers of code quality beyond running without errors
- Explain unit testing, and apply core debugging techniques
Transcript
Everything said in the video, section by section (1,260 words). Read along, or search it.
Implementation, Testing, and Maintenance
Programming Essentials
This section is about the code itself. How it is written, tested, and debugged. We will cover coding standards, and two ways of organizing a program, structured and modular programming. Then what makes code good, rather than just working. And finally, unit tests, and the core techniques for tracking down a bug.
Coding Standards
Not What Code Does, but How It Is Written
A coding standard is a set of agreed rules, for how code should be written within a team or organization. Notice what it governs. Not what the code should do, but how it is written while doing it. Why does that matter? Because code is read far more often than it is written. Think of a developer joining the project months later, or a teammate fixing a bug at two in the morning. They benefit enormously from code that follows a consistent, predictable style. Not code that reflects whatever habits its original author happened to have. Coding standards are one of the most direct ways a team supports maintainability, right at the level of the code.
What a Standard Covers
4 Elements of a Coding Standard
A typical coding standard covers four elements. Naming conventions give consistent rules for naming variables, functions, and files. So a project always uses one form, like calculate total, instead of mixing three different spellings of the same name. Indentation and formatting keep spacing, line breaks, and bracket placement consistent. Every nested block is indented by the same number of spaces. Commenting practices set when and how comments explain code. A good comment above a complex calculation explains why it works the way it does, not just what it does. And file and module organization sets where different kinds of code live, such as keeping database code in its own folder, apart from the user interface.
Structured Programming
Just 3 Control Structures
Structured programming builds a program out of just three control structures. Sequence, where steps run one after another. Selection, where a decision, such as an if-else branch, chooses between paths. And iteration, where a loop repeats a set of steps. Why restrict a program to only these three? Because they stop code from jumping around unpredictably. The flow stays easy for another person to read, from top to bottom.
Modular Programming
One Module, One Task
Modular programming takes a different angle. It is about organization. A program is broken into separate, self-contained modules, functions or procedures, each handling one specific task. A module dedicated to a single task is easier to write correctly. It is easier to test in isolation. And it is easier to reuse elsewhere, compared with one large block of code trying to do everything at once. This is a different idea from encapsulation, from the object-oriented approach. A module organizes code by task. Encapsulation bundles data and behavior together inside an object. The two ideas can, and often do, work side by side.
Figure 7.1
A Structure Chart
A structure chart shows modular decomposition visually. At the top is the module process order. It handles the overall task by calling lower-level modules. Validate order, calculate total, update inventory, and send confirmation. Each handles one piece of the job. Those modules can call further modules of their own. Here, calculate total calls apply discount, and calculate tax. Each arrow shows which module calls which. Process order does not need to know how calculate total works inside. Only that it can call it, and rely on the result. That is the same top-down thinking used to break any large problem into smaller, independently understandable pieces.
Code Quality
Running Is Not the Same as Good
Code that runs without crashing is not automatically good code. Five traits distinguish code that holds up over a project's life. Readability. Another developer can follow what the code does, without excessive effort. Descriptive names, not cryptic abbreviations. Efficiency. The code uses time and resources reasonably, avoiding a slow approach when a faster one is just as simple. Robustness. The code handles unexpected or invalid input, without crashing. Such as checking that a quantity is a positive number before using it. Reusability. A module can be used in another context without being rewritten, like a validate email function any part of the system can call. And documentation. Comments explain non-obvious decisions, such as why an unusual workaround was needed. A function that works, but uses cryptic names and has no comments, is still low quality. It lacks readability.
Unit Testing
Known Input, Expected Output
Unit testing checks the smallest testable pieces of a program, usually individual functions, in isolation from the rest of the system. It is the same unit testing level from the V-Model. Here we see what a unit test actually looks like. A unit test supplies a known input, and checks whether the result matches the expected output. Take a calculate total function that gives a ten percent discount on orders over one hundred dollars. An order of fifty should come back as fifty, because it is below the discount threshold. An order of one hundred fifty should come back as one hundred thirty-five, with the discount applied. And an order of zero, the edge case of an empty order, should come back as zero. Because unit tests are automated, the whole set can be re-run every time the code changes. That quickly flags when a change in one part broke something that used to work elsewhere. This is called regression testing.
Debugging
5 Core Techniques
Debugging is finding and fixing a defect, once a program is not behaving as expected. Five techniques come up in almost every debugging session, whatever the language. First, reproduce the bug reliably. Find the exact steps that trigger it every time, so a fix can actually be verified. Second, read error messages carefully. A message and its stack trace usually point toward where the problem started. Third, isolate the problem. Narrow down which part of the code is responsible, often by testing smaller pieces separately. Fourth, step through with a debugger. Pause at a chosen line, called a breakpoint, and inspect variable values, one step at a time. And fifth, explain the code aloud. Describing it line by line, even to no one, often surfaces the bug. This is sometimes called rubber duck debugging.
Debugging Tools
Debuggers and Logging
Two tools support this work. The most common is a debugger, built into most development environments. It lets a developer set breakpoints, step through code one line at a time, and watch variable values change. Simpler, but still widely used, is logging. Logging means inserting statements that print variable values, or progress messages, while the program runs. It leaves a trail to follow, when a full debugger is not convenient. So what does setting a breakpoint and inspecting variables reveal? Exactly where a variable's value stops matching what was expected. That narrows down where the defect really is.
Key Terms
The Vocabulary of This Section
Let's lock in the key terms. A coding standard is a set of agreed rules for how code is written. Structured programming uses only sequence, selection, and iteration. Modular programming breaks a program into self-contained modules, each handling one task. A structure chart shows which module calls which. A unit test checks one piece of code in isolation. Regression testing re-runs the tests after every change. And a breakpoint is a chosen line where a debugger pauses execution.
Key Takeaways
What to Carry Forward
To pull this together. Coding standards give a team a consistent, predictable style, supporting maintainability at the level of the code. Structured programming limits code to sequence, selection, and iteration. Modular programming breaks a program into self-contained, single-purpose modules. Good code is readable, efficient, robust, reusable, and documented, not just functional. A unit test supplies known input to a small piece of code, and checks the result against the expected output. And debugging relies on reproducing the bug, reading error messages, isolating the problem, and stepping through with a debugger or logging.
About System Analysis and Design at UPI Study
System Analysis and Design (Computer Science 390) is a self-paced online course of 69 video lessons in 9 chapters, from the analyst's role and requirements to UML modeling, interface and database design, testing, maintenance and project management. It carries a NCCRS credit recommendation for 3 semester credits.
Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Enroll now → Course details Download the syllabus All Computer Science courses Every course with PRO →
Why take it here
Why students take System Analysis and Design with UPI Study
Where the credit goes
Universities that work with NCCRS
System Analysis and Design carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.
FAQ
Questions students ask us
About Programming Essentials: Writing, Testing, and Debugging Code
What is the difference between structured and modular programming?
What makes code good quality beyond just running without errors?
What is a unit test, with an example?
What are the basic steps of debugging code?
About the System Analysis and Design course
How many college credits is System Analysis and Design?
How much does System Analysis and Design cost and what is included?
Which universities accept UPI Study credits?
How long does System Analysis and Design take?
How are the exams done?
How do my credits reach my college?
Ready for the full course? Earn 3 credits in System Analysis and Design.
69 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.
3 credits · NCCRSEnroll →