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.
I am learning to use GTK+ in C, and as I am making more complex examples a few things are starting to bother me:
The lines of code are VERY long!
There is a huge amount of widgets. How do I name them uniquely in a way that makes sense with the hierarchy of containers without having 30 character long varaibles?
It is best practice for all widgets to have a unique name, or is it a good idea to have some temporary widget variable?
For as much as I know I don't understand how you can manage a small settings dialog, let alone a full GUI app!
I don't deal with GTK very much but in my experience with Qt you'd break individual widgets into their own classes and use pointers to handle the too many variables problem.
The idea of using a class as mentioned by alunduil is still valid in C. Just think struct rather than class, and remember it's just a container for that dialog. That way you will have a struct for, say a printing dialog box and you can call you cancel button cancel, or btnCancel if you prefer. You can also create a find dialog box again create a struct and the cancel button can be given the same variable name.
That's the price you pay to make the code maintainable.
To help make the code more readable you can always break your lines up and aligning each variable beneath each other, this is often necessary when passing several widgets to a function. You can then choose an alignment style that suits you aesthetic needs.
Not certain what such liberal usage of whitespace Python would make of that approach, probably awaken the Knights who say Ni from within the interpreter.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.