5 ms·
You can do this, but should you? Solutions like this, more abstraction to avoid repetitive code, are usually much worse than the problem. > Though we notice w
by gizzlon 7y ago
You can do this, but should you?
Solutions like this, more abstraction to avoid repetitive code, are usually much worse than the problem.
> Though we notice we only greet for mornings and afternoons so always having to pass “Good morning” or “Good afternoon” becomes a bit annoying.
Maybe? But one can do much much much worse than "a bit annoying"
> It would be great if we could create an instance of our “greet” function with the first argument pinned down.
No.
- iikoolpp 7y agoAh yes, the Go mantra. Make your code as dumb and long as possible.
- gizzlon 7y agoCompared to what? I used to do scripting languages and Go code is usually more verbose. Not much more verbose though. Think it's mostly the static typing. While keeping things short is a goal, it's not the only goal..
- dgb23 7y agoWriting dumb code is often a good thing. Dumb code still solves your problem and can be structured well to keep it readable and maintainable. I feel like code even should be dumb most of the time and only clever when needed. The hard part is to figure out when to be clever.
- qt-lmao 7y agoWrite clever code then dumb it down
- JyB 7y agoFound a “clever programmer club” member.
- tgv 7y agoI sort of agree. I had a project in which I wanted to use Go, but I ended up writing Emacs macros to repeat boiler plate code. That wasn't pleasant, and to me it meant that Go wasn't the most suitable language for that problem. That applies here too: if you find yourself writing too much boilerplate code in favor of an abstraction, try another language. If you want/have to continue in Go, look for another solution.
- erik_seaberg 7y agoGo demands a ton of boilerplate but writing it all by hand isn't a good use of time. Lots of people are working on //go:generate tools, much as cfront used to emit awful C boilerplate we would ignore while writing C++.
- ViViDboarder 7y agoWell, even if you think it would be great to have a greet function with the first argument pinned down, that is trivially done without currying. Currying would only really be useful if you have many functions you want to pass the “Good morning” parameter into.