Live data from Hacker News

Go Naming Conventions: A Practical Guide

alexedwards.net

71–77 of 77 posts

Re: Go Naming Conventions: A Practical Guide

#71
post #44

Earlier quoted context omitted.

>you have to go back and find the body of the loop If the loop is long enough that you don't naturally remember how it was introduced, that's the problem. In the given example, the use of `p.Age` is literally on the next line of code after ` for _, p := range people`. > I've never understood what is gained by using `p` instead of spelling it out as `person`. Wisdom I received from, IIRC, the Perl documentation decade…

> remember how it was introduced The problem is that many times I have not read the definition to remember. Debugger puts me into a context where I have to figure out what `p` stands for. I go up the call stack and now there's `s` to be deciphered. Worse is the reuse of `p` for person, product, part, etc. in different contexts. Debugging is not the only problem. Code is read rarely linearly. Many times I browse diffe…

This is a decent reason, but your original comment is dangerously close to a completely strawman argument of "the argument of the func AverageAge(people []Person) should be called peopleToCalculateTheAverageOfTheirAges because what if I forget the method's name or its purpose while I am reading its text?"

Which, now that I think of it, kinda applies to your argument as well. Yeah, the debugger dropped you into the middle of a function you see for the first time in your life. No matter how you dice it or slice it, this means you'll have to study this function; I personally find that going to the function's beginning and skimming it until the breakpoint is the most reliable (and therefore, on average, fastest) method.

Re: Go Naming Conventions: A Practical Guide

#72

Earlier quoted context omitted.

> remember how it was introduced The problem is that many times I have not read the definition to remember. Debugger puts me into a context where I have to figure out what `p` stands for. I go up the call stack and now there's `s` to be deciphered. Worse is the reuse of `p` for person, product, part, etc. in different contexts. Debugging is not the only problem. Code is read rarely linearly. Many times I browse diffe…

This is a decent reason, but your original comment is dangerously close to a completely strawman argument of "the argument of the func AverageAge(people []Person) should be called peopleToCalculateTheAverageOfTheirAges because what if I forget the method's name or its purpose while I am reading its text?" Which, now that I think of it, kinda applies to your argument as well. Yeah, the debugger dropped you into the mi…

I don't deny the trade-off between variable name length and other factors. But, between 1 and 38, I doubt that the optimal length is at 1. Adding 5 more letters doesn't take anything away, IMHO, while increasing comprehensibility significantly.

Re: Go Naming Conventions: A Practical Guide

#73
post #44

> we use the identifier p to represent a value in the people slice — the range block is so small and tight that using a single letter name is clear enough. No, it's not. When you see `p.Age`, you have to go back and find the body of the loop, see what it operates on and decipher what p stands for. When you see `person.Age`, you understand it. I've never understood what is gained by using `p` instead of spelling it ou…

>you have to go back and find the body of the loop If the loop is long enough that you don't naturally remember how it was introduced, that's the problem. In the given example, the use of `p.Age` is literally on the next line of code after ` for _, p := range people`. > I've never understood what is gained by using `p` instead of spelling it out as `person`. Wisdom I received from, IIRC, the Perl documentation decade…

> Wisdom I received from, IIRC, the Perl documentation decades ago

Perl is a language renowned for being difficult to read and maintain.

Re: Go Naming Conventions: A Practical Guide

#74
post #44

Earlier quoted context omitted.

>you have to go back and find the body of the loop If the loop is long enough that you don't naturally remember how it was introduced, that's the problem. In the given example, the use of `p.Age` is literally on the next line of code after ` for _, p := range people`. > I've never understood what is gained by using `p` instead of spelling it out as `person`. Wisdom I received from, IIRC, the Perl documentation decade…

> Wisdom I received from, IIRC, the Perl documentation decades ago Perl is a language renowned for being difficult to read and maintain.

Tell us about your concrete experience of development in Perl.

Re: Go Naming Conventions: A Practical Guide

#75

> we use the identifier p to represent a value in the people slice — the range block is so small and tight that using a single letter name is clear enough. No, it's not. When you see `p.Age`, you have to go back and find the body of the loop, see what it operates on and decipher what p stands for. When you see `person.Age`, you understand it. I've never understood what is gained by using `p` instead of spelling it ou…

This comes from some dated idea for stuff like C where "its okay to use shorthands for variables" but is it really? The only place I allow it is simple iterators, but now we have enhanced loops where even this is unnecessary. We don't need to save on pixel screen space like if its still the 90s. Even with a simple 1080p monitor you can fit plenty of words and code. Give your variables, functions, classes meaningful d…

As creators of Go have strong ties with the creators of C, that idea is not so dated.

Re: Go Naming Conventions: A Practical Guide

#76
post #75

Earlier quoted context omitted.

This comes from some dated idea for stuff like C where "its okay to use shorthands for variables" but is it really? The only place I allow it is simple iterators, but now we have enhanced loops where even this is unnecessary. We don't need to save on pixel screen space like if its still the 90s. Even with a simple 1080p monitor you can fit plenty of words and code. Give your variables, functions, classes meaningful d…

As creators of Go have strong ties with the creators of C, that idea is not so dated.

Just because some brought it back to modern languages, doesn't mean it's not rooted in a practice from constrained hardware. I'd rather we name things what they mean.

Re: Go Naming Conventions: A Practical Guide

#77
post #74

Earlier quoted context omitted.

> Wisdom I received from, IIRC, the Perl documentation decades ago Perl is a language renowned for being difficult to read and maintain.

Tell us about your concrete experience of development in Perl.

'x' is an operator
Post reply on HN