OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Apr 28, 2024 5:44 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: How to give a brief but meaningful name to my variables
PostPosted: Thu Jul 06, 2023 6:36 am 
Offline
Member
Member

Joined: Wed Jun 29, 2022 2:17 am
Posts: 27
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'

_________________
I'm a new man to develop operating system.


Top
 Profile  
 
 Post subject: Re: How to give a brief but meaningful name to my variables
PostPosted: Thu Jul 06, 2023 8:46 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4597
Location: Chichester, UK
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.


Top
 Profile  
 
 Post subject: Re: How to give a brief but meaningful name to my variables
PostPosted: Thu Jul 06, 2023 8:58 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1608
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.

_________________
Carpe diem!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group