chapter ten

10 Standards of coding and creating maintainable ML code

 

This chapter covers

  • Understanding ML code smells and applying that knowledge to identify problematic signs of production instability in code bases.
  • Clarifying the importance of naming conventions, structural standards, and basic good code architecture to reduce complexity in ML code bases.
  • Learning an alternative to the time intensive paradigm of tuple unpacking to minimize unexpected bugs in feature development and to reduce code complexity.
  • Learning the risks associated with improper exception handling and how to craft a try/catch properly.
  • Understanding the dangers of mutability, particularly how it can create very difficult to diagnose bugs in ML code.
  • Applying alternative approaches to heavily nested logic and illustrating how declarative logic can create unnecessarily complicated code.

In the last chapter, we covered the broad strokes of code foundation. Focusing on breaking up complex structure by utilizing was important to pave the way for further discussion of the more detailed aspects of software development for ML. Without having the foundation laid of the basic best-practices, the code architecture and design elements that follow simply don’t matter.

10.1 ML code smells

10.2 Naming, structure, and code architecture

10.2.1 Naming conventions and structure

10.2.2 Trying to be too clever

10.2.3 Code architecture

10.3 Tuple unpacking and maintainable alternatives

10.3.1 Tuple unpacking example

10.3.2 A solid alternative to tuple unpacking

10.4 Blind to issues: eating exceptions and other bad practices

10.4.1 Try / catch with the precision of a shotgun

10.4.2 Exception handling with laser precision

10.4.3 Handling errors ‘the right way’

10.5 Use of global mutable objects

10.5.1 How mutability can burn you

10.5.2 Encapsulation to prevent mutable side effects

10.6 Excessively nested logic

10.7 Summary