I found my variables' name are too long and I need spend a large time in typing their name.But I don't know what should I do to shorten their name and keep their meaning?
Is there any ideas?
For example:
'gate_descriptor_t'
'divide_by_zero_error'
'write_serial_str'
How to give a brief but meaningful name to my variables
-
- Member
- Posts: 27
- Joined: Wed Jun 29, 2022 2:17 am
- Libera.chat IRC: theflysong
How to give a brief but meaningful name to my variables
I'm a new man to develop operating system.
Re: How to give a brief but meaningful name to my variables
Keep them reasonably long and meaningful. It will pay huge dividends when you come to look at your code in a few months time. It doesn't increase the size of the executable and it's not that much extra typing. It also helps you to think about what you are actually doing when you use them.
Of course this doesn't apply to simple utility variables such as loop counters; there's no problem in using short, even single-letter variables there.
Of course this doesn't apply to simple utility variables such as loop counters; there's no problem in using short, even single-letter variables there.
Re: How to give a brief but meaningful name to my variables
Use an editor/IDE that allows for autocompletion. In VIM, for example, you can simply press CTRL-P to complete the word. Many IDEs have CTRL-Space or similar.
Those names you have cited aren't long. They are exactly the right length, and convey your meaning even to people that haven't read the code. That is a good thing. Too often I hear the advice that names should be long without the qualification that they should have the right amount of meaning. Being overspecific and writing novels worth of text each time is counterproductive. Being underspecific and having cryptic variable names people cannot understand is not helpful.
Those names you have cited aren't long. They are exactly the right length, and convey your meaning even to people that haven't read the code. That is a good thing. Too often I hear the advice that names should be long without the qualification that they should have the right amount of meaning. Being overspecific and writing novels worth of text each time is counterproductive. Being underspecific and having cryptic variable names people cannot understand is not helpful.
Carpe diem!