Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
Add more styling options to class wizard
BlueHazzard:
Hi,
i have to make A LOT classes and the styling convention of the normal codeblocks settings are not in accordance with the code styling guidelines of the target, so added some settings to control the style of the generated code.
For this i had to add a settings dialog for the classwizard plugin.
You can find the changes on this branch:
https://github.com/bluehazzard/codeblocks_sf/tree/test/classwizard/addSettingsDlg
possible changes:
--- Code: ---* Parameter name of the set function:
- use generic "var" name (default)
- use variable name without prefix
* First letter of set and get function
- upper case (default)
- lower case
* Implementation of set and get functions
- header file (default)
- source file
* function name generation for the set and get functions
- variable name without prefix (default)
- variable name but with first letter upper case (came case) after the set/get
- variable name all lower case
- variable name all upper case
--- End code ---
additionally i added in the settings dialog the settings for the file extensions. Right now they are saved from the new class dialog. I added this for convenience...
any comments?
greetings
oBFusCATed:
1. Always use the override keyword when overriding virtual methods
2. Don't commit commented code
3. Indent with 4 spaces
4. Prefer declaring enums for special options instead of using the plane numbers (I'm talking about nameGeneration, firstLetter, implementation)
5. Prefer using simple range based iteration instead of hard to read and easy to make an error while loops. I'm talking about this
--- Code: ---while (implementation == 1 && it != m_MemberVars.end() )
--- End code ---
This could easily be replaced by an if and for-each loop.
6. Calling Right on empty string I think causes an assert
7. Do not write complex ternary operators, they are hard to read or debug. if-else are better.
8. Use const more often
9. Consider adding a function which can add a single row. The code dealing with code printing is quite hard to read.
I cannot comment if this is useful addition or not because I'm not using this feature.
BlueHazzard:
--- Quote ---1. Always use the override keyword when overriding virtual methods
--- End quote ---
never seen in cb code... Will do!
--- Quote ---2. Don't commit commented code
--- End quote ---
Yea... i will fix this with a rebase
--- Quote ---4. Prefer declaring enums for special options instead of using the plane numbers (I'm talking about nameGeneration, firstLetter, implementation)
--- End quote ---
Isn't is going to clash with the config read functions? (enum <-> int is not that easy anymore with never c++ compiler)
so i have to use static casts, but it seems to be the better solution instead of unchecked ints
--- Code: ---const ClassWizard::eFirstLetter firstLetter = static_cast<ClassWizard::eFirstLetter>(cfg->ReadInt(_T("/SetGet/FirstLetter"), 0));
[...]
switch(firstLetter)
{
case ClassWizard::upperCase:
mv.Get << _T("Get"); break;
case ClassWizard::lowerCase:
mv.Get << _T("get"); break;
}
--- End code ---
Is this coding style ok?
--- Quote ---9. Consider adding a function which can add a single row. The code dealing with code printing is quite hard to read.
--- End quote ---
I do not understand this sentence.. What do you mean by "add a single row" ?
I will add a other option to make the set function use const ref as parameter.
oBFusCATed:
4. Yes, you need to use casts from int and back to int. Currently I prefer to use constructor like casts, like mytype(myintvar). They make code easier to read. But are not possible to use all the time.
9. The code related to adding code to the editor/file is rather ugly and bad because you have
--- Code: ---<< bla << someotherbla << endofline << newlinebla << endofline << more
--- End code ---
My suggestion is to do something like appendLine(...); appendLine(...); I think it will make the code easier to read.
BlueHazzard:
ok, i rebased the branch and made a force push, so if someone wants to test it he has to force a pull...
i fixed most of your suggestions, beside the 9. If i add this i have to rework all code of the class wizard, and i do not have time and will to do it. I have tried it a bit, but the resulting code was not more readable as the current code... I think it is ok as it is, at the moment. I have added all things i need for my work. If someone else wants to add more functionality and change the code generation he can do it (maybe i am this person in a few months...) But i think the improvements ate the moment are quite good and necessary (specially the const ref setting).
Navigation
[0] Message Index
[#] Next page
Go to full version