Jump to content

Practical numbers: Difference between revisions

→‎Composition of pure functions: Moved comment to talk page.
(→‎Composition of pure functions: Moved comment to talk page.)
Line 181:
 
Note that no type hints are added for the compiler in this example. The additional work of adding such hints can pay off with larger projects, particularly those involving several collaborators, but the cost/benefit (work for the coder, run-time startup cost) is known to be rather less clear at a small scale.
 
Clarity about the '''return type semantics''', is however, very useful when reasoning about pure functions, and my personal approach is to add light informal '''comments''' about the type, in a Hindley Milner idiom, which lends itself well to brief and clean notes on the type of '''curried''' functions, which are more easily composable, especially with higher order functions, and which I generally prefer to use.
 
I've been asked (always by the same person :-) why I don't find the idiom of Python '''compiler type-hints''' a good match for my semantic type '''comments''', and the answer is essentially that the compiler type hints are not a clear or helpful notation for this purpose – not just because they generally involve more typing and visual noise, but also, and in particular, because with '''curried''' functions the compiler hint notation becomes swamped by use of the cognitively redundant `Callable` keyword, which degrades clarity, and imposes burden, for the human reader.
 
<lang python>'''Practical numbers'''
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.