Posts

Showing posts from April, 2021

Clean Code in a Python Algorithm

 The practice of writing clean code is one that exists no matter the language, framework or tool you use. When you write code that will be read or altered by any other developer, you will want that code to be easily readable and understandable, and easy to edit. Recently I've been working on some algorithms for an assignment at school, but I wanted to show off some of the things I might try to do to write clean code. The algorithm is in Python, which I have found can be easy to write cluttered code, but not difficult to write clean code either. I'll cover a couple of the things I chose to do to keep my code clean. The first thing I do here that is worth mentioning is the Python Typing library. It allows you to describe the types for a variable. It doesn't make your code immutable but it makes your code more readable. By specifying the type of data the function expects, a reader doesn't need to go searching through the code to understand what to give the function. Typing

Catching Unhandled Errors in .NET/C++

Most developers are familiar with the pain that comes from an application crashing in production, and not offering any helpful information why it crashed. I recently was tasked with trying to catch some mystery errors, and I learned a lot about how .NET has some built in tools to catch errors in C++. The SetUnhandledExceptionFilter function supersedes the top-level exception handler in a thread, so if you hit an error the function will catch and allow you to do something before everything goes up in flames. This is a great time to do things like creating logs that will give some insight about what went wrong. It'll allow you to get a better idea of why a program crashes in production. Keep in mind, this only works outside of the debugger, so even in Visual Studio you'll need to run without debugging to test this. This code snippet is probably the simplest proof of concept for this tool that I could come up with. Essentially we are going to set the function that will handle our