Live data from Hacker News

PHP is worth learning and using

bulletproofphp.dev

351–360 of 468 posts

Re: PHP is worth learning and using

#351

I have used PHP for years. Like it. Have accomplished some nice things with it. Think it's evolved nicely in recent years. Feel it's a great tool for particular problems. Will continue to use it. Will always be open to alternatives. Will never understand why some people find that so offensive and will tell you that you mustn't use it or imply that you are ignorant or stupid for using it.

Here's a choose your own adventure for people new to the field. Pick something you want to build, then see which languages are the best suited. If you want to build several things, see which languages are the most recurring and versatile: - Web frontend: Javascript/TypeScript - Web backend: Javascript/TypeScript, Python - Performant backend (where you manage threads and queues): Go, Java, Rust - Machine learning: Pyt…

I really would not discourage C, at all. Even encourage it, especially for embedded. It really makes you grok the lower levels in a way few other languages do, and it's still widely used.

C++, though, agreed.

Re: PHP is worth learning and using

#352
I really don't understand all the PHP dismissal on HN. As a language it has continued to evolve in meaningful ways, especially with the latest releases. Companies like Facebook are built on PHP (yes, they extended with Hack, but most of the benefits are available in PHP 8 now without the downsides).

Coming from a C background, I found PHP easy to step into as many of of the underlying libraries and common functions are wrapped and available in PHP (with similar names).

Re: PHP is worth learning and using

#353

I have used PHP for years. I like it too. Its tight integration with http is nice. The PHP language can be used as a templating language itself: Hello

Does PHP still look like that in 'real life'? I was reintroduced to PHP last year via a Laravel based project and it looked nothing like that. It was all Objects and Models and Controllers spread out across a half dozen folders and scaffolding code generated via CLI commands. All actual HTML was generated with Blade templates.

Re: PHP is worth learning and using

#354
post #91

Earlier quoted context omitted.

But, what is, if not php? Do you shoot for what has had longevity, or what's rising?

It depends on what you want to do. The problem is that PHP is hyper-optimised for serving up HTTP. That was great in the 2000s when the web was eating the world and the other options were Java, Python, and Perl, but is less useful in the current climate where there's so many more platforms and web development requires javascript. By learning PHP, you are effectively locking yourself into the narrow niche of backend w…

PHP pays my bills. I don't use it for web backends, it runs automations for a number of operations that glue APIs together, as well as exporting some custom document types and sorting out workflows/data.

Simplistically speaking, all I have to do is stick the path hashbang at the top of a php file, follow with the business logic and run it as a shell script. Clears any urgent ad-hoc request within a day.

Re: PHP is worth learning and using

#355

Earlier quoted context omitted.

That's not quite a language feature though: one can write (Fast)CGI or similar programs in any common language.

I've never actually tried writing CGI scripts with a non-PHP language (I've not really seen the point since it's usually more ergonomic to just use a language native-server interface like Python's WSGI). Do any other languages have the same kinds of optimisations that PHP has with FPM where it keeps the process alive but pretends it's a complete fresh execution at the language level? (getting the performance benefits…

>Do any other languages have the same kinds of optimisations that PHP has with FPM where it keeps the process alive but pretends it's a complete fresh execution at the language level?

I know that's how the TCL and Perl FastCGI implementations work. I suspect that's how most of them work, and there's lots of languages supported by FastCGI.

Re: PHP is worth learning and using

#356

Earlier quoted context omitted.

That's not quite a language feature though: one can write (Fast)CGI or similar programs in any common language.

I've never actually tried writing CGI scripts with a non-PHP language (I've not really seen the point since it's usually more ergonomic to just use a language native-server interface like Python's WSGI). Do any other languages have the same kinds of optimisations that PHP has with FPM where it keeps the process alive but pretends it's a complete fresh execution at the language level? (getting the performance benefits…

> Do any other languages have the same kinds of optimisations that PHP has with FPM where it keeps the process alive but pretends it's a complete fresh execution at the language level?

I'm not aware of other languages where it is baked into a language itself, but FastCGI libraries tend to be basically drop-in replacements for CGI ones (at least it's the case with common C, Perl, and Haskell libraries; sometimes CGI and FastCGI libraries are combined, so that they are usable in either setting): you get the optimization, while still can pretend that it's a regular CGI. I guess the primary difference from PHP is just that global/static variables would survive.

Re: PHP is worth learning and using

#357

Earlier quoted context omitted.

The best part of PHP is the development model. You copy some files to a server, and load the page. That's it. It is really hard to beat how easy it is to iterate, even if the language is truly terrible.

That ship has sailed a long time ago (or you're just playing around and most languages will have a REPL nowadays) Modern PHP wears a business suit and wants to buddy the "big boys" (Java/C#) of the world. You'll have deployment pipelines, strong push towards classic OOP, strict type checking etc. I personally think ruby for instance is leaner in its dev process in most real world projects.

Many people learn PHP as a first or at least as an early language. They don't want to know about deployment pipelines, CI/CD, or how to configure JDBC, they want to make a website store a list of names. You can't easily generate HTML from Java without some kind of templating language and framework around it, or a billion string concatenations if you're working without external libraries. ASP.NET has an advantage similar to PHP, but getting ASP.NET up and running has always been a chore in my opinion; there are a lot of moving parts that you need to configure right to get the browser to show you the end result.

I believe that PHP is the easiest way to just Get Things Done when you're starting out with a programming language. To deploy a website, you sign up for a free account somewhere, often with a free subdomain like mywebsite.cheapwebhosting.com, put the files on there and hit refresh. Seeing a result immediately is very motivating for beginners, and PHP doesn't require knowing anything complex like DOM manipulation to generate web pages the way Javascript does. If there were as many free web hosts that allowed the same ease of use for C# or some other language with inline templating, I'm sure it'd take off just as easily.

The language isn't as bad as people claim either, I think it's on par with languages like Python and Javascript. PHP has its quirks, like using a dollar sign for variables, it's really not that much worse than its competitors. Shorthands like $_POST/GET/SESSION are such a relief to work with compared to the "professional" languages with their frameworks upon frameworks and complex, layered objects representing state. It's a great tool for setting up a simple website, maybe even a very basic web shop, where the "big boys" are complete overkill. A website like HN doesn't need more than a few PHP files to function until it hits a certain scale, and even then scaling up PHP websites is relatively easy.

I think the real reason people hate PHP is because it's a language used by a lot of beginners and intermediate programmers who overestimate their ability and deliver subpar projects that someone else now needs to maintain or rewrite. I wouldn't want to inherit some kind of custom blogging engine written by an intern three years ago in any programming language, and because of its ease of development many PHP programs are just designed badly.

Re: PHP is worth learning and using

#358
post #298

Earlier quoted context omitted.

Comparing Rails to PHP is unfair given that one is a framework and one is a programming language. Compare PHP and Ruby or Rails and Laravel to keep things apples to apples and oranges to oranges.

A lot of people 10+ years ago were building websites by interpreting PHP and using the output as HTML. The language (at the time) seemed to encourage this. I agree that PHP is not a framework, but it seemed to have some opinion on how HTML was to be generated, which most languages don’t have. Also rails is 7 years older than Laravel, so my point still stands that PHP was behind the curve.

If your standard is rails then literally everything in every language before rails was "behind the curve". Currently PHP has frameworks that have caught rails, but Ruby's perf is still garbage.

Re: PHP is worth learning and using

#359
post #352

I really don't understand all the PHP dismissal on HN. As a language it has continued to evolve in meaningful ways, especially with the latest releases. Companies like Facebook are built on PHP (yes, they extended with Hack, but most of the benefits are available in PHP 8 now without the downsides). Coming from a C background, I found PHP easy to step into as many of of the underlying libraries and common functions a…

One thing I've noticed is people who code in PHP for work or projects don't bother to come on here and try and defend the language. It's underrepresented, but maybe the groupthink ship against PHP has sailed here a long time ago, they don't bother. Or perhaps, more likely, they are too busy creating.

Re: PHP is worth learning and using

#360

Earlier quoted context omitted.

That ship has sailed a long time ago (or you're just playing around and most languages will have a REPL nowadays) Modern PHP wears a business suit and wants to buddy the "big boys" (Java/C#) of the world. You'll have deployment pipelines, strong push towards classic OOP, strict type checking etc. I personally think ruby for instance is leaner in its dev process in most real world projects.

OP is correct, you still can develop like this with PHP, and no the ship has not sailed for many. You can have deployment pipelines etc, but if you like, you can still develop the ancient way - it still works.

Sure, but would you have that in production for the company you work for?

One can also use old school CGI to serve their site, it’s super lightweight and you just upload the file at the right place, for almost any language. But that has been deprecated for the last 2 decades now.

Post reply on HN