Se Activity
Se Activity
Learning Outcomes:
Objective:
Students will explore the concepts of software maintenance by identifying bugs, making
improvements, and refactoring code in an existing software project.
Instructions:
Part 1: Setup
At least 3 minor bugs or issues (logic errors, performance issues, outdated libraries,
etc.)
(Optional: You can use a simple open-source Python project or create your own
sandbox project.)
Students will:
Identify Bugs
Run the program and list all bugs or unexpected behaviors they encounter.
Suggest fixes and justify their choices.
Add a Feature
Based on the existing project, propose and implement a small new feature.
Args:
length: The length of the rectangle.
width: The width of the rectangle.
Returns:
The area of the rectangle.
"""
return length * width
Args:
length: The length of the rectangle.
width: The width of the rectangle.
Returns:
The perimeter of the rectangle.
"""
return 2 * (length + width)
```
* **Reasoning:** Separating the area and perimeter calculations into distinct functions improves
code organization, readability, and reusability. Each function now has a single responsibility.
Applying Better Naming Conventions:
o Replace l with rectangle_length or length.
o Replace w with rectangle_width or width.
o Rename the parameters of calculate_area and calculate_perimeter to length
and width for consistency.
o Rename length_rect to rectangle2_length or length2 for clarity (or ideally,
choose one consistent naming style).
o Rename width_rect to rectangle2_width or width2.
o Rename le to length and wi to width in area_calc and perimeter_calc to match
the refactored functions.
Writing/Updating Documentation:
o The docstrings for calculate_area and calculate_perimeter are now more
informative, explaining what each function does, its parameters, and what
it returns.
o We could add comments to explain more complex logic if needed (though
this simple example doesn't require much).
3. Add a Feature:
Proposed Feature: Add a function to check if the rectangle is a square.
Implementation:
Python
Args:
length: The length of the rectangle.
width: The width of the rectangle.
Returns:
True if the rectangle is a square, False otherwise.
"""
return length == width
Updated Version of the Codebase (with fixes, refactoring, and the new feature):
Python
Returns:
The area of the rectangle.
"""
return length * width
Args:
length: The length of the rectangle.
width: The width of the rectangle.
Returns:
The perimeter of the rectangle.
"""
return 2 * (length + width)
def display_message(msg):
"""Displays an important message.
Args:
msg: The message to be displayed.
"""
if msg:
print("Important Info:", msg)
Args:
length: The length of the rectangle.
width: The width of the rectangle.
Returns:
True if the rectangle is a square, False otherwise.
"""
return length == width
print("Is the first rectangle a square?", is_square(length, width))
print("Is the second rectangle a square?", is_square(length2, width2))
This provides a comprehensive set of answers and a well-maintained version of the
initial codebase. Students can use this as a reference to compare their findings and
solutions. Remember that there might be other valid approaches to refactoring and
naming, but this provides a clear and reasonable solution.