Thanks to Guido da Rozza for the base image CC BY 2.0
I’ve often coded in PHP. Recently, I realized that when I code in Go, it’s easier to spot my PHPisms. After weeks of cleaning them up, it only takes a day to fry my brain with them again. I’m sure I’m not the only developer doing this, so I started collecting tips and tricks to help with the process. I’m sure other ElePHPants have their own tips and tricks, but here are a few of mine.
You don’t always need an additional memory allocation.
PHP’s API is formatted into functions that return values. Want to parse JSON? Just read a string into a variable and
I know – there are exceptions like
fgetcsv. Still, you can anticipate that you pass a variable as input and get some kind of output. Variables, as opposed to resources, must be noted here.
Conversely, Go allows for variables as much as streams. You’re able to
In Go, you have to determine what to do and the ramifications of your actions. Will it be better to process loading/unloading from memory (
json.Marshal) or just iteration through the