Remix.run Logo
colesantiago 3 days ago

I bit the bullet rewriting my app from PHP to Go and it paid off for my company, we're talking 20K lines of PHP code, reduced to 4K lines of Go and with the added efficiency gains with it.

I think some orgs just need to take the jump and plan a rewrite, add tests (easier with Go) and just do this if they are a PHP shop, I would say it's worth it.

Instead of blending Rust/PHP or Go together and having an unmaintainable mess of a codebase.

criemen 3 days ago | parent | next [-]

How did you reduce LoC with a move from PHP to go?

Go is a pretty verbose language, whereas for me PHP is somewhere in the middle of the pack in terms of verbosity (Haskell would be on the terse side, enterprise Java and Go on the verbose end, particularly due to the constant error-checking after every function call).

yurishimo 2 days ago | parent [-]

Maybe they mean with dependencies? There are some bloated libraries out there but because PHP is a dynamic language, the bloat only matters if it’s in your hot path.

But I would say a 20k line PHP app is pretty small… we probably have 20 different 1k+ files in our app. They’re not pretty but they’re still fast enough and they work so I’m not gonna try and rewrite them just for giggles.

That said, when working on this legacy behemoth, it’s not uncommon we find a way to delete a few hundred lines because there are so many old features that aren’t needed by the business anymore so we can remove that cognitive load from codebase. Maybe that had a similar experience and the rewrite was just a good time to get buy in from the business to admit that the features weren’t important anymore. We run an e-commerce site so there are lots of little marketing experiments cluttering the app and it’s a constant churn to remove old ones and add new ones for people to tweak and test with feature flags. Removing dead code is just a part of the job.

coolgoose 2 days ago | parent | prev | next [-]

I fail to see how you got 5x lower loc from php to go.

Php isn't perfect but it has a lot of shortcut syntaxes that go just doesn't have

NeutralForest 3 days ago | parent | prev | next [-]

But the question always is: was the rewrite the reason for the gained efficiency, or the new language?

colesantiago 3 days ago | parent [-]

Both.

Go made this worth it and it also was easy to hand over to another experienced developer.

NeutralForest 2 days ago | parent [-]

Fair, what did you find in Go that you couldn't in PHP? Do you miss anything from PHP?

tayo42 3 days ago | parent | prev | next [-]

Surprised you made it more compact and not have it turn into 40k lines of if err! = nil

Ive done do rewrites of stuff in python and it gets really verbose, plus dependency injection patterns for testing.

benjiro 2 days ago | parent [-]

A ton of stuff in PHP is mostly templating + DB calls for a lot of websites.

If you combine Go + Templ for instance, your "if err" are mostly on the DB calls. What you needed to check in PHP anyway.

Yes, the if err != nil is extreme frustration when your doing for instance, type conversion. But if your already doing this with reflection in your DB calls (by casting to the correct types in your struct), that saves a ton.

Same with getting external data, casting it directly to structs and if something is wrong, its a single "if err".

And if your just doing PHP style programming in Go, well, _, ignoring errors like PHP does and you can panic/recover to make Go act as badly as PHP, to save on the "if err". ;-)

2 days ago | parent | prev | next [-]
[deleted]
avan1 2 days ago | parent | prev [-]

i don't recommend rewrite in anycase (had done 2 successful rewrite before but still i don't choose that my self) and new php run times can may be really fast. you can checkout benchmarks. swoole for instance if used with all the functionalities like its specific caches may be so fast (in some cases as fast as Go)