top | item 36976993

(no title)

matteodt | 2 years ago

Interesting bit about sane logic. Is it something you verify manually by reading the pull request code? Or do you rather expect automated tests that use something like spies to check when a control structure is called?

In my coding life, I had a period where I was super into test driven development with mocks and I believe I was doing something very similar to what you called sane logic check. However, I later dropped this approach in favor of heavily parametrized tests where checks happen only on the output of functions and on side effects when necessary (e.g. an email is sent or a row is updated in the database).

Note: I am using this Martin Fowler's definition for "spies": https://martinfowler.com/bliki/TestDouble.html

discuss

order

uticus|2 years ago

The "sane logic" part can be helped and automated by a code analyzer, but I also like to manually read the code (I'm manually reading anyway, as much as possible, to enable learning opportunities and conversation as needed).

Unit testing will not help this aspect much. Indeed the spies you mention are the only way I know of to check this in a meaningful way - in a unit test. Fuzzing gets closer, as it has a better possibility of exposing corner cases that accompany the "insane" logic.

Maybe I'm old school but imo it's an art, partly driven by language capabilities and intentions. There are times when the logic, taken by itself, is totally fine but in the larger context is misleading. Of course this idea of sane logic bleeds over into the other areas mentioned in the article. So it's not a complaint against the article, more of something that is important to my personal experience. I mean if one writes a compendium one has to classify somehow, and this article do a good job of that.

uticus|2 years ago

Forgot to mention, the idea of "sane logic" is often times more important for the human who maintains the code, than the consumer who gets whatever it is the code has produced. Maybe that clarifies my thoughts.

matteodt|2 years ago

Thanks for the clarification! By the way, I am going to add a reference to fuzz testing after your mention.

ano88888|2 years ago

would love to see something equivalent for functional or lispy software design guide instead of object oriented approch.