Lab Exp: 8 Defining Coding Standards and walk through.
1. Coding Standards
1.1 Definition
Coding Standards are a set of guidelines, rules, and best practices for writing code in
a consistent, readable, and maintainable way.
They ensure that multiple developers can work on the same project without confusion.
In simple words:
Coding Standards are like rules for writing clean and uniform code, so that everyone can
understand and maintain it easily.
1.2 Objectives of Coding Standards
1. Readability – Makes the code easy to understand for any developer.
2. Maintainability – Helps in fixing bugs and adding new features faster.
3. Consistency – All programmers follow the same style.
4. Error Reduction – Reduces chances of logical and syntax errors.
5. Collaboration – Multiple developers can work together smoothly.
1.3 Examples of Coding Standards
Example 1: Python (PEP 8)
Use meaningful variable names
python
CopyEdit
# Bad
x = 25
# Good
student_age = 25
Indentation: Use 4 spaces per indentation level.
Function naming: Use lowercase_with_underscores
def calculate_area(radius):
return 3.14 * radius * radius
Example 2: Java
Class names: Use PascalCase
java
CopyEdit
class StudentDetails { ... }
Variable names: Use camelCase
int studentAge;
Constants: Use UPPERCASE_WITH_UNDERSCORES
final int MAX_STUDENTS = 100;
1.4 Advantages of Coding Standards
1. Makes the code easier to read and review.
2. Reduces bugs and maintenance cost.
3. Helps new developers understand the code quickly.
4. Promotes reusability of code modules.
2. Walkthrough in Software Engineering
2.1 Definition
A walkthrough is a peer review process where the author of a code or document
explains it to a team to find errors, improvements, or missing elements.
It is a manual verification process done before testing or deployment.
In simple words:
A walkthrough is a step-by-step team review of the code or document to catch mistakes early.
2.2 Key Features of a Walkthrough
1. Conducted by author with review team.
2. Informal review, not as strict as inspection.
3. Main purpose is to improve quality and remove errors early.
4. Usually done after coding but before testing.
2.3 Walkthrough Process Steps
1. Preparation
o Author prepares code/document and informs team members.
2. Presentation
o Author explains logic, flow, and design to the reviewers.
3. Discussion
o Team members ask questions, identify mistakes, and suggest improvements.
4. Documentation of Issues
o Errors and suggestions are recorded for correction.
5. Correction and Follow-up
o Author updates the code or document and may schedule another review if
needed.
2.4 Example of a Walkthrough
Scenario:
A Python function is written to calculate the factorial of a number.
Code Presented:
def factorial(n):
result = 1
for i in range(1, n):
result = result * i
return result
Walkthrough Findings:
1. Logic Error: Loop should run till n+1 or range(1, n+1)
2. Variable Naming: result is fine, but i could be factor for readability
3. Improved Code:
def factorial(n):
result = 1
for factor in range(1, n+1):
result *= factor
return result
2.5 Benefits of Walkthrough
Early detection of errors saves time and cost.
Improves code quality before testing.
Enhances team knowledge of the system.
Reduces project risk by avoiding late-stage failures.