19

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?

Comments
  • 3
    Now there's something I haven't seen before!

    50 points to @igorsantos07
  • 3
    @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)
  • 5
    @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.
  • 0
    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...
  • 0
    Ah come on, have you never skipped googling and reimplemented array_column yourself? :D
  • 2
    Soo... Whoever uses that fn gets their colon pulled out [i.E. Extracted]?
  • 1
    I rate this 3.6, not great but not terrible.
  • 1
    This reminds me of students in my course not being able to access arrays properly.
    I have not ever seen such a thing.
    Why
  • 1
    @sawmurai only when the function didn't exist! And then I was eager to upgrade to 5.6 to get rid of it haha
  • 1
    @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
  • 1
    "collon"
  • 1
    Hahahahaa I was laughing so hard that my wife came asking me what was that.
  • 0
    @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.
Add Comment