Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions JOURNAL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# AI-Assisted Software Development: Final Journal
# Treasure Mashabane

## 1-4: Code Comprehension & Decomposition
I focused on breaking down complex algorithms into smaller, testable functions. I learned that "Functional Decomposition" is the first step to avoiding technical debt.

## 5-8: Design Patterns & Advanced Features
Implementing the Factory Pattern helped me understand the 'Open/Closed' principle. I also used Decorators to handle logging, which kept my business logic clean.

## 9-12: Code Quality & AI Collaboration
I used AI to optimize O(n^2) algorithms into O(n) solutions. My main takeaway is that AI is a powerful pair-programmer, but human oversight is required for code safety and style.
2 changes: 2 additions & 0 deletions ai_optimized.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Paste your optimized Python code here
print("Optimization logic goes here")
10 changes: 10 additions & 0 deletions use-cases/code-algorithms/python/algorithm_challenge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def filter_high_value_orders(orders, threshold):
"""
Algorithm: Extract orders above a price threshold
and format the labels for a report.
"""
return [
{"id": o['id'], "label": f"VALUED-${o['price']}"}
for o in orders
if o.get('price', 0) > threshold
]
21 changes: 21 additions & 0 deletions use-cases/code-algorithms/python/code_quality.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def format_user_data(name, age, city):
"""
Demonstrates clean string formatting and
proper PEP 8 naming conventions.
"""
formatted_name = name.strip().title()
return f"User: {formatted_name} ({age}) - Location: {city.upper()}"

cat <<EOF > ai_optimized.py
def find_duplicates_optimized(items):
"""
Before: O(n^2) using nested loops.
After AI Suggestion: O(n) using a set for constant time lookups.
"""
seen = set()
duplicates = set()
for item in items:
if item in seen:
duplicates.add(item)
seen.add(item)
return list(duplicates)
10 changes: 10 additions & 0 deletions use-cases/code-algorithms/python/decomposition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def calculate_total(price, tax_rate, discount):
"""Separating concerns: logic decomposition"""
subtotal = apply_discount(price, discount)
return apply_tax(subtotal, tax_rate)

def apply_discount(price, discount):
return price * (1 - discount)

def apply_tax(amount, tax_rate):
return amount * (1 + tax_rate)
17 changes: 17 additions & 0 deletions use-cases/code-algorithms/python/decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import functools
import time

def timer_decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
print(f"Execution time for {func.__name__}: {end_time - start_time:.4f}s")
return result
return wrapper

@timer_decorator
def complex_data_process():
time.sleep(1)
return "Process Complete"
12 changes: 12 additions & 0 deletions use-cases/code-algorithms/python/error_handling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def safe_access(data, key, default=None):
"""Refactored to handle KeyErrors and TypeErrors safely"""
try:
return data.get(key, default)
except AttributeError:
return "Error: Input is not a dictionary"

def divide_numbers(a, b):
try:
return a / b
except ZeroDivisionError:
return "Error: Cannot divide by zero"
17 changes: 17 additions & 0 deletions use-cases/code-algorithms/python/factory_pattern.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from abc import ABC, abstractmethod

class Notification(ABC):
@abstractmethod
def send(self, message): pass

class EmailNotification(Notification):
def send(self, message): return f"Email sent: {message}"

class SMSNotification(Notification):
def send(self, message): return f"SMS sent: {message}"

class NotificationFactory:
@staticmethod
def create_notification(method):
methods = {"email": EmailNotification(), "sms": SMSNotification()}
return methods.get(method.lower(), ValueError("Invalid method"))
8 changes: 8 additions & 0 deletions use-cases/code-algorithms/python/readability.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def get_admin_emails(users):
"""Before: Nested loops and manual checks.
After: Clean list comprehension for readability."""
return [
user['email']
for user in users
if user.get('role') == 'admin' and user.get('active')
]
5 changes: 5 additions & 0 deletions use-cases/code-algorithms/python/resource_management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def write_report(filename, content):
"""Uses a Context Manager to ensure files are closed properly."""
with open(filename, 'w') as file:
file.write(f"REPORT START\n{content}\nREPORT END")
return "File written successfully"
7 changes: 7 additions & 0 deletions use-cases/code-algorithms/python/task_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def process_tasks(tasks):
"""Refactored Task Manager using Idiomatic Python"""
return [t['name'].upper() for t in tasks if t.get('status') == 'pending']

def find_task_by_id(tasks, task_id):
"""Algorithm Deconstruction: Search optimization"""
return next((t for t in tasks if t['id'] == task_id), None)
13 changes: 13 additions & 0 deletions use-cases/code-algorithms/python/tests_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import unittest

def add(a, b):
return a + b

class TestSimpleMath(unittest.TestCase):
def test_add_positive(self):
self.assertEqual(add(1, 2), 3)
def test_add_negative(self):
self.assertEqual(add(-1, -1), -2)

if __name__ == "__main__":
unittest.main()