weixin_39922868 2020-11-21 21:39
浏览 0

Source code naming convention

For motivation see #88.

NZBGet code base is old. The project was started in 2004 and from the beginning uses hungarian notation for identifiers. No one uses it nowadays anymore since it does more harm than good.

The naming changes can be done for example using global text replacements. The big problem here is to guarantee that the code works as before.

Work items

This list is continuously updated.

1. local variables, member variables and function parameters: - [x] define new naming convention; - [x] do total renaming; - [x] make sure everything is intact after the global naming change; - [x] review conditional code paths; - [x] review results and make additional manual renamings where appropriate.

1.5. repeat step 1 for folder "tests": - [x] do total renaming; - [x] make sure everything is intact after the global naming change.

2. normalize acronyms: - [x] do identifier renaming; - [x] rename related source files; - [x] make sure everything is intact after the global naming change.

3. global variables: - [x] define new naming convention; - [x] do total renaming; - [x] make sure everything is intact after the global naming change.

该提问来源于开源项目:nzbget/nzbget

  • 写回答

7条回答 默认 最新

  • weixin_39922868 2020-11-21 21:39
    关注

    Step 1: local variables, member variables and function parameters

    In older code:

     C++
    // OLD
    class Tokenizer
    {
    private:
        char                m_szDefaultBuf[2014];
        char*               m_szDataString;
        bool                m_bInplaceBuf;
        const char*         m_szSeparators;
        char*               m_szSavePtr;
        bool                m_bWorking;
    
    public:
                            Tokenizer(const char* szDataString, const char* szSeparators);
                            Tokenizer(char* szDataString, const char* szSeparators, bool bInplaceBuf);
                            ~Tokenizer();
        char*               Next();
    };
    

    Requirement: We want to remove type prefixes (such as sz for strings, b for booleans, etc) for local variables, member variables and function parameters. Variable names must be written in camelCase (starting with low case character).

    The new code should look like this:

     C++
    // NEW
    class Tokenizer
    {
    private:
        char                m_defaultBuf[2014];
        char*               m_dataString;
        bool                m_inplaceBuf;
        const char*         m_separators;
        char*               m_savePtr;
        bool                m_working;
    
    public:
                            Tokenizer(const char* dataString, const char* separators);
                            Tokenizer(char* dataString, const char* separators, bool inplaceBuf);
                            ~Tokenizer();
        char*               Next();
    };
    
    评论

报告相同问题?