3 ms·
I've certainly found them handy to encode + self-document specific loops and reduce duplication, e.g.:- https://github.com/lorenzo-stoakes/weak/blob/master/boa
by singular 15y ago
I've certainly found them handy to encode + self-document specific loops and reduce duplication, e.g.:-
https://github.com/lorenzo-stoakes/weak/blob/master/board/helpers_test.go#L15 https://github.com/lorenzo-stoakes/weak/blob/master/board/he...
(helper functions for unit tests within a chess engine.)
Having closures allows you to be very flexible in the way you interact with a block of code, and there are some things you just cannot de-duplicate without them.
However they are just a tool and as the cliché goes - 'after a while everything starts to look like a nail' - so as with all programming it's a matter of using taste and good judgement to use them where they reduce duplication/coupling + increase maintainability and [the endlessly subjective but equally vastly important] readability.