4 ms·
I have read an extreme counter-opinion in some J or APL article. It said that it is a bad pactice to name small and common functions: The example was maybe the
by szemet 8y ago
I have read an extreme counter-opinion in some J or APL article. It said that it is a bad pactice to name small and common functions:
The example was maybe the average function - and the reasoning was, if I recall correctly:
1. The defintion is shorter then the name average ;)
2. Every praticioning programmer will recognise the definition as a common idiom
3. From the definition it is immediately clear how corner cases are handled (e.g. zero length array)
I just leave this here as an example to show, that programming communities/cultures exists with completely different/alien? ideas about what clean code is ;)
- AstralStorm 8y agoAllegedly. And then you suddenly want to write a SIMD version of an average or optimize it... Mass search and replace time? That'd bloat the code a lot. Common repeated well defined and mostly immutable code is best left as functions. This is why for example in C strcmp exists instead of everyone writing a two-liner - and the specialized variant gives big performance gains.
- szemet 8y agoI've got your point. Just for the sake of nitpicking: both your actual examples have been solved by compilers automatically. SIMD/AVX: https://code.jsoftware.com/wiki/Guides/AVX https://code.jsoftware.com/wiki/Guides/AVX JVM generates vectorized string instructions from your simple for cycles - if availabe: http://jcdav.is/2016/09/01/How-the-JVM-compares-your-strings/ http://jcdav.is/2016/09/01/How-the-JVM-compares-your-strings... edit: my second example link is maybe wrong, but anyway, auto-vectorization is a real thing...