Code like this is interesting to me whenever I see it:
const g = [['', '', ''], ['', '', ''], ['', '', '']] // grid Why not just be descriptive and call it `const grid`? It's like we're all playing some game to be as terse and obscure as possible with variable names in all languages.
So many code examples have things like this and worse.
One I saw the other day had about 10 variables created in one part and then these were all placed into another object that had the same names as all the variables. You also see a lot of examples with loads of other irrelevant code in them. Just keep it simple please!
For small functions / blocks and descriptive types I’m ok with it in Go BUT I always use descriptive names anyway. So much easier to keep context in my head.
I thought the whole single-char-var thing was for very short-lived variables.
I very much prefer
for c in internalProductCategories
p = fetchProductsInCategory(c.id)
m = getAccountManagerName(c.id)
results.append({categoryName: c.name, products: p, manager: m.name})
to
for internalProductCategory in internalProductCategories
products = fetchProductsInCategory(internalProductCategory.id)
manager = getAccountManagerName(internalProductCategory.id)
results.append({categoryName: internalProductCategory.name, products: products, manager: manager.name})
They're both clear, neither needs comments, but one is unnecessarily verbose.
I'm not sure this is "ordinary practice", especially as `nan` often refers to "not a number" as an error category.
Typing full words doesn't take that much longer than acronyms, and results in more readable code (although this is well enough established at this point that I don't think I need to go over it).
Bugs are ordinary practice. Importing naughts and crosses is not. I giggled mischeviously when I wrote it. Particularly since it looked Pythonic. YMMV.
I have no problem with abbreviations over a limited scope but
looking at this code[1] I can't figure out what the author meant
by 'm' and that makes me wonder if the author does know what he's
doing.
>> if you change the state, it runs the function again, this returns a new virtual DOM
What do you mean by "change the state"? How do you do that? By calling some function, or perhaps by assigning a value to some property of a state-object? OR by calling the function again with a different state-object? Thanks
If that grid was going to be used in a single loop or something I may write it like that but any larger scope and it would definitely have a descriptive name.
Comments (156) 28 threads
Show all comments
Showing thread 25 of 28
const g = [['', '', ''], ['', '', ''], ['', '', '']] // grid
Why not just be descriptive and call it `const grid`? It's like we're all playing some game to be as terse and obscure as possible with variable names in all languages.
One I saw the other day had about 10 variables created in one part and then these were all placed into another object that had the same names as all the variables.
You also see a lot of examples with loads of other irrelevant code in them.
Just keep it simple please!
https://en.wikipedia.org/wiki/Code_golf
I very much prefer
to They're both clear, neither needs comments, but one is unnecessarily verbose.Continue this thread — 12 replies
Technically it's consistent with ordinary practice. e.g.
Typing full words doesn't take that much longer than acronyms, and results in more readable code (although this is well enough established at this point that I don't think I need to go over it).
Code should be stupidly obvious so that reading it consumes as less cognitive resources as possible.
[1]: https://github.com/leontrolski/leontrolski.github.io/blob/ma...
edit: Ok, I should have read the article first. It's probably for https://mithril.js.org/
What do you mean by "change the state"? How do you do that? By calling some function, or perhaps by assigning a value to some property of a state-object? OR by calling the function again with a different state-object?
Thanks