Hacker News new | past | comments | ask | show | jobs | submit login

Single letter variables. A terrible pattern the go community picks up.



Eh. 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:


I 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.


Single letter variables like `i`, `j`? How `index1`, `index2` is any better?


I'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.


My guess is that he means, he would prefer variables to be more descriptive. Easier to read and follow.


Is that really the best argument against Go lmao ?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: