Earlier quoted context omitted.
Crazy that actually using your type system leads to better code. Stop passing everything around as `string`. Parse them, and type them.
As a PHP developer I am frankly disappointed you think that we only do that with strings. I've got an array[1] full of other tools. 1. Or maybe a map? Those keys might have significance I didn't tell you about.
How I write HTTP services in Go after 13 years
101–110 of 259 posts
Re: How I write HTTP services in Go after 13 years
#102Re: How I write HTTP services in Go after 13 years
#103Earlier quoted context omitted.
The issue is DRY often comes to wreck this sort of thing. Some devs will see "Hmm, Username is exactly the same as just a string so let's just use a string as Username is just added complexity". I've tried it with constructs like `Data` and `ValidatedData` and it definitely works, but you do end up with duplicate fields between the two objects or worse an ever growing inheritance tree and fields unrelated to either o…
One of the major issues with a lot of the outdated concepts in programming is that we still teach them to young people. I work a side gig as an external examiner for CS students. Especially in the early years they are taught the same OOP content that I was taught some decades ago, stuff that I haven’t used (also) for some decades. Because while a lot of the concepts may work well in theory, they never work out in a w…
Re: How I write HTTP services in Go after 13 years
#104Re: How I write HTTP services in Go after 13 years
#105Re: How I write HTTP services in Go after 13 years
#106Earlier quoted context omitted.
It's not guaranteed at all, that's where go's zero-values come in. E.g. nested structs, un/marshaljson magic methods etc. How do you deal with that?
Every struct requiring its zero value to be meaningful is probably one of the worst design flaws in the language.
It's funny seeing this beside the DRY thread. Seems programmers taking things a bit too literally is a common theme.
Re: How I write HTTP services in Go after 13 years
#107I just run Go servers under fcgi. You get orchestration and crash recovery with a very simple interface. Fcgi will launch server processes as needed, feed them events, and shut it down when there's no traffic. Performance is good, and you can run on cheap hosting.
Re: How I write HTTP services in Go after 13 years
#108Earlier quoted context omitted.
Every struct requiring its zero value to be meaningful is probably one of the worst design flaws in the language.
There is no such requirement. Common wisdom suggests that you should ensure zero values are useful, but that isn't about every random struct field – only the values you actually give others . Initialize your struct fields and you won't have to consider their zero state. They will never be zero. It's funny seeing this beside the DRY thread. Seems programmers taking things a bit too literally is a common theme.
“Just do the right thing everywhere and you don’t have to worry!”
You can’t stop consumers of your libraries from creating zero-valued instances.
Re: How I write HTTP services in Go after 13 years
#109> The Valid method takes a context (which is optional but has been useful for me in the past) and returns a map. If there is a problem with a field, its name is used as the key, and a human-readable explanation of the issue is set as the value. I used to do this, but ever since reading Lexi Lambda's "Parse, Don't Validate," [0] I've found validators to be much more error-prone than leveraging Go's built-in type check…