News for hackers. Stuff that matters.
Re:Why we need a book about naming by croo on Thursday February 13, 2020 @05:05AM (#22316561)
I found the CleanCode book suggestions good enough for naming conventions:

Variable name length should be proportional to its scope. Only used in the next three lines? "i" is good enough. Is it a public field? Then its name should be long enough to be descriptive.

Functions are somewhat the inverse of variables - private functions called once or twice should have long descriptive names, public functions / api calls should be short descriptive names. This way I can always tell by glance what goes on under the hood if I ever have to peek.

Contrary to parent comment I found it absolutely unacceptable to call a function "asm". A few more characters costs literally nothing and it helps communicate intent to other programmers or future self. Even if the name itself become a lie the intent will remain true and will tell stories about what the original tought process was.

Re:Why we need a book about naming by geocar on Thursday February 13, 2020 @05:12AM (#22316588)
> Contrary to parent comment I found it absolutely unacceptable to call a function "asm".

You can take your snark up with GCC, and leave me out of it:

https://gcc.gnu.org/onlinedocs/gcc/Global-Register-Variables...

Re:Why we need a book about naming by quelltext on Thursday February 13, 2020 @05:28AM (#22316643)
I think they may have simple misunderstood what your example was about (G, not asm(...)).

On the other hand their criticism contradicts their earlier point about widely used public/stdlib function names best having short names.

Re:Why we need a book about naming by marcosdumay on Thursday February 13, 2020 @05:39AM (#22316690)
Widely used libraries have one more constraint, in that they will always be used a lot, but they'll never be the most used things on any code base.

As a consequence, they shouldn't use very short names. They should let the 1-3 letter names available for local code. (But there are exceptions, of course. There always are.)

Re:Why we need a book about naming by simiones on Thursday February 13, 2020 @05:25AM (#22316637)
You misunderstood the parent code snippet, even if your statement will still stand. "asm" is a GCC intrinsic for inline assembly code. The name he was pointing to was "G" - that is, in the entire program, the variable G is used to mean a pointer to processor register r12 I believe.
Re:Why we need a book about naming by croo on Thursday February 13, 2020 @08:37AM (#22317603)
Yeah I misunderstood it. I never wrote a single inline assembly code in C in my life so that probably flew over my head but I hope my general message is clear: don't use less letter than whats needed to be understandable and descriptive. If every C programmer thinks the same when he sees 'asm' then its great. If you have to go into the function body to find out "what the fuck is 'asm'" then its definetly not and your function name is bad and you should feel bad.

Thats the message.

Like... 'eval' instead of 'evaluate' is probably fine as everyone understands it (though I would vote for the latter). 'evaluate_code' is just additional noise without entropy.

'umount' or 'passwd' or 'usr' gets a sad head shake from me every time. Or function names with numbering in it. These things are just terrible.

Re:Why we need a book about naming by js8 on Thursday February 13, 2020 @07:49AM (#22317296)
> Variable name length should be proportional to its scope.

I remember the rule from CC, and I kinda like it. But there are obvious exceptions to that. There are things like logging or printing in the global scope that one would die for to have short names.

Also if you have an object with many fields that you need to access. Then it is more convenient to give it a short name, to make the code more readable.

So parent's suggestion, to have length of the name inversely proportional to its frequency, is also a good point. The two conventions unfortunately sometimes contradict.

Re:Why we need a book about naming by croo on Thursday February 13, 2020 @08:46AM (#22317650)
I agree and these are definetly just guides not hard rules to follow. What I'm really against is using a short name which don't convey any meaning.

For example 'getRtw' - which is a great shorthand for something we may never know until we go and find out. That is unacceptable naming anywhere regardless of scope, function, whatever. Use short but meaningful, pronouncable words as names and don't left out random characters from it (like usr instead of user) because thats just silly.