Skip to content

Instantly share code, notes, and snippets.

@mcsee
Created May 24, 2025 14:23
Show Gist options
  • Save mcsee/a4f08aa097dbf1822beb80534b078af4 to your computer and use it in GitHub Desktop.
Save mcsee/a4f08aa097dbf1822beb80534b078af4 to your computer and use it in GitHub Desktop.
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
class InvoiceProcessor:
def process_invoice(self, invoice_data, database):
# Business logic mixed with database access
customer = database.execute(
"SELECT * FROM customers WHERE id = ?",
invoice_data['customer_id']
).fetchone()
if customer['credit_limit'] < invoice_data['amount']:
raise Exception("Credit limit exceeded")
# More business logic
tax = invoice_data['amount'] * 0.21
total = invoice_data['amount'] + tax
# Direct database manipulation
database.execute(
"INSERT INTO invoices (customer_id, amount, tax, total) "
"VALUES (?, ?, ?, ?)",
(invoice_data['customer_id'], invoice_data['amount'],
tax, total)
)
database.commit()
return total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment