3 ms·
This is one of the idioms of Go I liked. "It's OK to repeat the same 3 lines of code." My thought process has always been: If there is a common piece of functi
by B-Con 8y ago
This is one of the idioms of Go I liked. "It's OK to repeat the same 3 lines of code."
My thought process has always been: If there is a common piece of functionality to be shared, then refactor. If it just happens to be the same, maybe leave it.
- rabidrat 8y agoOTOH, when you're repeating the same 3 lines of code over and over, refactor so it can fit in one line of code. This is one of my big peeves with Go; in C at least I can make a RETURN_ERR macro.
- lelf 8y ago> It's OK to repeat the same 3 lines of code … 2–3 times. Not ok to repeat them 1000 times.
- ummonk 8y agoNo, Go repeats the same 3 lines of code millions of times that you should never really have to do. There is no reason you should have to constantly throw in err != nil boilerplate when other languages have Optionals that make this automatic (and typechecked too). Likewise with for loops that could be done much more simply with proper maps and reduces.