Re:Python, as Reviewed by a C++ Programmer
by pzh on Sunday April 23, 2017 @01:23PM
(#14179145)
For me the biggest downside of dynamically typed lanaguages like Python and Javascript is that a small error in passing a function's parameters can propagate very far in a complex system. E.g. if you mistakenly interchange two consecutive function parameters, you could spend several hours debugging the effect several modules down. This is an error that a C++ compiler would catch right away.
[ Parent
| on HN ]
Re:Python, as Reviewed by a C++ Programmer
by makecheck on Sunday April 23, 2017 @02:48PM
(#14179698)
C++ is not always able to detect common parameter errors, especially for things like implicit conversions of numbers. Arguably Python’s option of keyword arguments make certain classes of parameter errors go away, too.
Several years ago I remember someone who (perhaps unwisely) wrote a C++ function with many floating-point values as parameters and a single default "bool". At some point the function was extended to have another float. The compiler did not catch calling code that failed to add an extra float; it simply allowed the formerly-flag arguments to be assigned to the new float argument instead. In fact, implicit conversion of parameters is such a common C++ problem that I occasionally define wrapping types for the sole purpose of being parameter types: then the compiler has to trip over them when they are used incorrectly and callers have to do some kind of explicit action to indicate what their values really are.
Those implicit conversion rules (largely inherited from C) are one of the bits of C++ that bit me the most when I was a primary C++ dev.
Re:Python, as Reviewed by a C++ Programmer
by falcolas on Sunday April 23, 2017 @06:40PM
(#14180838)
The cpp compiler would catch it only if the incorrect data was of a different type. Type specification and hinting only helps with the more egregious mistakes.
Re:Python, as Reviewed by a C++ Programmer
by kevin_thibedeau on Sunday April 23, 2017 @02:02PM
(#14179402)
Type hints can catch most of these mistakes.
Re:Python, as Reviewed by a C++ Programmer
by humanfromearth on Sunday April 23, 2017 @02:03PM
(#14179408)
There are solutions for this: flowtype for js or mypy for python (preferably with python3.5+).