8 ms·
>involves naming things as tersely as possible. No it doesn't. It involves naming things appropriately. If you have a 4 line function that does something wit
by asdasf 13y ago
>involves naming things as tersely as possible.
No it doesn't. It involves naming things appropriately. If you have a 4 line function that does something with a string, that string argument should be named "s". You aren't making it clearer by giving it a longer name. The length of a variable name is proportional to its scope.
- evilduck 13y agoI disagree. 's' has no meaning by itself, which means that you have to read all of the context surrounding 's' into your short term memory just to gain any understanding of the single line you may be interested in. That's slow and more work than necessary most of the time. Also, naming things is a habit and a style. Short variable naming leaks out of 4 line methods into any 40 and 400 line methods you may eventually write, and it leaks into the ABIs/APIs of your application. I've rarely seen any code that would use 's' appropriately in a 4 line method that wouldn't hesitate to use it everywhere else inappropriately.
- asdasf 13y ago>'s' has no meaning by itself That is exactly the point. It is just a string. That is the entire context of the variable, there is no more insight to be gained. The more generic a function is, the more generic the argument is, and thus the less context exists to be put in the name. Naming it "thisIsAStringJustSoYouKnowTwiceThatItIsAStringLikeTheTypeAlreadyToldYou" instead of "s" does not provide any benefit. >I've rarely seen any code that would use 's' appropriately in a 4 line method that wouldn't hesitate to use it everywhere else inappropriately. You should read more code. Both go and haskell have tons of examples, as this is standard practice in those languages.
- deleted 13y ago[deleted]
- jff 13y agoOh come the fuck on. At least to anyone who's written a C program, using "s" for a string argument is absolutely clear. Read the man pages for pretty much every goddamn string function in the standard library; strlen, strcmp, whatever, they call name them either "s" or "s1", "s2" if there are multiple strings. Maybe we should do strlen(const char* theStringThatIsBeingMeasured), that's a lot clearer. Maybe we should expand char to character, and strlen to stringlength, because it might not be clear enough.
- bsg75 13y agostringlength may not be clear enough. Need some underscores in there to separate the terms, maybe a prefix to indicate the type, and a url to the parameter documentation.
- pkinsky 13y agoDon't bring underscores into this, underscores scan quicker and are aesthetically pleasing! http://ieeexplore.ieee.org/xpl/articleDetails.jsp?tp=&arnumber=5521745 http://ieeexplore.ieee.org/xpl/articleDetails.jsp?tp=&arnumb...
- evilduck 13y agoWhy are you guys stuck on 's' definitely being a string? It could just as easily be a struct or anything else imaginable, in which case, you're back to not knowing anything about it from the name 's' without going to look it up. You can contrive simple examples about basic data types all you want, the simple cases and built in types are precisely where it's not a problem. Go read the src for Go's Unicode package as an example, you get 60 line methods with stuff like 't1' used all over the place and the value of t1 is assigned pages away from where it's actually used.
- asdasf 13y ago>Why are you guys stuck on 's' definitely being a string? Because that is the example I used. >It could just as easily be a struct or anything else imaginable, in which case, you're back to not knowing anything about it from the name 's' without going to look it up. If there were more information that could be conveyed, then it wouldn't be named "s". That is the entire point.
- gnaritas 13y ago> that string argument should be named "s" That's an opinion a lot of people don't and won't share.
- asdasf 13y agoThat's fine. But the point is that it isn't naming things as tersely as possible, it is naming things based on the value the name provides. There is no name you can give to "s" to make it more meaningful or useful. Thus a longer name is not beneficial.
- gnaritas 13y ago> There is no name you can give to "s" to make it more meaningful or useful. Again, an opinion others don't necessarily share. > Thus a longer name is not beneficial. Again, an opinion others don't necessarily share. You seem to have a habit of stating your personal taste as fact; it is not. Some of us always prefer full words as names as a matter of style.
- asdasf 13y agoRepeating the same thing is not productive. Nobody cares about personal taste or what you do or do not prefer. That has nothing to do with the topic.
- gnaritas 13y agoRepeating the same thing is not productive. Nobody cares about your personal taste or what you do or do not prefer. That has nothing to do with the topic.