3 ms·
Most languages rely on coding patterns for code safety. This is merely a best practice, usually involves writing multiple lines of code, and is merely a convent
by jackfoxy 7y ago
Most languages rely on coding patterns for code safety. This is merely a best practice, usually involves writing multiple lines of code, and is merely a convention.
Functional languages have many of these patterns already encoded into common functions, like map and fold. As functions their correctness can be considered mathematically proven. Would you rather rely on convention or the compiler?
Consider adding on top of functional safety/correctness type safety with a functional language implementing a strong type system, like F#. Sure, F# is only functional first, not purely functional, and probably all type system have some sort of implementation edge issues. For most practical purposes you can consider the added level of type safety imposed by the compiler also to be mathematically provable.
- threatofrain 7y agoWhat kind of mathematical correctness are you getting by using FP? The same kinds that the Rust compiler offers?
- Filligree 7y agoDifferent, but related. If you call 'map' then you know you're not mutating the values, and you get an output the same size as the input without dropping values, and... It means you operate on a higher level of abstraction, and that inherently makes reading code faster. Not per line of code, but certainly per functional unit. Idiomatic Rust tends to use a lot of functional code, and provides all the tools to make that safe. Its map function could mutate the input -- it would be unidiomatic, but certainly possible -- except that, if you don't pass a mutable reference, then you're safe to assume it won't.