Software Implementation & Coding MCQs for NSCT
Software implementation is the stage where a design becomes working code. For the exam it means three things: following coding standards, reviewing code to catch defects early, and refactoring to keep code easy to change. It is topic 9 of the Software Engineering area, which carries 10% of the NSCT according to HEC's Areas of Competencies. In 2026 candidates averaged 50.1% in Software Engineering, per the HEC NSCT report and APP.
Sommerville adds three implementation issues beyond writing code: reuse (of functions, components and whole systems), configuration management (tracking versions and builds) and host-target development (building on one machine for another platform). Expect at least one question on that list.
Coding standards
A coding standard is a team's shared set of rules for naming, layout, comments and safe constructs. Consistent code is faster to read and review, whoever wrote it. For Python, the reference is PEP 8.
| Item | PEP 8 rule | Example |
|---|---|---|
| Indentation | 4 spaces per level | |
| Functions and variables | lowercase_with_underscores | calculate_gpa |
| Classes | CapWords | StudentRecord |
| Constants | UPPER_CASE | MAX_CREDITS |
| Line length | 79 characters (72 for comments) | |
| None checks | use is / is not |
if result is None: |
Good standards also ban risky habits. Each of these Python snippets was run to confirm its output:
total = 0.1 + 0.2
print(total == 0.3) # False: binary floating point
print(abs(total - 0.3) < 1e-9) # True: compare with a tolerance
def add_item(item, basket=[]): # default list is shared between calls
basket.append(item)
return basket
add_item("pen")
print(add_item("ink")) # ['pen', 'ink']
Exam angle: formatting rules are best enforced automatically by a formatter and linter, a form of static analysis (checking code without running it). Human reviewers can then focus on logic.
Code reviews
A code review is a systematic check of code by people other than the author. The forms range from informal to formal:
| Form | Led by | Formality | Main goal |
|---|---|---|---|
| Pair programming | The pair (driver and navigator) | Continuous, informal | Catch defects as code is written |
| Walkthrough | The author | Low to medium | Explain code, gather feedback |
| Inspection (Fagan) | A trained moderator | High: roles, checklists, recorded defect data | Find as many defects as possible |
A Fagan inspection has fixed roles: the moderator leads, the reader paraphrases the code, the recorder logs defects, the author does the rework, and inspectors look for defects. Its stages are planning, overview, preparation, the inspection meeting, rework and follow-up. Reviews aim at defects, not at judging people.
Exam angle: when a review question lists several findings, rank them by risk. A SQL query built by pasting in user input (SQL injection) outranks any naming or spacing comment.
Refactoring
Fowler defines refactoring as changing a program's internal structure to make it easier to understand and cheaper to change, without changing its observable behaviour. Automated tests must be in place first, so that each small step can be checked.
Refactoring is guided by code smells, surface signs of deeper design problems:
| Smell | Symptom | Typical refactoring |
|---|---|---|
| Duplicated code | Same logic pasted in several places | Extract Method |
| Long parameter list / data clumps | The same values always travel together | Introduce Parameter Object |
| Feature envy | A method uses another class's data more than its own | Move Method |
| Switch statements | The same type check repeated in many places | Replace Conditional with Polymorphism |
| Large class | One class with many responsibilities | Extract Class |
| Shotgun surgery | One change needs edits in many classes | Move Method / Move Field |
| Magic number | An unexplained literal such as 3500 |
Replace Magic Number with Symbolic Constant |
Exam angle: if a "refactoring" changes output for any input, it is not a refactoring. A common slip is changing > to >= while extracting a method.
Common traps
- Calling a bug fix or new feature "refactoring". Refactoring never changes behaviour.
- Mixing up shotgun surgery (one change touches many classes) and divergent change (one class changes for many reasons).
- Thinking a walkthrough is led by a moderator. The author leads it; the moderator leads an inspection.
- Using
assertto validate user input. Python strips assertions when run with-O. - Catching every exception with a bare
except:, which hides real errors. - Writing comments that repeat the code instead of explaining why.
Worked examples
Understanding. What does the recorder do in a Fagan inspection? Answer: logs every defect found, with its type and severity. The moderator leads, and the author fixes the defects afterwards.
Application. What does this print?
for i in range(3):
pass
print(i)
Answer: 2. A Python loop variable stays defined after the loop ends and keeps its last value. Some coding standards discourage relying on this because it is easy to misread.
Analysis. Three modules each contain their own copy of a grade-point calculation. A bug was fixed in one copy only. What is the root cause, and what is the best fix? Answer: duplicated code. The fix had to be made three times and two copies were missed. Extract the logic into one function (Extract Method) and call it from every module, following DRY (Don't Repeat Yourself).
Practise
The quiz below has 99 Software Implementation & Coding questions, which you can filter by tier and difficulty.
Practise: 99 questions
FAQs
What is the difference between refactoring and rewriting?
Refactoring changes structure in small, behaviour-preserving steps, each checked by tests, so the system keeps working throughout. A rewrite replaces the code wholesale, which risks losing hidden behaviour that users depend on. For legacy code without tests, write characterisation tests for its current behaviour first, then refactor.
Is a code review the same as testing?
No. A review examines code without running it (static verification), while testing runs the code with inputs (dynamic verification). They catch different defects: reviews find unclear logic, standards breaches and security risks that may never show in tests, and tests find run-time failures. Sommerville recommends using both.
Why does PEP 8 say to compare with None using is?
None is a singleton: there is only one None object. is checks identity, which is exactly right, and a class cannot override it. == calls __eq__, which a class may override to behave strangely. PEP 8 therefore requires is None and is not None.
What is technical debt?
Technical debt is Ward Cunningham's term for the extra future work caused by taking shortcuts now, such as copied code or skipped tests. Like a loan, it speeds delivery today but charges "interest" as every later change gets slower. Regular refactoring pays it down.
Next step
Continue with Software Testing MCQs, go back to the Software Engineering hub, or try a timed NSCT mock test.