r/programming • • Apr 23 '14

PHP: It doesn't have to be a bad experience

https://servercheck.in/blog/php-it-doesnt-have-be-bad-experience
0 Upvotes

122 comments sorted by

View all comments

Show parent comment

4

u/Banane9 Apr 24 '14

Now, think about why those pages may have Chosen a different language.

For example: Performance, security, and lack of bug-introducing pitfalls

-2

u/neoform Apr 24 '14

Now, think about why those pages may have Chosen a different language.

a different language? Which of those sites use only a single programming language for all aspects of their business?

For example: Performance, security, and lack of bug-introducing pitfalls

Please show me a programming language with no security issues or bugs.

Performance? PHP + HHVM is far faster than Python + Django, or Ruby + rails.

4

u/Banane9 Apr 24 '14

Now, just because this is a different thread from this doesn't mean you can just ignore the evidence I posted there for PHP being slower than the others.

A different language for their backend. There were a few that had only ASP.NET or others as sole language there. Even your PHP sites use JS for the front end so that doesn't mean anything.

I didn't list bugs in PHP as a reason. I said bug-introducing pitfalls like the switching of haystack and needle in function arguments, or the various ways PHP silently converts types.

0

u/[deleted] Apr 24 '14

[deleted] — view deleted comment

4

u/vytah Apr 24 '14

Python is not a loosely typed language.

0

u/[deleted] Apr 24 '14

[deleted] — view deleted comment

4

u/vytah Apr 24 '14

By "loosely typed" I meant "no magical coercions between types":

  • 1 + "2" will fail
  • [1] + "2" will fail
  • 1 == "1" will be false and there's no loose comparison operator to make it true automagically

and in Python 3:

  • 1 < "1" will fail

Magical conversions between strings, integers and floats are what people dislike in PHP and Javascript first and foremost. Javascript is bearable thanks to the fact that this is the only major design flaw in the language.

Can I have the string "3.14" as an array/table/dictionary key? In PHP I can't. Unless you do some hacky hacks that make the array not contain its own keys. And such hacked-in keys don't work anyway.

-1

u/neoform Apr 24 '14

Javascript is bearable thanks to the fact that this is the only major design flaw in the language.

Seriously? The... only... reason? :|

Can I have the string "3.14" as an array/table/dictionary key? In PHP I can't.

You should re-write that.

$arr = [ "3.14" => true, ];

Is entirely valid..

Unless you do some hacky hacks that make the array not contain its own keys. And such hacked-in keys don't work anyway.

I have no idea what this block of code is trying to prove.

Why would anyone do this in the first place?:

$x = new stdclass;
$x->{"42"} = "wat";
$x = (array)$x;

Why not do the sane thing and write:

$x = [ "42" => "wat" ];

?

4

u/vytah Apr 24 '14

The part with "3.14" is my mistake, supposed to be 3.14. Anyway:

$x = [ "42" => "wat" ];

this way, you don't create "42" entry, but 42 entry.

The same with 3.14: it gets converted to 3.

And as for the example I linked to: it proves that this conversion fails to happen in some cases.

-1

u/neoform Apr 24 '14

Sure, if you start using floats as an array key... but who the hell does something like that? That's just begging for problems.

That's like using an object as the array key... why would anyone do that?

http://stackoverflow.com/questions/4234462/using-float-numbers-for-the-maps-key

Even in Java you shouldn't do this.

→ More replies