Hacker News new | ask | show | jobs
by rorrr2 4648 days ago
Why would you do this for numbers?

How is

    $number = new Number(6.9);
    echo $number->ceiling()              // 7
            ->max(array(5, 9, 49.1)) // 49.1
            ->floor()                // 49
            ->sqrt()                 // Value
            ->value();               // Get raw value rather    than string
better than writing it in actual functions?

    sqrt(
        floor(
            max(
                5, 9, 49.1, ceil(6.9)
            )
        )
    )
2 comments

I've never really understood the incessant need to replicate idioms from other languages on top of the already existing idioms in PHP.
Incessant? I suppose it is, the language is in real need of it.
I've been using PHP for over 12years now. I even attempted what you are doing once, but via an extension, but quickly realised I was simply complicating things in some misguided attempt to fix which wasn't broken.
I think its ugly?
It's as efficient as you can possibly get with PHP .. how is that ugly? Ugly because it doesn't remind you of Python, Ruby or whichever language you prefer?
Yeah, mostly. Also because its how it should have been done. PHP Internals should strive to clean up PHP to conform to my work ;)
Nothing wrong with that attitude at all! Especially when backed up with code. Keep up the good fight .. but I would suggest you implement this as an extension.
Yeah, I think that'll be the way to go. There's apparently a new way of writing extensions, might've gotten slightly more bearable since you last looked at it :)
I think converting numbers to objects and back is ugly.

And insanely inefficient. For this particular example it must be orders of magnitude slower.

Well yeah, efficiency wasn't the aim.
OK, if I never need to write insanely slow object oriented code for no good reason, I will download your "library".
Don't be a dick, dude.