How to avoid bugs by thinking functionally
As functional programming really avoids bugs in a very good way, how can we avoid bugs when using a traditional programming language? My suggestion is: wrap logic into functions, and think of a function as having an input and an output, and try to make sure the function processes the input correctly and gives a correct output. The input and output can be an environment, such as the file system with before and after states, or can be a data object with before and after states, or can be two objects which are disconnected with each other. Hope this explains how to think more functionally. BTW, for parallelism, functional programming languages have an advantage, that is, the compiler knows a function and can do optimization on it; this is what conventional languages can’t easily do (hard to do).