ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
View Poll Results: what do you do with your variables?
When I'm doing real programming, I try to use meaningful variable names. For a while I attempted using Hungarian notation, but lapsed out of it. Too bad there's no really standard practice for that; it can be helpful to remember what type something is later on in the program, though. Some obvious exceptions, though, like i, j, k, for loops, or temp for temporary storage.
If I'm just hacking together something simple, I don't bother with descriptive variable names. foo, bar, ack, blah, and so on. Sometimes it's fun to give them personal names, like Fred, Jim, Steve, etc., so they can have an identity
Man, I need to do some programming. Haven't touched the stuff in almost a year...
It depends on the type of program I am working on. If it's just for testing something or new ideas, I use simple variables. But while working on a project, I make sure that the variable names are meaningful. Hungarian notation, I guess is not a great idea (Maybe coz it was developed by M$ )
Well, one of my latest programs (in java) has a flowlayout flem, gridlayout grim,
a pannel called pain... (pane..) I also have a thelps (for the help stuff) who was a character in one of the books I wrote in elementary.
I sometimes name my vars in spanish, to avoid restricted words.. such as new etc.
No matter what language im using or what program im writing I always use descriptive names.Whether I am writing a game engine or writing a program to test an idea Its program relate variable names for me.
Just think about the guy that comes after you and has to read your code, than you have your answer quite quickly. Always use descriptive variable names to keep your code readable!
From GNU.org
auto accident;
register voters;
static electricity;
struct by_lightning;
void *where_prohibited;
char broiled;
short circuit;
short changed;
long johns;
I keep my variable names simply program related. That keeps the record straight and the program can be easily understood by anyone.
Learnt a good lesson when a few years ago I messed up with the names of my variables and at a later stage could myself not understand(literally) which variable represented what
Descriptive and program related.
Even if I'm doing it just for fun, because if I ever want to look at that program again I won't have a clue what's happening if they aren't well named.
I try to keep them short, but if I have to I'll use longer ones to remove any ambiguity. ~5 character generally, ~15 for the longer ones.
I always try to be descriptive where I can, normally i put sections into my code, such as "video_codec_check" so it implies what it is (a check box), what it is related to (a bitrate) and what area it is for (video).
Not variables, but I do have a nasty habit of leaving in warnings:
Code:
warn "arse";
was left in a release version of my acidrip package.... clever stuff!
I hardly program but when I do, I don't care much about my variables as long I can figure out wat I am doing and be able to follow back...
maybe that is to why I never get far...
I think I should give more attention to the variable ...
Good post
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.