News for hackers. Stuff that matters.
Re:Moving from Go to PHP Again by ggregoire on Friday February 08, 2019 @01:05AM (#19111940)
Any idea why PHP has such a bad reputation compared to other interpreted and dynamically-typed languages such as Python?
Re:Moving from Go to PHP Again by sfteus on Friday February 08, 2019 @01:23AM (#19111997)
To keep it simple, it was originally created as sort of a helper instead of a full-fledged language, and just kind of grew into that. As such, its early years were plagued with architecture, security and performance issues, as well as many "gotchas" that could wreak havoc on amateur programmers that tended to gravitate to the language. Couple that with the fact that the maintainers drug their feet in implementing modern paradigms found in other languages and fixing the latter issues in the name of backwards compatibility, and that at the time most PHP knowledge bases were years out of date, and it was a recipe for a poor ecosystem all around.

PHP 7.0 took a huge step forward by straight up removing old extensions that weren't maintained, focused a lot on performance and allowing more strict standards, and tons of new improvements. In addition, more modern frameworks like Symfony and Laravel started to pop up, which helped reduce the stigma of it just being a "scripting" language and made it very pleasant to work with.

I maintain a PHP app that was originally written in PHP 4, and one that was created in PHP 7 and the difference is night and day. I maintain a few Ruby and Python apps as well, but even having used these more often PHP still tends to be my go to for prototyping.

Re:Moving from Go to PHP Again by elcomet on Friday February 08, 2019 @05:19AM (#19112931)
This sounds a lot like JavaScript
Re:Moving from Go to PHP Again by 1_player on Friday February 08, 2019 @07:22AM (#19113510)
Gotchas in Javascript are syntactic/semantic, because there's no standard library worth its name bundled with it.

PHP's gotchas are syntactic/semantic but mostly on its huge standard library, which is an haphazard collection of functions from sending emails to parsing ID3 tags from MP3 files.

EDIT: JS, as the legend says, was written in 10 days, while PHP grew without much long term vision for years.

Re:Moving from Go to PHP Again by Technetium_Hat on Friday February 08, 2019 @09:46AM (#19114595)
I think the parent poster was talking about both being messy in the past, but recently having a major version upgrade that deprecated old features. PHP 7 could be compared to ES6 (as well as ES5's strict mode)
Re:Moving from Go to PHP Again by jbarham on Friday February 08, 2019 @01:26AM (#19112007)
PHP: a fractal of bad design: https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/

This rant is almost seven years old now, but I imagine that some things still hold true.

Python in particular is indisputably more versatile than PHP.

Re:Moving from Go to PHP Again by redwall_hp on Friday February 08, 2019 @02:10AM (#19112148)
Oof. I haven't read that classic in awhile. Yeah, most of the things in there can't really be fixed without pulling a Python 3 and intentionally breaking backwards compatibility. And the scary thing is people just brush some of these horrifying things off as non-issues.

PHP was one of my first languages, and it took a long time to break some bad habits it taught. I still can't get over the existence of PHP's "arrays." (Mentioned in the article.) The only data structure is one-size-fits-all. It's truly baffling when you approach it with basic CS knowledge, and the rabbit hole only gets worse...

Re:Moving from Go to PHP Again by furicane on Friday February 08, 2019 @04:18AM (#19112645)
In the context of what you're doing with PHP, that one-fits-all data structure is all you need. I sincerely doubt you had hurdles in your career because of PHP's array :)

However, let's prove once more that languages evolve: http://php.net/manual/en/book.ds.php

The "classic" you're referring to is far from something objective. There will always be problems with languages. That's why we have the human factor who is supposed to be intelligent and work around the apparent issues and make the computer do useful work despite apparent tool glitches.

Sadly, we're just creating better idiots who are only getting better at whining.

Re:Moving from Go to PHP Again by Aeolun on Friday February 08, 2019 @06:38AM (#19113315)
I personally really enjoy the one size fits all array. It’s a serious switch going to any other language though.
Re:Moving from Go to PHP Again by acomjean on Friday February 08, 2019 @01:25AM (#19112004)
Its a quirky little language and the early versions weren't great. The language can be inconsistent in places, and embedding php in the html made for a rapid though sometimes trying experience. Its keeps backward compatibility which keeps those quirks in there. (though with new 7 series php versions older stuff is starting to break.)

Someone wrote an article with a title like "php a language with terrible design" that got traction.

I like the language and with the right framework and templating engine its a pleasure. (I'm moving code from silex to symfony).

I've been to a fair number php meetups and frankly people there seem to be end result focused not so concerned with the language. Frankly I think PHP doesn't have as strong a fan club as ruby/python, which are decent languages but they too come with their own quirks.

Re:Moving from Go to PHP Again by type0 on Friday February 08, 2019 @02:17PM (#19117686)
> Frankly I think PHP doesn't have as strong a fan club as ruby/python, which are decent languages but they too come with their own quirks.

The reason quite possibly is that those are joy to use where PHP isn't. In my mind the developer happiness should be on top of the list, also the syntax is still ugly however you look at it. The versatility of Python is unmatched. Ruby allows me to do things I could only dream of in other languages, in PHP those dreams are nightmares.

Re:Moving from Go to PHP Again by gnarcoregrizz on Friday February 08, 2019 @02:53AM (#19112299)
"and embedding php in the html made for a rapid though sometimes trying experience."

Funny, that is React/JSX's biggest sell

Re:Moving from Go to PHP Again by likeclockwork on Friday February 08, 2019 @03:40AM (#19112466)
JSX adding HTML literals to JS is fundamentally different than embedding PHP in HTML.
Re:Moving from Go to PHP Again by ggregoire on Friday February 08, 2019 @03:24AM (#19112415)
Not really comparable tho. In React, the JS in the HTML is to make loops and conditional rendering, i.e. presentational logic, like in any other templating system. In PHP, you can embed business logic and database accesses in the HTML.
Re:Moving from Go to PHP Again by Aeolun on Friday February 08, 2019 @06:35AM (#19113288)
You can do the same in your React render method I suppose, though it’s a bit harder since you are not attached to the server.
Re:Moving from Go to PHP Again by nprateem on Friday February 08, 2019 @03:19AM (#19112390)
React can't execute arbitrary database queries.
Re:Moving from Go to PHP Again by Aeolun on Friday February 08, 2019 @06:36AM (#19113295)
I’m sure you can use the all JS mysql client to connect directly from your client app to your database.
Re:Moving from Go to PHP Again by nprateem on Friday February 08, 2019 @10:50AM (#19115286)
Well yes if you're stupid enough to directly expose your DB to the world then it's technically possible, but barring such idiocy there's arguably more risk of a DB hack through PHP than client side JS in most architectures.
Re:Moving from Go to PHP Again by mixedCase on Friday February 08, 2019 @12:14PM (#19116366)
React can do SSR. You can use JSX on the backend for rendering pages just like on PHP.
Re:Moving from Go to PHP Again by gdfasfklshg4 on Friday February 08, 2019 @06:17AM (#19113198)
Can too!

{e = () => ajaxCallToMutateDatabase()}

Or something similar...

It's just people don't do it because it is a bad idea!

Re:Moving from Go to PHP Again by mathieuh on Friday February 08, 2019 @01:28AM (#19112012)
For years it was a very permissive language that allowed you to do a lot very quickly but then with a lot of overhead to make sure things were correct.

E.g., I've seen a payment management suite that was written using php traits, which then had a super class that everything descended from, meaning every service could do everything, completely breaking OOP. For example, a DirectDebitService has methods like processMandate(), processDd(), but then because of the traits it also has access to processCreditCardPayment(). As you can imagine this made unit testing literally anything require lines of set up code and just made things impossible to work with.

With the introduction of classes, and PHP 7's scalar type declarations as actual keywords rather than just PHP docs, as well as the option for strict comparison, plus the ridiculous speed improvement between 5.6 and 7.0.

Further, tools like composer (which I think was actually one of the first modern package managers (with lock files, version selectors), Behat for integration tests, plus the huge steps frameworks have made in removing in overhead have made PHP actually a very nice language to write these days.

Deployment in a micro service context is still annoying as PHP's built in web server is not great, requiring you to have an Ngninx pointing at a PHP-FPM which actually serves each of your microservices.

You may think you can get away with one Ngninx, but then as soon as micro services start requiring things like scaling it's a pain in the arse. E.g. you may wish to do rate limiting or rbac or something for a specific service, requiring an nginx->PHP-FPM in front of each PHP service.

I'm sure there are cleverer ways to get around this but this is the way I always go and the way I've seen other PHP deva go

Re:Moving from Go to PHP Again by kristopolous on Friday February 08, 2019 @05:28AM (#19112964)
None of these other answers get to the real point.

The entry level language gets the reputation of the code written on the platform.

That's why basic, flash, php, Java, and JavaScript all had bad reputations at one time.

You can knock on any sufficiently complex language, it's actually really easy.

Python, for instance, gives different numerical results between 2 and 3 for the code "False - 3 * True / True / 2 + 3 * False" (-1 and -1.5)

Making things look absurd isn't hard.

Re:Moving from Go to PHP Again by aczerepinski on Friday February 08, 2019 @07:54AM (#19113676)
This may sound trivial but I dislike the aesthetics and ergonomics of typing PHP. In most dynamic languages user.name is 9 keystrokes, but in PHP $user->name is 13 keystrokes.
Re:Moving from Go to PHP Again by ileri62 on Friday February 08, 2019 @08:30AM (#19113911)
100% agree. The syntax of languages such as php, c++ and rust just look ugly af. The use of $ and :: piss me off the most
Re:Moving from Go to PHP Again by h8hawk on Friday February 08, 2019 @01:26AM (#19112005)