asMSX
asMSX copied to clipboard
Make code modular by making functions "pure"
This is something I am doing right now with tape output functions, and would like to extend to the entire code base of asMSX. A pure function is a function that operates only on it's explicit input, and it's results are also returned explicitly. No I/O or any global state reading/writting is permitted. Using global constants is fine.
Doing this allows for a very modular composition of the code and for a near 100% unit test coverage.
A good explanation of pure functions and programming in functional-like style in C/C++ is in John Carmack's seminal article on Gamasutra: http://www.gamasutra.com/view/news/169296/Indepth_Functional_programming_in_C.php
First "pure" functions are coming in PR https://github.com/Fubukimaru/asMSX/pull/39
We now have gtest for unit testing: https://github.com/Fubukimaru/asMSX/pull/45
The testing system is now implemented with behave in an case-by-case testing instead of by function.