Author Topic: Add more styling options to class wizard  (Read 503 times)

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2171
Add more styling options to class wizard
« on: December 27, 2018, 04:51:37 pm »
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: [Select]
* 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

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

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11394
    • Travis build status
Re: Add more styling options to class wizard
« Reply #1 on: December 27, 2018, 06:06:47 pm »
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: [Select]
while (implementation == 1 && it != m_MemberVars.end() )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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2171
Re: Add more styling options to class wizard
« Reply #2 on: December 28, 2018, 07:24:17 pm »
Quote
1. Always use the override keyword when overriding virtual methods
never seen in cb code... Will do!

Quote
2. Don't commit commented code
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)
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: [Select]
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;
        }
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.
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11394
    • Travis build status
Re: Add more styling options to class wizard
« Reply #3 on: December 28, 2018, 08:47:25 pm »
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: [Select]
<< bla << someotherbla << endofline << newlinebla << endofline << moreMy suggestion is to do something like appendLine(...); appendLine(...); I think it will make the code easier to read.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2171
Re: Add more styling options to class wizard
« Reply #4 on: December 29, 2018, 07:59:12 pm »
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).


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11394
    • Travis build status
Re: Add more styling options to class wizard
« Reply #5 on: December 29, 2018, 11:45:38 pm »
I don't think you need to introduce the usage of the function in the whole plugin, just the new places. But this is up to you, you're reading and modifying this code. I doubt that I'd touch it for anything other but reviewing patches.  8)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]