I discovered PHP when I was 16 years old. It was the first language that I used for real programming. Back then I was using it to evaluate forms submitted by users and send an email, mostly “contact us” forms. Over the years I always kept PHP as my strength and I always made sure that I’m constantly expanding my PHP knowledge and skills. I don’t think I’m a master in PHP, but it’s the language I know best. In the past, I had the chance to work with Ruby, JAVA, Python, and NodeJS for small or medium projects. These experiences allowed me to see how PHP compares to other programming languages, leverage its strengths better and guard against its weaknesses.
6 Months ago I joined MessageBird as an Engineer. I applied for PHP, but little did I know that after onboarding I will start working with GoLang step away from PHP completely. It’s been an amazing experience, I learned a new programming language during this time and now I’m going back to PHP, taking with me 6 months of experience programming in GO.
GO is a powerful programming language with a unique combination of features. I am sorry for not giving it more time. I’m returning to PHP for reasons not related to the programming language, but, I do want to sum up this experience and share a comparison of the two.
Static vs Dynamic
GoLang is a static programming language, unlike dynamic PHP. This means that you always have to think in advance when initializing variables and objects. In PHP you never initialize a variable, you just start using it right away when you need it. Because of this, GoLang makes you think twice before you declare a new variable which I’ve noticed to be more productive than always checking the contents of a variable as we do in PHP. PHP added type declarations in version 7 and using those is a better practice, but thinking twice before writing your code is a much healthier practice.
Subroutines vs Parallel Processing
One of the most amazing features that GoLang provides is the goroutine. It allows running functions asynchronously. In PHP nothing comes close to the simplicity and easiness of Goroutines. Whenever you have to do parallel processing in PHP, you need to add external queueing mechanisms (Beanstalk, RabbitMQ, etc). This complicates the infrastructure architecture and increases the complexity of your project.
GoLang is the winner for parallel processing.
The concept of OOP has been around since programming was invented. It became the dominant paradigm in the 90s when the techniques became widely available in C++. The best thing that I like about OOP is that it allows engineers to create a map of the business logic using code. This proves invaluable when introducing changes in evolving systems. Both PHP and GoLang provide OOP features, however, there are major differences between the two languages.
One feature that took me a while to get used to is implicit interfaces. In GoLang, your type satisfies an interface after all the methods have been implemented. In PHP you tell explicitly what interface your type needs to define and after this, you start implementing. This feature of Go makes you not think ahead about your application’s contracts and it’s the opposite of what I expect from static type language.
An evolving model has complex needs that domain-driven design can approach. To accomplish this, you need many OOP features and PHP provides plenty of these — traits, abstract methods and classes, final method and classes, magic methods and many more. GoLang misses many of these features and it’s a limitation that’s difficult to overcome. That’s why I think GoLang is suitable only for microservices or small applications, while PHP is great for all, microservices, small, big and enormous applications.
I think the most important thing that defines the quality of a project is testing — unit testing, integration testing, functional, UI testing, performance testing — the more of these you have for your project, the better the quality of your deliverables. Both GO and PHP have excellent frameworks for unit testing — Go has the embedded testing package and PHP has PHPUnit, both of them provide a rich set of feature for testing your code. PHPUnit has more features than GoLang’s testing package and that’s because PHP has more features. Both tools get the job done for their programming language. However, when going into advanced testing, PHP and Go show major differences.
Firstly, for performance testing, Go has many features inside its testing package. Many libraries such as pprof use these features to create rich data reports. While PHP has its own set of libraries and techniques for performance testing, Go seems easier to use. I believe this is one advantage of a static type language.
Secondly, for advanced testing techniques, such as BDD, TDD, and A/B testing, PHP has more support, more libraries to choose from and a bigger community. For example, Cucumber (or Gherkin) has an implementation for both languages, but PHP with its BEHAT implementation has support for over 40 languages, it’s built from the ground-up on independent components and has more support on GitHub than Cucumber (more forks, more stars, etc)
Lastly, for functional or UI testing, PHP has more libraries and better support for existing tools. Selenium has great support for PHP (3000+ cross-browser testing, video recording, text and visual logs, etc) while for Go there is only an unmaintained driver — tebeka/selenium (last commit 5 months ago at the date of this post).
There are many other differences between the two languages, I will mention just a few:
- GoLang has better performance than PHP. There are hundreds of benchmarks that test PHP and GoLang in various situations and most of them, GoLang is a clear winner. On top of this, there is also the feeling of Go being faster while developing — tests run faster, memory is used more efficiently, CPU usage is lower.
- The PHP community outnumbers GoLang’s, and the support is amazing. I have seen some bad things being used in GoLang, such as code generators, things that the PHP community left behind years ago.
- Package maintenance is also very different. In GoLang it’s internally managed, while in PHP there are two layers with different implementations — first, the level of PHP extensions and second the libraries level for which everybody uses composer. For PHP it’s more complicated, while go manages the two layers in one.
There are clear distinctions between the two and the choice between one or the other is easy to do. GoLang has better performance, has native asynchronous functions and clean features which make it perfect for small applications and microservices that will require intense usage.
With PHP it feels natural to develop growing applications focused on complex business logic that leverage the OOP features and the community support.