Par for the course, Also refactoring showcase #1

 Of course, as per usual i neglect to update this even slightly...

i have a handful of drafts, but they never get published.

At any rate, new goal for this blog:
Showcasing neat ways in which refactoring has altered sections of code i'm actually working on.

Too often, people will show "demo code" to highlight how certain techniques are useful, i intend to use this blog to show how i'm refactoring actual production code

First off, two small examples:

Example #1:

This code comes from an algorithm to translate an artificial "genome" into a neural network layer, specifically the part where i decide which "flavor" of network layer to use

Before refactoring:



GetActivation checks the available data, as well as validating that an activation function was correctly generated, throwing an exception upon failure instead of returning null.

Example #2:  

Same program, now coming from some genetic mutation-related code, specifically the "mutation" that will randomly select one of the two chromosomes to use within a genome:

Before refactoring:


After refactoring(stage 1):

After refactoring (stage 2):


A big chunk of duplicated code that got separated out, functionality for adding chromosomes got simplified a lot and extension methods are quite nice


Popular posts from this blog

Building SIC-1 in VCB Part 1: RAM

On the intricacies of affordance-based interfaces in C++

Building SIC-1 in VCB Part 3: Fadder and auto-RAM