25 ms·
Moving from Go to PHP Again
- tptacek 8y agoFor 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.
- steve19 8y agoI have not written a new PHP app in years but recently I had a look at the latest and greatest from the PHP community and its pretty good. The frameworks and tooling look about as good as you will get anywhere and PHP appears to be fast now.
- tomschlick 8y agoAs someone who was about to ditch the PHP ecosystem 6 years ago for something like Rails... frameworks like Laravel absolutely changed the PHP ecosystem. Also since the release of PHP 7.0, core development seems to have really picked up with good stuff in every release (7.3 was just released a few months ago).
- sethrin 8y agoI've used both Rails and Laravel fairly extensively. The Psy shell and Laravel collections library are quite nice, but not quite as versatile as Rails/pry. However, Ruby has a long way to go to catch up to the PHP interpreter's performance.
- Aeolun 8y agoI just do not understand the fascination with Laravel. When the first version of Laravel was released Symfony was already lightyears ahead. The only thing Laravel had going for it was that you could take more shortcuts, and it was a pain to integrate into any IDE if you wanted decent autocompletion.
- disiplus 8y agoI haven't touched symphony from 1.2 but laravel was a lot simpler to use, especially for begginers. no stupid yaml files, the need to definine everything in yaml before. simpler orm and so on.
- spdionis 8y agoWhen people talk about symfony now they usually mean version 2. Symfony 1 is not comparable to Laravel.
- spdionis 8y agoThe main thing Laravel had going for it was good marketing.
- tomschlick 8y agoI disagree. Laravel is much less verbose than Symfony and tries to optimize for developer happiness. Couple that with a kick ass video tutorials site (laracast.com) and that Laravel was started at the fall of CodeIgniter giving it a great boost in users.
- KerryJones 8y agoLaravel is not what it used to be either -- Laravel 5 is far more capable/usable than Rails or Django. It's ecosystem is vaster, much stronger community, better docs, faster -- pretty much every state it's better than it's competitors. Not an end-all be-all, but worth noting: https://github.com/topics/framework https://github.com/topics/framework
- Aeolun 8y agoLaravel may, may be better than Rails. But Django is better still.
- KerryJones 8y agoHow so?
- the_duke 8y agoSymfony 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.
- tomschlick 8y agoIt is getting better though. I'm hoping that 8.0 can introduce some real BC breaks that will clean up the mess the language has created over the years.
- chx 8y agoDoes 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?
- the_duke 8y agoType 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.
- vesak 8y agoWhat's the equivalent of === for < and > in PHP?
- namidark 8y agoBuffalo has made it a pretty pleasant experience in the past year or so
- edgarvaldes 8y agoBuffalo?
- pjm331 8y agoA go web development framework
- orware 8y agoThe Buffalo Web Framework for Golang: https://github.com/gobuffalo/buffalo https://github.com/gobuffalo/buffalo
- lazyjones 8y agoSeems useful, but it’s yet another of those frameworks that introduce spurious CLI tools for „initializing“ the project by generating dozens of files that one either doesn’t need at all or has to replace anyway. I don’t need a tool to generate CSS boilerplate, I can just copy it from somewhere myself if I decide to use external CSS. One of the reasons PHP was appealing initially was that all this boilerplate and extra files were unnecessary, you just wrote something in the .php file (in Apache’s hierarchy) and could load the web page. As problematic as that was, it let you focus on getting stuff done instead of overwhelming you with ad hoc conventions and dozens of files with no immediate use. Go is a language with sane defaults and little boilerplate. It would benefit from a web framework with similar principles.
- diamondo25 8y agoRest 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.
- sam0x17 8y agoThen 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.
- deleted 8y ago[deleted]
- nkozyra 8y agoIt's pretty flexible in my opinion. And you can substitute go templates for another template library if you like. Granted, we're talking about largely server side generated web pages and, haha, who does THAT still in 2019 : hangs head in shame :
- 52-6F-62 8y agoIt's true. I don't often do so at work anymore, either—except for utility pages. But I am rewriting my personal site/blog in Go as a trial run/learning process. I've been critical of Go in the past so I thought I'd give it a... go. So far I don't mind the experience. No server framework, either. The standard library is actually pretty good, at least for something simple like that. The only [external] dependency I'm pulling in so far is `blackfriday` for parsing Markdown files (the posts) upon request— I'm much too lazy to write a Markdown parser myself for this purpose. It's not finished yet, but it's on its way— https://github.com/robertfairley/rf-19-go https://github.com/robertfairley/rf-19-go
- benatkin 8y agoFlask is a good alternative to Django for building web apps with python on the backend. If I'm using react or vue with a JSON API, I don't need the form support in symfony or django.
- jszymborski 8y agoHowever, deploying a Flask/Django/Rails app still is usually less fun than deploying a PHP app of the same spec written w/ Symfony or Laravel. Configuring a service to monitor gunicorn, which itself took a bit to configure, before I begin configuring NGINX or Apache... it's really a pain in the butt. LAMP/LEMP stacks just... are
- zepolen 8y agoSetting up and monitoring those apps are as simple as apt-get install uwsgi and writing 10 line /etc/uwsgi app.ini config file. Deploying is as simple as touching a reload.wsgi file.
- lapnitnelav 8y agoI'm working on an internal tool for our micro operation (we're 2 folks) built with Flask and it was my main concern. Turns out, leveraging Dokku and having the right files, ie a Procfile to bind your app to Gunicorn and pushing the repo to the dokku instance was all it took. Granted, it's for internal use so downtime isn't that big of an issue.
- dcbadacd 8y agoSo ease-of-install beats code quality, code readability, security, future maintenance and better tooling. Dang. LEPP (nginx, PostgreSQL, Python) stack seems to me an all-around better stack for most of the deployments people use LAMP for.
- jszymborski 8y agoYou have to make your own cost analysis to see what is most efficient for you. Writing secure, readable, quality code in PHP is something I'm far more comfortable doing than deploying Flask or Django apps on a VPS. That's a function of my lived experiences. YMMV, but I think declaring python/ruby on the backend is "the all-around better stack" for everyone is a bit short-sighted imho.
- darkr 8y ago> Go just isn't designed to make serverside-rendered database-backed websites especially pleasant to write. Citation needed. I’ve had a very nice time. It’s statically typed, has excellent templating support, and is generally very productive.
- latch 8y agoWell, they thought Go would be an alternative to C++ (1) which has never really been the most popular website backend language. I'm glad it's working out for you, but I don't think it's a stretch to say it wasn't really designed for it. On its own, that doesn't mean it's a bad fit; but I agree with your parent and think it's awful for this type of stuff. (1) - https://commandcenter.blogspot.com/2012/06/less-is-exponentially-more.html https://commandcenter.blogspot.com/2012/06/less-is-exponenti...
- xdfgd0ig0dg 8y agoHighly outdated to point out Go would be an alternative to C++. It has been most popular in web-dev, with alot of people switching to Go from Python, PHP or Ruby. Go does web really really well.
- apta 8y agoIt turned out to be more of a replacement for Python for places where you need speed. Then again, a JVM or .NET language would probably be better.
- grogenaut 8y agoIn go, Querying SQL is very much like doing the same thing with the base libraries for mysql in C. Doing the same in most any other language is much much easier and just as safe. Credentials: Worked mainly in go for 4 years... 18+ years coding in about 9 languages. Yes I realized this is opinion.
- nkozyra 8y agoHuh? How is database handling different in Go? You write a parametrized query, the driver prepares it and you deal with the response. MySQLd in PHP is a mirror process, and in fact retains the C function names.
- apta 8y ago> but Go just isn't designed to make serverside-rendered database-backed websites especially pleasant to write. Or anything else for that matter, maybe aside from some command line tooling.
- stolsvik 8y ago> For the kinds of applications people tend to build in PHP, PHP is probably a better choice than Go. Facebook goes into this category then, I presume?
- _the_inflator 8y agoCan relate, after 7+ years I am again using WordPress and PHP again. I am impressed by PHP 7.
- ehnto 8y agoHm, I hate to be on the bandwagon, but why WordPress? One of the things that has made PHP become what it is today is a focus on good software engineering and the introduction of language features that are required by that. WordPress did not keep up on the engineering front and there are so many amazing options out there now for well written, well engineered platforms. Even in pre-built blog platforms. You're not alone mind you, most of the new platforms are not very popular just because of how embedded WordPress is in its ecosystem. It just surprises me that both WordPress never moved on and that the PHP developer community never chose something different when it was clear WordPress had no intention of moving to more modern practices.
- vvpan 8y agoI am completely out of the loop here. All I know is that I really disliked Wordpress and really-really disliked Drupal back in the day. Can you mention some of the better alternatives? Once in a while a PHP CMS is what I gotta deal with and I dread it, because of the said systems.
- pasta 8y agoAs a developer use ProcessWire instead of all the others. Imho the best CMS for PHP.
- leetbulb 8y agoOh man, yes! Doctrine and especially Symfony's Form component absolutely spoiled me. Check out Sylius for a really solid Symfony based application: https://sylius.com/ https://sylius.com/
- proyb2 8y ago> Honestly, Go is great. Its simplicity is refreshing and its performance unmatched. I would still pick it if we need a small API or something that requires high throughput. I wonder which part is performance unmatched? My opinion would be Crystal language for its simplicity and higher throughput but unmatched performance is behind Rust and C.
- pjmlp 8y agoNot sure about the OP, but for many Go is the only compiled language they ever used, so they get to attribute features to Go that aren't that unique of it.
- sacado2 8y ago> for many Go is the only compiled language they ever used That, or it can be read as "in the family of web-friendly languages". The only other "fast" language widely used for the web is Java.
- trixie_ 8y agoEach 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 Wordpress, running off of php files can download plugins to its own server (which are just more php files) to instantly extend itself. Without restarting or redeployment. (What other web platforms can do this?) Intuitive, simple, powerful. Can be as easy as editing a php file in notepad and dropping it on a ftp server. Deployed. Amazon lambda may have more in common with PHP in terms of discreet deployable units of functionality. What's old is new again. Compiling/deploying an entire system to change a single endpoint feels backwards after using PHP.
- enz 8y agoPlain PHP files work that way. But what if you use a framework (even an in-house one)? Does this holds true?
- jszymborski 8y agoYup :) 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).
- hnzix 8y agoI 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
- 0x0 8y ago
- argd678 8y agoIs there any way to test php code the same way a compile phase does in other languages to catch obvious mistakes from hitting your users?
- pram 8y agoPHP 7 has type hints and a strict mode. Probably as close as you're going to get. It prevents execution from the interpreter.
- n1c 8y agoPHP Static Analysis Tool (https://github.com/phpstan/phpstan https://github.com/phpstan/phpstan) is pretty good at surfacing that kind of thing.
- bunnybender 8y agoPhan (https://github.com/phan/phan https://github.com/phan/phan) is another one. Other potentially useful tools: - PHP_CodeSniffer (https://github.com/squizlabs/PHP_CodeSniffer https://github.com/squizlabs/PHP_CodeSniffer) - GrumPHP (https://github.com/phpro/grumphp https://github.com/phpro/grumphp) - PHP Mess Detector (https://phpmd.org/ https://phpmd.org/)
- DCoder 8y agoThere's also Vimeo's Psalm [0]. [0]: https://github.com/vimeo/psalm https://github.com/vimeo/psalm
- lukifer 8y agoIt's obviously not as comprehensive as compiled or strictly-typed languages, but you can use "php -l" as a linter to catch obvious parsing/syntax bugs. I use this script to check our whole codebase before deployment: > find . -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v "No syntax errors detected"
- deleted 8y ago[deleted]
- Xeronate 8y agoWhy do so many companies keep moving to go? I tried to like it, but it was just so painful to write.
- joshmn 8y agoWhat do you usually write? That might answer some questions.
- 12298765 8y agoI'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
- sam0x17 8y agoIn 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.
- sam0x17 8y agoOn 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.
- Bucephalus355 8y ago[deleted]
- shittyadmin 8y agoTo be clear, this just means that PHP has libsodium as an official language extension. Most modern languages have better package management than PHP and make pulling it in as a library trivial. This has nothing to do with homomorphic encryption, unless I'm missing something.
- 00deadbeef 8y agocomposer require some/library That's PHP's package management. What's so non-trivial about that?
- spdionis 8y agoAnd, as a bonus feature, composer install won't automatically update your lock file!! Unlike some other package managers...
- pram 8y agoGo has has a native nacl implementation jfyi.
- openloop 8y agoGood luck with that one.
- ilovecaching 8y agoWhy not try out Hack? It's kind of a cross between PHP and Go. Hack has a real type system, and HHVM is incredibly fast.
- kijin 8y agoPerhaps because they don't want to incur technical debt to a language/runtime that could change at the whim of one company that probably doesn't have other companies' best interests in mind? The speed advantage of HHVM has also been largely erased. Some high-profile PHP sites migrated to HHVM before and up to ~2015, but I haven't heard of a single site doing that since PHP 7.0 came out.
- ilovecaching 8y ago> Perhaps because they don't want to incur technical debt to a language/runtime that could change at the whim of one company that probably doesn't have other companies' best interests in mind? How is Go any different?
- kijin 8y agoGo has been well received outside of Google. Wikipedia even has a list of companies known to use Go. I'm not sure how up to date it is, but the list includes Cloudflare and Netflix. At least some of them might have the oomph to fork, take over, or otherwise influence Go if Google ever dropped the ball. Meanwhile, I can't think of any major online service that relies on Hack apart from Facebook and its subsidiaries.
- pushtheenvelope 8y agoSlack does. But I agree with the original point about not fully relying on the whims of a major corporate promoter. Priorities can change within, without clear visibility on the outside.
- acomjean 8y agoThere was a time when hack was new and it was so much faster than php. PHP really got their act together (nothing like a little competetive pressure) and made the 7 series that ran at almost the same speed as hack. People are inertial and won't change unless they have too or something is significantly better.
- iamleppert 8y agoAn entire business that resolves around a nag box? Wow!
- tak2siva 8y agoGolang is not a silver bullet. No programming language is.
- aboutruby 8y agoSeems like he should try Rails (from which Symfony was inspired) and that is much better suited for building web apps that Go
- thekingofh 8y agoWhat are the differences between the both of them?
- aboutruby 8y agoI only tried Symfony 1.4 and 2.0. And I'm doing Rails from 2.3 to 5.2. I could go on a very long discussion about why I prefer Rails but at the end of day it's just up to you to compare. When I started Rails I was building an app with Symfony, took me a week to get it to a good state and it was extra frustrating (I had been doing PHP for 5 years). I started Rails, learned Ruby on Wikipedia and just general googling and got the same app in a few hours.
- ggregoire 8y agoAny idea why PHP has such a bad reputation compared to other interpreted and dynamically-typed languages such as Python?
- sfteus 8y agoTo 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.
- elcomet 8y agoThis sounds a lot like JavaScript
- 1_player 8y agoGotchas 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.
- throw2016 8y agoPHP is the same but with speed improvements in 7. But even without that the sheer number of high traffic sites built on PHP and proven scalability cannot be ignored or its ease of use and setup. All talk of accessibility and ease for new users often comes off as posturing by some tech folks who then proceed to rubbish any efforts at achieving it and the compromises involved. It fits in nicely with the 'contempt culture' recently covered here. The growing problem for the technical community and new users is the marketing by other languages, frameworks and those vested in these ecosystems which means using forums like this to belittle, rubbish and exaggerate any perceived fault in everything else. PHP's contemporaries like Python, Ruby, Javascript have their many downsides too but these efforts create false binary narratives. This is not a good basis for technical decisions or informed discussion.
- nodex-alex 8y agowhich is precisely what's wrong with websites such as HN / Stackoverflow with their opinionated ironic so called programmers who sit on the internet all day with opinions on the "real world" without actually living in or contributing to it and knowing exactly how it works.
- pasta 8y agoI agree with the author. Symfony 4 is the best PHP framework at the moment. Trying both Laravel and Symfony I think there is no need for Laravel (anymore). Laravel just has too much magic that will bite you later on. The only thing you should skip in both frameworks are 'annotations'. But this is easy to do.
- Double_a_92 8y ago> Laravel just has too much magic that will bite you later on. Especially when that is not explained in the docs or just in a very vague way... I tried improving the docs by pointing out where magic (e.g. fix naming conventions) is needed and where not, but the mantainer just turned that into vague mush again (after he had even agreed to the changes). Also if you need any more details that are not in the docs, everyone points you to paid video courses that assume you have a Mac... That honestly leaves me with a bad taste im my mouth after trying laravel :/
- Aeolun 8y agoLaravel feels like some sort of lifestyle. I don’t know. It’s odd.
- tomschlick 8y ago> Also if you need any more details that are not in the docs, everyone points you to paid video courses that assume you have a Mac... I assume you're referring to laracasts.com... what does having a mac have to do with the videos there?
- Double_a_92 8y agoWhen I watched it 2-3 years ago most of the tooling that they set up was OSX specific. Nothing tragic, but still.
- tompi 8y agoAbout annotations, a new proposal has been submitted a few days ago. It's not the first time so I don't want to be too optimistic, but it looks great. https://wiki.php.net/rfc/annotations_v2 https://wiki.php.net/rfc/annotations_v2
- bsaul 8y agoHonest question : is there any technical reason that prevents a go web framework to replicate the functionalities of symfony / doctrine ?
- atsjie 8y agoNo. And there alternatives. The best known is probably Revel: https://revel.github.io https://revel.github.io For a doctrine (ORM) alternative you have for example https://github.com/jinzhu/gorm https://github.com/jinzhu/gorm The point about Go; using those types of tools is generally frowned upon in the community. It's overkill for most (micro)services. But few gophers build a full-stack website in a single application. I'm a gopher; I wouldn't want to use Revel or Gorm. I feel I'd be using the wrong tool for the job. I'd more likely use Django or Symfony when I'd need to build a full-stack SSR. If a backend API is used by different clients (mobile apps, SPA, servers, ...) using a full-stack SSR framework like Symfony or Django doesn't make much sense anymore. You wouldn't use 90% of the framework's features. It feels like bloat. But many websites don't need to serve different clients. The author's decision to go from Golang to PHP makes perfect sense if he's building SSR websites.
- Oras 8y agoGorm is not bad but I don't think it is an alternative. To start with, the association requires some extra work to save/update which you have to do manually. In doctrine, this is done already. Documentation, maturity, and community behind doctrine are a lot better.
- atsjie 8y agoFunny this, +/- 6 years ago when I last worked with Doctrine I had the same feeling about Doctrine itself. I thought it was a poor replacement compared to Hibernate / JPA. I'm getting old ;) Obviously things will have matured since then. Doctrine implements the Unit of Work pattern. From what you're saying GORM is more like an Active Record ORM. You're right, that wouldn't make it a good direct alternative.
- joaodlf 8y agoI love Go, for many situations, but definitely not for a typical user facing website. The community seems bent on the whole "all you need is net/http", but that just isn't practical in modern web development. People like ORMs, easy to handle html forms, security as a default, easy session/cookie handling etc. In the end, web developers want ease of life. Go is a great language for many things, but if it's going to take on the web at large (outside of HTTP APIs), the community needs to grow out of this "net/http or nothing" approach. There is some hope, some frameworks like https://gobuffalo.io/en https://gobuffalo.io/en are showing up, but the Go ecosystem is dying for a Rails/Django solution.
- jimmy1 8y ago> but that just isn't practical in modern web development People always use this modern term as if it implies something significantly different or more "advanced". The web hasn't changed much. It's still data over tcp sockets to a contained runtime -- a web browser. > People like ORMs People in my experience are starting to dislike ORMs. If you have done this for long enough, you realize they are great for getting off the ground, but they inevitably get in your way, and start generating some really bad queries which you have to start one by one replacing with raw SQL statements, at which point you might have well started with raw SQL. Having come from Rails, and PHP frameworks like Symphony and Laravel at my company, using Go I feel almost like I am more intimate with my code. I understand it better, the dependency chain only ever goes one or at most two levels deep. I will admit the the templating and routing is more "batteries included" in these frameworks, but the other parts that I have control of that I consider much more important (such as how my data actually gets stored and other network calls I have to make), I would much rather do those in Go than in PHP
- pier25 8y ago> People in my experience are starting to dislike ORMs That's what I see around me as well.
- davidsawyer 8y agoSpeaking as someone who moved from a company that heavily leaned on an ORM to a company that is using jOOQ (a thin Java wrapper around SQL) for everything, not being able to use an ORM is pretty painful. I greatly miss the nice, clean ORM experience. It's so much better for developer efficiency.
- moreentropy 8y agoHe's comparing a language (w/ extensive standard library) with a web application framework.
- skrebbel 8y agoAnd?
- k__ 8y agoIt's hard not to. Comparing Go ans PHP a few years ago would mean to compare Go and PHP/Apache or PHP/Nginx, because PHP could not run its own server. It's like comparing Git and Subversion, where you have to explain concepts like staging. Or IntelliJ and Eclipse, where you have to explain workspaces.
- sandreas 8y agoWell comparing Go and PHP is kind of difficult, because they are targeting completely different goals. After some years of development, both languages have evolved a lot and they both can be used for many other things, that they haven't been designed for. PHP was a dynamically typed scripting language to build personal homepages (Personal Home Page Tools). Today it is an object oriented, type hinted language that supports functional and object oriented programming, many database management systems and has a package manager (composer). I really like PHP (see https://github.com/sandreas/m4b-tool https://github.com/sandreas/m4b-tool for a proof), but some concerns about PHP have always been (and still are): - backwards compatibility reaching too far - way too big standard library (see levenshtein function) - the "callable" concept - call_user_func_array([$obj, "method"]) - mixing up too many concepts (OOP, Traits, Functional style) - the type system (which is getting better with php 7) - unpredictable statements - empty($x), comparisons (== vs ===) and the "mixed" type - the "array" type being array and dictionary and... - the $ used for variable declaration - $this-> is still needed for calling object methods - "." for concatenation and "\" for namespace separation Another bad thing about PHP is, that on most web servers it is meant to be stateless, which means that you are in trouble using technologies like websockets. Some of these things unfortunately mean that PHP often is much slower than it could be - and this is where "go" can be a successor. Performance. If you really need FAST web apps and performance is the goal, go can be a nice choice. But for getting things done in a not too complex web page, i would always choose php.
- ddtaylor 8y ago> - the "callable" concept - call_user_func_array(["object", "method"]) For at nearly 10 years now PHP has had support for lambdas, meaning for most uses `$foo()` can be used instead and with the inclusion of the spread operator it's seldom used.
- sandreas 8y agoWith the "callable" concept i meant, that many things are seen as callable: [$obj, "methodName"] => callable for $obj->methodName() "str_replace" => callable for function "str_replace" ["ClassName", "staticMethod"] => callable for ClassName::staticMethod() "ClassName::staticMethod" => callable for ClassName::staticMethod() function() {} => callable for a lambda I would prefer a "ClassMethod" and a "Function" type, instead of using strings. $x = phpinfo; $x(); $y = $obj->method; $y(); But i don't think, this is possible, because PHP supports global constants and function names cannot be distinguished from constants, especially because PHP is not case sensitive regarding functions and classnames. But I see, that my karma has decreased with this post, so it seems, that not many are in my opinion...
- deleted 8y ago[deleted]
- perlgeek 8y agoWait what, two complete rewrites of their complete website in 2 or 3 years? If you have that much time to spend on rewrites, I really envy you :-)
- no_gravity 8y agoIt's interesting that he names Symfony 4 as one of the main reasons he uses PHP again after he already used PHP with Laravel. I have a lot of discussions with friends in the startup scene about the topic of Laravel vs Symfony. So far it's a head to head race. I have yet to find a good 'Laravel vs Symfony' comparison page. Yes, there are tons of 'SEO optimized articles' with this title. But I find them all rather uninformative and often even totally wrong and unfair. The page I would love to see would have the same project coded twice. Once with each framework. And then display each file on the left for Laravel and the corresponding file on the right for Symfony.
- pasta 8y agoThose SEO pages are horrible. I had the same problem. But there are multiple reasons I choose Symfony 4 over Laravel. And if you want a code comparison then this small example: Laravel: class User { } Symfony: class User { private $id; private $name; public function getId():?int { return $this->id; } public function setName(string $name): self { $this->name = $name; return $this; } public function getName():?string { return $this->name; } } Laravel looks a lot easier and quicker. And it is. But good luck next month when you can't remember what properties User has. Your IDE can't autocomplete it. And also good luck working with a team. Your team members have to look up the database model for the User to see what properties are available. And this is happening in Laravel all the time. Very quick, very easy, a lot of magic but it will bite you in the end.
- honopu 8y agoI don't use laravel anymore, but I had a live template that would generate getters and setters that wrote to set_attribute. As long as you maintained the convention of doing this, you could use autocomplete with getters and setters to accomplish this. You could also hint these with / @var */ there are ways around it but yes it isn't ideal. I really liked doctrine, perhaps I was using it wrong, but having everything in annotations was pretty nice since migrations etc could run off of it. With doctrine I ran into issues with performance, which you can alleviate with extra lazy etc, it also hydrated what appeared to be massive objects, which you had to use a custom debugger because print_r'ing one with the recursive references etc caused some crazy issues. I have since moved on from PHP, but if the project calls for it, I have no problem using laravel. While not ideal, it sure is productive to build an API in. I wrote a project in lumen, which is/was a subset of laravel built for APIs, and that was okay to work in. No clue if it still exists.
- thrownaway954 8y agoIn all seriousness... doees PHP have C# envy? With all of the stuff that has been put into PHP7 (like typed returns and typed arguments) and stuff being proposed (like annotations), PHP isn't that far off from being a interpreted brother of C#.
- jsjohnst 8y agoBetter than the Java envy it had in the past.
- romanovcode 8y agoAll OOP languages have C# envy, they just don't want to admit it.
- EZ-E 8y agoQuestion : modern PHP is great for websites, but what are the solutions when you need to make some async work ? For example if I need to make few third party API calls in parallel ? With Laravel I resorted to using queues which feels like more complicated than it had to be (each worker takes up quite a bit of memory). Eventually I switched to SQS + Lambda + node.js. Is there any mature way to do async work in PHP ? In Node.js for example, it's quite trivial and powerful with promises and async/await
- no_gravity 8y agoOne easy way to do multiple http requests in parallel are the curl_muli functions: http://php.net/manual/en/function.curl-multi-init.php http://php.net/manual/en/function.curl-multi-init.php
- EZ-E 8y agoThanks, that's one solution if making multiple calls is needed. That was mostly an example though, for example if I wanted to run 3 functions in parallel, I don't find any "easy" and elegant way. Some libraries exist like amp, but it seems a bit heavy handed as the language itself doesn't have great tools for it https://github.com/amphp/amp https://github.com/amphp/amp
- no_gravity 8y agoWhy do you want to run 3 functions in parallel?
- EZ-E 8y agoIt's an example. For example if each of these functions takes about 0.2 seconds to finish, it might make sense to run them in parallel
- moojd 8y agoNeither amphp or reactphp will let you start running blocking functions in parallel out of the box. They basically just provide syntactic sugar for making single-threaded, cooperative multitasking easier by wrapping php's native ability to read/write to sockets asynchronously (or by using pecl extensions.) So you can respond to websocket messages or http requests asynchronously but you're not going to be able to implement anything like a parallel merge sort were you offload work to other threads. Things like general purpose file IO are not easy at the moment either. Amphp might seem a heavy handed because they've taken the monorepo approach. ReactPHP on the other hand has broken everything up into individual components. For example, you can get started with ReactPHP by just pulling in the event loop https://github.com/reactphp/event-loop https://github.com/reactphp/event-loop. All the heavy lifting for the native loop is <200 lines https://github.com/reactphp/event-loop/blob/master/src/StreamSelectLoop.php https://github.com/reactphp/event-loop/blob/master/src/Strea... and the API is tiny as well https://github.com/reactphp/event-loop/blob/master/src/LoopInterface.php https://github.com/reactphp/event-loop/blob/master/src/LoopI...
- gigatexal 8y agoUm... “Just for fun, I compared apples and oranges again by benchmarking the login page (which doesn't hit any database) for both application versions using Siege. The Symfony application (PHP 7.3, OPcache enabled, optimized autoloader) handles about 1470 req/s. The Go application (compiled using Go v1.11) averages about 18600 req/s.”
- gigatexal 8y agoI’d say that’s apples v apples.
- lixtra 8y agoYes, but you’re more interested in fruit salad vs. fruit salad. Maybe they actually never have to handle more than a dozen logins. But they have to change the templates relatively frequently: > it’s more maintainable for us to do it in PHP right now
- PunchTornado 8y agowhy would I need 18600 req/s ? If you're at that scale then probably symfony isn't for you.
- gigatexal 8y agoEveryone does: it’s like having a good offense: you don’t need to think about defense if you’re constantly scoring goals. A lot of issues can be hidden by being really good at serving content and taking requests quickly.
- xdfgd0ig0dg 8y agoThis is bad for your business and your devs on so many levels.
- the_other_guy 8y agoGolang is awesome once you submit and accept its intentionally mediocre design as a work of mysteriously genius simplicity. I did that myself and now I love it.
- waibelp 8y agoSymfony 4 is much more lightweight than previous versions. If you create a new symfony 4 project with composer you just get an empty project with just a hand full of dependencies. First time I tried out the v4 (coming from 2.x & 3.x) I thought that the installation did not work properly because stuff like twig (for templating) and other things were missing. The whole integration in composer with the symfony flex component makes developing even easier than before: https://symfony.com/doc/current/setup/flex.html https://symfony.com/doc/current/setup/flex.html
- ryanmccullagh 8y agoWhat IDE do people use for PHP these days? Editing PHP in a standard text editor is a pain because most don't supporet "Go to definition", or "Find all refernences" (Two killer features of Visual Studio)
- tatoalo 8y agoPhpStorm I'd say [https://www.jetbrains.com/phpstorm https://www.jetbrains.com/phpstorm]
- gknoy 8y agoI've always been a fan of JetBrains' IDEs (Webstorm, Pycharm), so I would imagine that their PhpStorm is similarly excellent. (Each of the ones I mentioned are language-specific subsets of IntelliJ.)
- ok_coo 8y agoMost of my work on a daily basis is PHP (Laravel) and I use Visual Studio Code as my main driver. It's pretty good with Python too, which we have a little bit of (mostly Flask apps).
- davidsawyer 8y agoDo you have any good extension recommendations for VS Cocde as it relates to PHP development?
- vaggal 8y agoFor code copletion I use PHP Intellisense but it still doesn't support multiple root folders in the same workspace. For debugging PHP Debug. vscode-php-cs-fixer and vscode-phpstan have helped a lot. In addition I use PHP Namespace Resolver and PHP DocBlocker. Lastly, PHP Getters & Setters may be useful.
- 013a 8y agoGo really just isn't designed for the same kind of service that PHP is normally used for. Its best at small API services (and, tangentially, its also pretty great at CLI tools). > They were a little surprised to hear our stack involved Golang and some flat out told us they’d prefer PHP, because that’s what most of our products rely upon. I believe this is the real reason why, and everything else above it is pointless technical justification for a sound business decision. I also believe there's an unvoiced, even more powerful reason, in "I already know PHP and don't want to learn a whole new thing." These are both sound reasons. The technical justifications are not. Choosing Go for something like this was a bad decision. But choosing PHP is only slightly better. Opting for Django, Rails, or Phoenix would have better technical justification, but technical justification is rarely the real reason why we make decisions like these.
- exceptione 8y agoYou are comparing frameworks with a language here. I think that if they choose to use a high-quality, modern php framework like Symfony, the technical decision would still make sense in the context of the alternatives you mentioned.
- 013a 8y agoThat comparison is intentional, for one reason: Go doesn't have any "frameworks", let alone frameworks that are remotely comparable to the productivity offered by Symfony, Django, or Phoenix. The language actively opposes the development of tools like these. At best, we've got libraries that wrap net/http, io/ioutil, etc and moderately increase developer productivity, but there's nothing holistic and opinionated. The closest you can get is something like gRPC, but its not even the whole story, and it also relies on codegen so that's a disqualification in my book. This isn't just technical; its baked deep into the culture of Go. And that's fine. Its designed for something different.
- crimsonalucard 8y agoI'm finding that although golang offers type safety it introduces a new kind of error class to applications typically not encountered in web apps of the python/php/ruby/node class. Deadlocks and race conditions. For node, the entire app is a single thread so this just doesn't happen. For python/php/ruby concurrency is abstracted away and handled above the framework layer so the programmer never has to deal with it. You can launch threads in a route handler for these languages but it's not often done and you have nothing like a context object that is basically this abstraction leak that explicitly forces the programmer to constantly be aware of concurrency issues.
- tmaly 8y agoInternally, I think PHP is great for prototyping. I have written systems in Go and PHP, and I think each has their strengths. I like the batteries included standard library and single binary deployment of Go. PHP, like others have said, gives you a single endpoint and you can make rapid changes. Its ideal for internal web apps that do not require insane performance.
- luord 8y agoNow that's pragmatism that's rare to see, specially here in HN.
- lazyant 8y agoSeems like he didn't go from Go to PHP but from Go to a PHP framework that does a lot of things for him.
- abbiya 8y agoWould you choose golang if we have a framework like symfony in Go?
- kenzieL 8y agoI stopped working with PHP about 4 years ago and I can't say I miss it. I moved to Python and never looked back.