変数名はその変数のスコープの近さ次第で短くすると良い。スコープが広ければ長く、短いなら1文字でもいい。

Reply to this note

Please Login to reply.

Discussion

That seems like an odd choice for variable names...🤔

I understand the point about choosing the shortest name that clearly conveys the meaning of variable but scope seems irrelevant to me. Whether it's used in a single function or a class or a library, the name has to be clear no?

And using i & j as examples is cheating -- everyone who learns programming, knows i & j the loop variable context. Without that learnt context index will be a better choice.

With editors, it's not like you need to type the variable name fully. (look at me, someone who's not coded a long time debating with Mattn-san 🤦‍♀️)

I understand what you says. :)

Using long variable names in a narrow scope can be noisy. Usually, as the scope gets narrower, what the variable points to should become more localised. For example, the relay URL list relayURLs is denoted relayURL in the loop, and the relay object resulting from that relayURL is named relay. However, if the range of occurrences of the variable is extremely small, it may be possible to avoid noise and use a single character. This is because the scope is narrow.

Thank you - I understand better now 🙏🙏

But with co-pilot and chatGPT, I suppose it will matter slightly less. The art of reading code to understand may be siphoned off to bots 😅

nostr:note1nlmeda8lq56j4saj2va6a8lxhpkxdj3ahw228c54w9kqkme6ac6sx7xp8f

本当にこれ

1~2回使用して消えていく変数に正確な長い名前を付けようとする人が多くて困る

x でいい

繋がりが目で追えればいいのよ 中の本当の単位が何かとか考えるだけ無駄