3 ms·
Single letter variables. A terrible pattern the go community picks up.
by madeofpalk 3y ago
Single letter variables. A terrible pattern the go community picks up.
- favadi 3y agoSingle letter variables like `i`, `j`? How `index1`, `index2` is any better?
- cultavix 3y agoMy guess is that he means, he would prefer variables to be more descriptive. Easier to read and follow.
- leetrout 3y agoEh. Yes and no. I have not worked on a team that enforces that and I do agree with using them for short functions with 1 or 2 types. I do this in python as well with open(..) as f:
- lm28469 3y agoIs that really the best argument against Go lmao ?
- carb 3y agoI have never seen this done in enterprise Go code, and I don't think it's been strongly recommended since the mid 2010's? For small functions where you can see everything in a single page, this is fine. Though I think they should always be avoided except the most common cases (`i` for index) because keeping a codebase grep-able is a high priority. Using constant, verbose variable names can make tracing through a codebase much easier.
- jjgreen 3y agoI've heard that this is the result of snake-case refugees from C, Python etc. Single letter variables are camel and snake, everyone's happy.