Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@C0D4 quite creative, right?
Unfortunately, that can't be credited to the same weird developer - forgot to mention, but that's a piece of an antique OCR code (phpOCR). Look at this awesome project page: http://phpocr.sourceforge.net (yep, SourceForge) -
C0D4669025y@igorsantos07 oh, an unmaintained lib in the depths of sourceforge. This should be interesting.
"
Works best for small images
"
😅 can't wait to give this a go. -
Nothing against trivial one-line functions. I literally have the same as arrI(array $a, int $i) { return $a[$i]; }
I also have id($x) { return $x; }
Both are only used by giving them to other functions that apply them on some sort of collection or compose chains, manglers, validators, or guards from them.
The id function is obviously only used whenever i need a function doing nothing - instead of passing (and then needing to handle) a null.
The typos and comments are absurd though... -
sawmurai2375yAh come on, have you never skipped googling and reimplemented array_column yourself? :D
-
This reminds me of students in my course not being able to access arrays properly.
I have not ever seen such a thing.
Why -
@sawmurai only when the function didn't exist! And then I was eager to upgrade to 5.6 to get rid of it haha
-
@Oktokolo hmmmmmmmm got curious on those uses. Do you have examples? I see the first case is that so you avoid creating a closure to select a specific key on a chain, but the second one didn't ring any bells.
PS: given the age of the project, I severely doubt they had the same reasoning, but I can't check what happens because that function is not even in use anymore LOL -
@igorsantos07
For me it isn't about avoiding creating a closure as i mostly use that operator aliases with fixed leading or trailing arguments.
I can use iterMap(['arrI', [], [2]], $list) to get a list of the values stored at index 2 of each sublist. There is no magic here. My iterMap prepares the given callable definition by calling my funM on it. That actually does return a closure in this case - it needs to bind the trailing index somehow.
It isn't about avoiding closures at all. It just makes the functional coding paradigm less verbose in PHP by implementing curying (but from both sides *g*).
An example where i don't bind any arguments:
listFilter('notE', $l) returns $l without empty elements.
The id function is most often used inside functions wich accept an optional callable (most often a guard), wich is allowed to be omitted. The default value for that optional callable is then 'id', so i do not need any extra handling for the null case.
Related Rants
The legacy codebase, episode 94385948:
How to neatly organize your code in the age pre-docblocks.
Bonus: could this function be renamed to colectomy? Or maybe de-punctuation?
(yep, probably a bad joke with a "typo", sorry)
Bonus 2: seriously? A function for that?
rant
php
legacy code
code formatting