in reply to Re^3: Commify numbers, the boring and straightforward way
in thread Commify numbers, the boring and straightforward way

I would argue that the initial version, had it been sufficient, would be much easier understood by a novice than the regex solutions. Case in point: I got this function (the initial version) right three and a half times1 from scratch in a single motion without having memorized the sequence, merely by remembering the mechanics. Given the triviality of the function, that is not a feat by any means, but doing the same with any of the regex-based versions certainly would have been. I consider that anecdotal proof for this approach indeed being simpler than the regex based ones.

Dealing with the extra cases complicated it beyond a significant win though. The extended approach probably does not require much less explanation than regex based ones either. I still consider it easier to grasp, but at this point the difference isn't particularly large.

And while you're right about code that has been sunk into a project in progress, that is not the context for which I advertised this snippet. I am not telling anyone to go back and change all their commify functions to this rendition. But best practices evolved and the Perl documentation too is constantly being revised — as they should be. This was precisely an attempt2 at adding another tiny step forward to the current best practices.

Architects and engineers play on different levels under different constraints.

1 Lack of sleep notwithstanding.

2 Oh well.

Makeshifts last the longest.

  • Comment on Re^4: Commify numbers, the boring and straightforward way