3 ms·
> If we're building an API, go will win hands down. I'm not so sure of that. Writing business logic in PHP is usually more concise than in Go, and more flexibl
by withinboredom 2y ago
> If we're building an API, go will win hands down.
I'm not so sure of that. Writing business logic in PHP is usually more concise than in Go, and more flexible. Also, I can think of a number of json schemas that are impossible to replicate in Go's type system but work just fine in PHP.
- zer00eyz 2y ago>> Also, I can think of a number of json schemas that are impossible to replicate in Go's type system but work just fine in PHP. Not at all. There are some that would be painful to write "by hand". An expansive and nested set of null fields would suck if I had to spell it all out... https://sqlc.dev https://sqlc.dev << changes everything. If you add in the YAML (and I hate yaml) you can get your JSON to DB mapping in there, as well as your validations (all output as struct tags). Everything else that you're going to want (transforming inputs to/from json, logging, auth) is some pretty simple middleware.
- dgb23 2y agoYou can't fully replicate JSON schemas in either language without writing logic. In terms of just static definitions, Go has typed container types while PHP has not. That's a pretty common case for JSON. PHP is more convenient at another common case which is heterogeneous maps. Neither of those languages make me particularly happy in that regard. It also depends on what you're doing with the JSON. If you want/need to walk through it in a single pass fashion, then Go is definitely more fitting.
- withinboredom 2y ago> Go has typed container types while PHP has not. I suggest looking at https://github.com/Crell/Serde https://github.com/Crell/Serde, if that is a requirement in PHP. > PHP is more convenient at another common case which is heterogeneous maps. Or arbitrary, user-defined keys... > If you want/need to walk through it in a single pass fashion, then Go is definitely more fitting. array_map, array_reduce, array_column is pretty good at walking through arrays very quickly, assuming you parsed the json into arrays instead of objects.
- deleted 2y ago[deleted]
- kmwr 2y agoGo has builtin typed container types while PHP has not.