💾 Archived View for paritybit.ca › arboretum › programming › general-programming-tips-advice.gmi captured on 2023-01-29 at 02:57:59. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

General Programming Tips and Advice

← Back

Refactoring

A nice technique when refactoring large amounts of code is to use the compiler to catch missed replacements. This is something that's afforded to you by strongly/statically typed languages but not languages like Python or JavaScript where, if you miss a replacement, you have no idea if you broke something until you hit that piece of code. This can be called the "compile by fire" technique.

A helpful technique for catching errors is also to wrap a block of code in an outer block, define the variable with a type you know is not the type of the variable to be replaced, and then let the compiler yell at you to fix things because the types don't match. For example, if you're replacing an integer variable called "c" with one called "constant", surround relevant blocks of code in {} (or whatever your language has for denoting blocks) and define "float c;" at the top or something like that.

From:

https://www.youtube.com/watch?v=2J-HIh3kXCQ