3 ms·
Task: write code that does genetic programming by applying combination of 20 specific 5-line functions in random combinations and comparing results. My solutio
by ajuc 5y ago
Task: write code that does genetic programming by applying combination of 20 specific 5-line functions in random combinations and comparing results.
My solution: array of lambdas
Your solution: array of references to functions named f1 .. f20.
Which is cleaner?
- fendy3002 5y agots/js: I see no problem? * if anyone not get it, ts/js can declare a key-value lambda like: let myFunc = {f1: () => , f2: () => } and so on. It can be called by string key like myFunc["f1"](), and all it's props can be get by Object.keys(myFunc) so it can be randomized easily.
- thom 5y agoAre we allowed an array of references to functions with meaningful names?
- ajuc 5y agoSure but the point was - sometimes there's no meaningful names, and the best description of a function is its definition. That's why you write functions like this: def testXIsYAfterSettingAToBAndCToD(): A = B; C = D; assert(X == Y); So much meaning provided by the name ;)
- cryvate1284 5y agoNot that I am taking a stance here, but you didn't really engage with the GP saying that having functions instead of lambdas allows one to name, test and document them: in fact, they might not be called f1 to f20, in fact they might have docstrings (I guess one could comment lambdas, but see it rarely) and you couldn't test lambdas unless you assign them, i.e. give them a name i.e. turn them into functions in all but name.
- mypalmike 5y agoThe one with the names.