FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » switch with case 0
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: switch with case 0 [message #182598 is a reply to message #182593] Sat, 17 August 2013 15:56 Go to previous messageGo to previous message
Peter H. Coffin is currently offline  Peter H. Coffin
Messages: 245
Registered: September 2010
Karma:
Senior Member
On Sat, 17 Aug 2013 13:16:32 +0200, Thomas Mlynarczyk wrote:
> J.O. Aho schrieb:
>
>> PHP will make a type casting and try to make the "foo" to a integer
>
> And that's precisely what PHP shouldn't do. Cast an integer to a string?
> Yes, no problem, since this can be done without loss of information. But
> the other way round, especially if the string is obviously not
> representing a numeric value? That's just plain stupid.
>
> PHP should never, never, never try to parse out anything from a string
> *unless* explicitly told to do so. And throw an error or return `null`
> in situations like `(int) "foo"`.

But the only way to do that that's consistent is to drop "loosely typed"
entirely, and then numeric-to-string goes away as well. And it's NOT "no
problem" either because you need to know how to represent that number.
Is it "0"? "0.0"? "0.00000"? Are big numbers like
"873425783240914325987643256732459087423598876234785624358" or
"8.73425e57"? Are we going with "-4" or "(4)"? And that's before we even
TOUCH on locale issues like whether to use thousands separators, are
they commas, dots, or spaces, and what do decimal places look like? Are
they thousands-sparated as well? Might as well throw out the one-way
implicit conversion as problematic as well, and just go with a
stronger typing.

Strong-typing introduces its own complications: Are we going to cast
implicitly between numeric types? It's easy to say "Sure, that's okay"
but we're IMMEDIATELY up against float rounding and questions of "Do we
want an explicity DECIMAL type?" and how to compare them. Is "004.50000"
comparable to "4.5000002" and are they equal or not? They're both DECIMAL
types, and differ only precision, and could have been even assigned the
same value in the same statement immediately before like

def a : decimal(8,5);
def b : decimal(8,7);

let a = b = 4.5000002; # are we even going to allow this to work, or
# should it also fail because we're trying to
# assign a value of a different scope to a
# variable. But we kind of have to allow math
# with un-predetermined outcomes to be assigned
# to variables, unless we want to explicitly type
# every single term we're going to use...
if (a == b); then
print "equal\n";
else
print "inequal\n";
fi

And then you've got to DOCUMENT all that.

Even just thinking about it makes me 100% behind "We're a loosely-typed
language and it works how it works. If you want to know HOW it's going
to work in a particular case, don't guess, test or look at the source.
Which we make available."

--
17. When I employ people as advisors, I will occasionally listen to
their advice.
--Peter Anspach's list of things to do as an Evil Overlord
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: AND and OR
Next Topic: Compiling PHP 5.x on Cygwin
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 11:56:13 GMT 2024

Total time taken to generate the page: 0.04606 seconds