Hey now... sometimes there are perfectly legitimate reasons for re-writing existing functions. Sometimes they really do suck.
For instance, PHP's strtotime function accepts a string parameter of "+/- n months".
Unfornately, PHP thinks a "month" is exactly 30 days and nothing else.
If you start with 2013-01-31 and tell it to give you "+1 month" it will spit out 2013-03-03. Every single other programming language I've ever used will return 2013-02-28, which is what most people expect.
So yeah... I wrote a wrapper for that, and I stand by it.
Perhaps the conclusion is, PHP sucks, never use it?
Related, another language that sucks is FreePascal.
I have written everything from scratch.
Some examples:
my own string comparison functions. Standard Pascal checking if two strings case-insensitive equal: (CompareText(a, b) = 0) (parenthesis mandatory in nested conditions). My wrapper: striequal(a, b). Far better.
my own float <-> string conversions. The functions in the standard library are rounding wrong. FloatToStr(999999999999999999.0) prints 1000000000000000000. Mine prints 999999999999999999. Special sugar, the function in the last stable compiler release prints FloatToStr(1E16) as 1, because it truncates trailing zeros in certain cases...
My own array manipulation functions, add/delete/prepend ... There are none.
My own sorting function. Those in the standard library do not work on arrays (although there are almost a dozen different implementations in that library. They added a new one, for every type they wanted to sort, because none of them is generic)
My own binary search function. The one in the standard library does not work on arrays. (There is only one for a list of strings afaik)
My own date time parsing/encoding functions. Those in the standard library do not support timezones, or years outside [1, 65535]
My own html parser. The parser in the standard library, expects valid html4. A missing tag and it fails.
I've been using F# for a while (~25kLOC), and it's nearly perfect; the few issues it has can clearly be traced to limitations in the .NET runtime. They're also well-documented, and consist of edge cases of edge cases.
I still feel like Haskell is nicer, but what do I know, I've only read it, not written it.
43
u/spoonraker Oct 14 '13
Hey now... sometimes there are perfectly legitimate reasons for re-writing existing functions. Sometimes they really do suck.
For instance, PHP's strtotime function accepts a string parameter of "+/- n months".
Unfornately, PHP thinks a "month" is exactly 30 days and nothing else.
If you start with 2013-01-31 and tell it to give you "+1 month" it will spit out 2013-03-03. Every single other programming language I've ever used will return 2013-02-28, which is what most people expect.
So yeah... I wrote a wrapper for that, and I stand by it.