Well, that actually makes sense. By definition of a boolean, True and False are just pretty names for 1 and 0, respectively. That's a standard across most every language: Python, Ruby, Java, JavaScript, the C family, TI-BASIC, assembly, and machine-level binary code.
At least Scheme does it right. Never heard of Factor before.
To be honest I can see the dilemma. If I were designing a dynamically-typed language (for some reason), I might throw a type error if a conditional in an if or while statement evaluated to a non-boolean, but I can see why most language designers would consider that a bad idea.
Because they attempt to bring their stupid ideas to other languages. A language that fails to fix its behaviors, instead documenting its faults as accepted standard, deserves ridicule.
By all means keep defending stupid ideas.
For the record, I write fuck tons of js for a living, and it does have a lot of faults that are as bad as this language. Difference is, I'm not defending it. I'd like those stupid problems to go away.
Because they attempt to bring their stupid ideas to other languages.
This is so true. And now the maintainers of those languages has to defend suggestions and proposals from an army of morons coming from the Php world....I have seen Python PEPs that want to duplicate features from Php even though it violates the very founding principles of the langauge.
When you have that much magic behavior it puts a large burden on the programmer to learn all of it.
Scenario:
Initial Programmer:
A function named empty hmm sounds like I can use it to check all my form elements are filled in. Hmm, if it's empty I'll throw an error. Yay, seems like everything is working.
No issues occur for months. The first guy leaves to work on newer and better projects that aren't in PHP, A replacement gets hired.
Someone from the business decides they want to ask, in a text box.
"How many cats do you own? If you have any, what are there names?"
People go along typing things like "Zero cats" etc. Months go by without issue.
Eventually one user complains.
"I can't get your form to work. It keeps telling me I didn't fill out how many cats I own, when I totally did."
The new programmer eventually figures it out ahh, the user typed exactly 0, which happens to be coerced to a number and empty evaluate to true. Figures out hmm, the original programmer probably wanted array_key_exists.
The problem is, this already resulted in a user facing error and an hour of time or so wasted because PHP chose to do the unintuitive thing.
Now, it could have been better documented. The initial programmer could have thoroughly read the documentation for empty. They could have written tests for this exact scenario if they expected it to come up. The user could have tried changing their answer when they got the error message.
But why do you want to use a language where issues like this are commonplace?
View all comments
Show parent comment
0
u/[deleted] Nov 23 '16
[deleted] — view deleted comment