6 ms·
f or x will do. If your function grows, rename the variable. Why would you just not give it a reasonable name to begin with? Why not call your variable frobber
by lemming 15y ago
f or x will do. If your function grows, rename the variable.
Why would you just not give it a reasonable name to begin with? Why not call your variable frobber? The only possible reason for not doing so is that you're using an editor that makes you type it every single time. I insist that calling your Frobber variable frobber is strictly easier to understand than f or x. Why not t? Or sdfsdg? None of them make any sense to someone reading the code, and it increases the amount the reader of the code has to keep in their short-term memory, making it more challenging to understand.
pg writes about this in On Lisp: long names feel heavier. They might be super cheap to call, but because the name is long, you're less likely to call it.
Even if pg wrote it this is patently absurd, and it's endemic in lisp code which contributes greatly to the famously write-only nature of lisp. Again, if you're using a decent editor, there is no reason to call your UserDetails object anything but user-details (or maybe details if you're in a context only relating to users).
- snprbob86 15y ago> The only possible reason for not doing so is that you're using an editor that makes you type it every single time. Here's some C: for (int player_index = 0; player_index < players.length; player_index++) { int rank = player_index + 1; render_score(rank, players[player_index].name); } Blah. So much for the brain to parse! for (int p = 0; p < players.length; p++) { int rank = p + 1; render_score(rank, players[p].name); } I find that much, much easier to parse in my head. The definition of p is available without any backtracking. The word "player" appears five fewer times, reducing confusion with the players array. This is a small case. If this code were to start to grow, and the definition of p and its usages start to grow appart, it's trivial to replace.... but it's probably better for you to refactor.
- lemming 15y agoThat's kind of a pathological case you have there - I don't think many people would argue that loop indices should have long variable names. None of the examples in your post above were loop variables, and what I see a lot of in lisp code is using ps for players, for example. In your example you've used pretty sensible names for players, rank and render_score - why not ps, r and rs respectively?
- snprbob86 15y ago> why not ps, r and rs respectively? Um... Because that would be hard to read? I'm advocating using full words in general, avoiding long variables (multi-word phrases, adjectives, contextualization, etc), and not being afraid of short variables names if they help, rather than hurt readability. There are plenty of cases where short names are totally fine. If you've got a module full of string utilities and every single function takes a first argument of type String, why not just call it "s"? Everyone will figure it out in seconds and it will save the mental overhead of differentiating "String" and "string". when that does come up. Things like that; I'm saying use your judgement.