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.
public function html2wikitext(
PageConfig $pageConfig,
string $html,
array $options = [],
?SelserData $selserData = null
): string
I am sure an IDE could do that for you.That being said, I think the Python way of formatting type annotations ("variable : type") is more readable than C-style "type variable = ...", especially when the annotation is optional.
Further, documentation: "of course everybody knows what you're supposed and forbidden to pass into $data" - NOT. Even if it's just you writing the code: the you+1year will have trouble reading it (been there). Not even when it's supposed to be documented. If you have an explicit data structure, this becomes far more evident, even before any documentation (note: not replacing it).
I'm not interested in playing computer in my head any more, juggling internal state that's completely superfluous to me: am I a higher primate? Yes. Are higher primates tool users? Also yes. Should I let machines do the menial tasks for me, leaving me to do the creative ones? A hundred times yes.
(NB: this is not a silver bullet - e.g. won't help against logic errors - but it's a useful guard against going completely off the rails)
function html2wikitext($config, $html, $options = [], $data)
and then infer the types, and subsequently enforce them. The typechecker should only complain when it can't infer the types (a-la strict). If you use tooling to reduce verbosity, you'll have best of both worlds simultaneously.You: I like X!
> I see this "strictness over readability" on the rise in many places and I think it is a net negative.
which makes your tastes a bit more... absolute to say something. So it makes sense to me that people reply to your negative view with counter arguments.
For lone wolf coding or rapid prototyping the equation is different.
https://news.ycombinator.com/item?id=22282080
and
https://news.ycombinator.com/item?id=22282306
For what comes out of the box with Perl regarding undefined variables. Perl has "my" "local" and "ours" for the start but even more: the array and hash variables have by design different syntax, which helps immensely: the sigils are of real help as a kind of written "type." It's like in old Basics string variables looked different from the numeric ones, and Larry Wall acknowledged he was inspired by that. I can go on and on. Perl looks hard to the uninitiated but it can produce much more stable code, in my experience, than the "typical" scripting languages like Python and Javascript. Stable in the sense that you know it will work after it compiles, not only once you test with every possible input.
But yes, the people using it should know learn enough before they start contributing, and in a lot of places it's preferred to have people who barely know the basics of what they use (because they are "cheap" and "easily replaceable").
Example: https://github.com/wikimedia/parsoid/blob/master/src/Parsoid...
This is how I would write the function definition:
This how Wikimedia did it: 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: