asMSX icon indicating copy to clipboard operation
asMSX copied to clipboard

Make code modular by making functions "pure"

Open oboroc opened this issue 6 years ago • 2 comments

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

oboroc avatar Mar 05 '19 16:03 oboroc

First "pure" functions are coming in PR https://github.com/Fubukimaru/asMSX/pull/39

oboroc avatar Mar 14 '19 04:03 oboroc

We now have gtest for unit testing: https://github.com/Fubukimaru/asMSX/pull/45

oboroc avatar Apr 16 '19 18:04 oboroc

The testing system is now implemented with behave in an case-by-case testing instead of by function.

Fubukimaru avatar Nov 04 '23 15:11 Fubukimaru