Hacker News new | ask | show | jobs
by CaptainOfCoit 746 days ago
> If you use the std lib you can write a simple web app in Go as well in few lines of code?

PHP is made for web development though, while Go is made for different use cases. Comparing the standard libraries makes this very clear.

Things PHP comes with that Go doesn't come with (just as some examples about standard library differences): PDO (DB interface), session management, built-in mail sending, localization and internationalization. That's just from the top of my head.

Go has it's places though, and it works well for web development too. But even I who like Go in general more than PHP, can acknowledge that PHP (by default) is better setup for web development out of the box.

That said, I would much prefer Go than PHP too, but hard to argue against PHP for web development without resolving to emotions and feelings.

1 comments

Apart from localization all of the things you mentioned come with Go as well. There's net/smtp, database/sql. You can implement in-memory sessions in Go with a few lines or use the well established gorilla sessions or similar.

The only thing you _need_ to install via dependencies is a DB driver.

On top of it you are getting a HTML template system with very good security defaults. You are generally better guided and guarded when dealing with HTTP user input. Routing and handling is more explicit and doesn't require you to deal with the Apache configuration syntax etc. There are no arcane configuration footguns like max_input_vars that will silently break your application and so on.

Errors handling and logging are again, more straight forward, universal and explicit.

If you need interactivity, SEE and Websockets are not only easier to use but also a more natural fit for Go.

I think for a language beginner those things are very, very beneficial. Us more experienced programmers sometimes forget how many battle scars we had to earn with languages like PHP.