| Anybody else feeling that strict typing and long var names are not worth all the visual overload? Example: https://github.com/wikimedia/parsoid/blob/master/src/Parsoid... This is how I would write the function definition: function html2wikitext($config, $html, $options = [], $data = null)
This how Wikimedia did it: public function html2wikitext(
PageConfig $pageConfig, string $html, array $options = [],
?SelserData $selserData = null
): string
I see this "strictness over readability" on the rise in many places and I think it is a net negative.Not totally sure, but this seems to be the old JS function definition: https://github.com/abbradar/parsoid/blob/master/lib/parse.js... A bit cryptic and it suffers from the typical promise / async / callback / nesting horror so common in the Javascript world: _html2wt = Promise.async(function *(obj, env, html, pb)
|
This is fine in smaller codebases, 'your' code, and code that you can read to a point where you can extrapolate these variables from the implementation, but this simply does not scale beyond a certain code size - or more importantly, a certain amount of contributors.
It can be compensated with documentation (phpDoc), but that is just as verbose if not moreso than adding type information - although you should probably do both.
Type systems come into place where you are not expected anymore to fully comprehend the code. They are useful when you are just a consumer / user of this function and all you want to do is convert some html to wiki text without having to understand the internals of that particular function (and whatever else goes on beyond it). Types are documentation, prevent shooting yourself in the foot, reduce trial-and-error, and avoid the user having to read and comprehend hundreds - thousands of lines of code.