Exceptions vs Error Values: How to Pick a Strategy

Open a file that doesn鈥檛 exist in Python and open() raises a FileNotFoundError that unwinds out of your function. Do the same thing in Go and os.ReadFile hands back an error value sitting next to a nil byte slice. Same failure, two different shapes of code around it. The difference is not cosmetic. It decides whether a caller can ignore the failure by accident, and whether the compiler notices when they do. ...

October 26, 2026 路 8 min 路 1506 words 路 SpaghettiCoder

SOLID Principles Explained With Python Examples

A class that saves a user to the database, sends them a welcome email, and formats a receipt is one change away from breaking two features it has nothing to do with. Touch the email template and you risk the database write. Touch the receipt layout and you risk the email. SOLID is five rules aimed at that kind of entanglement, each from a different angle, and they share one idea: a class should change for one reason, and the rest of the code should depend on what something promises to do rather than how it does it. ...

October 10, 2026 路 9 min 路 1863 words 路 SpaghettiCoder

What Is Dependency Injection (With Examples)

Here is a class you cannot unit test without a live database and a working SMTP server: 1 2 3 4 5 6 7 8 9 10 11 public class OrderService { private readonly SqlOrderRepository _repository = new SqlOrderRepository("Server=prod-db;Database=Orders;..."); private readonly SmtpEmailSender _emailSender = new SmtpEmailSender("smtp.company.com"); public void PlaceOrder(Order order) { _repository.Save(order); _emailSender.Send(order.CustomerEmail, "Order confirmed"); } } OrderService builds its own SqlOrderRepository and SmtpEmailSender with new, connection string and all. Every test that touches PlaceOrder needs a real Orders database and a real mail server, or it fails before your assertion runs. The logic you want to test is two lines: save the order, send the confirmation. It鈥檚 welded to two concrete classes you can鈥檛 swap out. ...

October 1, 2026 路 8 min 路 1495 words 路 SpaghettiCoder

What Is Spaghetti Code and How to Refactor It

You open a function to fix a one-line bug and forty minutes later you鈥檙e still tracing which branch sets which variable. Three unrelated jobs are welded into one block, and none of them has a name. Pull one thread and you can鈥檛 tell which others move. That is spaghetti code, and the name has nothing to do with indentation or naming style. It describes control flow: execution jumps between conditions the way one strand of pasta crosses every other strand in the bowl, and following a single path to its end means holding four levels of if in your head at once. ...

September 25, 2026 路 10 min 路 1958 words 路 SpaghettiCoder