Live data from Hacker News

Moving from Go to PHP Again

dannyvankooten.com

51–60 of 371 posts

Re: Moving from Go to PHP Again

#51
post #13

Each PHP file is an endpoint. As opposed to having routers in code or client side SPA routing. PHP files can be deployed independently, swapped out or updated live. No building/compiling of the php files needed. A single layer as opposed to 'modern architecture' where there's client side back/front end layers, api layer, logic, validator, data access, and ORM layers. Can extend itself as it runs. For example Wordpres…

> Each PHP file is an endpoint. As opposed to having routers in code or client side SPA routing.

> Intuitive, simple, powerful. Can be as easy as editing a php file in notepad and dropping it on a ftp server. Deployed.

This isn't really php specific, with cgi you can do that in any language, even compiled ones like c.

> Amazon lambda may have more in common with PHP in terms of discreet deployable units of functionality. What's old is new again.

Agreed. I must admit I'm guilty of this myself, there is a tendency to start with a framework when there are much simpler and quicker ways to get started, something the world seems to have largely forgotten.

Re: Moving from Go to PHP Again

#52

Why do so many companies keep moving to go? I tried to like it, but it was just so painful to write.

I'm curious, what is painful about it?

I came to Go from mainly C++, Java, and Python background, and I feel like it's the best of all 3 (to me). It's compiled and really fast (like C++), it has a great set of libraries and community interaction/support (like Java), and it has simple syntax that is clear and quick to understand (like Python).

It's not a perfect language (nothing can ever be), but it's become my favorite to use for back-end web services and even taken over some of my scripting workflow.

I can see it being painful if you're trying to render websites server-side though. That's a bit outside of what it's made for

Re: Moving from Go to PHP Again

#53
post #2

For the kinds of applications people tend to build in PHP, PHP is probably a better choice than Go. I'd still do Django or Rails before PHP, but Go just isn't designed to make serverside-rendered database-backed websites especially pleasant to write.

Rest API? Sure. Building webpages? I dont think it was made for that... Although Go templates can work, its still not as flexible as you might want it to be.

Then again these days maybe that is enough for some people. I know a lot of people are eschewing server side page generation entirely for some static js and assets sitting in an S3 bucket that talks to an API server. The only barrier now is SEO, and people are coming up with all sorts of creative solutions to deal with that, as the search engine bots themselves get better and better at indexing js content. That said, I sort of hate frontend js frameworks. You can do everything I just said without them, and really, we should have been doing it for years, like even pre-2010, but we were just too caught up in this markup = server side mentality to really operate that way. Part of it, I think, was that CDNs are a sort of recent thing, and before them you were always running a server anyway, so why not generate the page server side if you're going to go to that much trouble. Also client-side capabilities have dramatically increased, and then you have HTML 5 to consider.

Re: Moving from Go to PHP Again

#54
post #49

Earlier quoted context omitted.

Yup :) You very much just `git clone` a Laravel project, point Apache/NGINX (with PHP-FPM configured) to the `public` folder and all you need to do is run database migrations (for the majority of basic deployments).

I inherited a Symfony2 app and it was a bitch to deploy. It definitely had an asset pipeline. php app/console cache:clear --env=prod --no-debug php app/console assetic:dump php app/console cache:warmup --env=prod --no-debug chown -R apache:apache . # fix owner chmod -R u=rwx,g=rwx,o=rx app/cache # fix cache perms apachectl restart # bounce Apache, otherwise it can throw segfaults

That chown looks super suspect. Usually you wouldn't want the webserver to have write access to the web application it is executing; that's how you get backdoored.

Re: Moving from Go to PHP Again

#55

Why do so many companies keep moving to go? I tried to like it, but it was just so painful to write.

I'm curious, what is painful about it? I came to Go from mainly C++, Java, and Python background, and I feel like it's the best of all 3 (to me). It's compiled and really fast (like C++), it has a great set of libraries and community interaction/support (like Java), and it has simple syntax that is clear and quick to understand (like Python). It's not a perfect language (nothing can ever be), but it's become my favor…

In all honesty, indenting with more than 2 spaces (or, gasp, with tabs) is enough to kill a language for me these days. There are so many competing "new age systems languages" as I call them (crystal/rust/go/nim/d/julia/etc) that you really can pick the one that suits you the most. Crystal is more my speed. Yes go is way more mature, and has all the features I want, but it just isn't set up how I want things to be set up, whereas Crystal is. Is Crystal perfect? No, but it's the closest thing to what I want, and has all the appearances, trappings, etc., that I would expect of a language sent by the gods. The way go code looks just doesn't do that for me, but I'm sure it does for the people who created it.

Re: Moving from Go to PHP Again

#56
post #46

Any idea why PHP has such a bad reputation compared to other interpreted and dynamically-typed languages such as Python?

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.

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

#57

Why do so many companies keep moving to go? I tried to like it, but it was just so painful to write.

I'm curious, what is painful about it? I came to Go from mainly C++, Java, and Python background, and I feel like it's the best of all 3 (to me). It's compiled and really fast (like C++), it has a great set of libraries and community interaction/support (like Java), and it has simple syntax that is clear and quick to understand (like Python). It's not a perfect language (nothing can ever be), but it's become my favor…

On the topic of web frameworks, though, I firmly believe it is possible to write a delightful web framework with mass appeal (like Rails) in any language, you just need the right influences and conventions, but this seldom happens because the people who could write it are already busy enjoying their framework in the language that they enjoy most.

Re: Moving from Go to PHP Again

#58

Why do so many companies keep moving to go? I tried to like it, but it was just so painful to write.

I'm curious, what is painful about it? I came to Go from mainly C++, Java, and Python background, and I feel like it's the best of all 3 (to me). It's compiled and really fast (like C++), it has a great set of libraries and community interaction/support (like Java), and it has simple syntax that is clear and quick to understand (like Python). It's not a perfect language (nothing can ever be), but it's become my favor…

Personally I found it too easy to accidentally forget to check an error, or to shadow a named error return, or to create a nil error that doesn't compare equal to nil. Also to write a method that appears to mutate the receiver but which in fact copies it.

Re: Moving from Go to PHP Again

#59
post #38

Earlier quoted context omitted.

Symfony and Laravel are really nice. It's still a horrible abomination of a language that invites bugs and requires A LOT of care to not produce buggy code, though.

Does it? If you declare strict, use strict comparison operators and typehint your arguments and returns, what more care do you need? These are not particularly onerous, the strict declaration is trivially templateable in any editor as it's the first line, you'd write types in any language and getting used to only use === !== and forget == and != is ... easy?

Type declarations definitely help a lot, but:

* touching basically any standard library function negates a lot of the benefit

* silent coercion still happens everywhere inside a function body

Even if strict comparison, you have to spend a lot of code validating the input and it's really easy to forget an edge case.

Re: Moving from Go to PHP Again

#60
post #13

Each PHP file is an endpoint. As opposed to having routers in code or client side SPA routing. PHP files can be deployed independently, swapped out or updated live. No building/compiling of the php files needed. A single layer as opposed to 'modern architecture' where there's client side back/front end layers, api layer, logic, validator, data access, and ORM layers. Can extend itself as it runs. For example Wordpres…

> Each PHP file is an endpoint. As opposed to having routers in code or client side SPA routing.

Which becomes a security issue due to accidental endpoints or uploads becoming endpoints. Or becomes a mess of imports. Either way, PHP frameworks often end up with a central router anyway.

> PHP files can be deployed independently, swapped out or updated live.

Which means some people try to do that the naive way and end up breaking a few requests that happen during the deployment.

> Can be as easy as editing a php file in notepad and dropping it on a ftp server.

Which causes https://stackoverflow.com/search?q=headers+already+sent+bom&... because people don't realise they had an invisible character before all the code.

I really don't think any of those are a good thing.

Post reply on HN