[poppler] Source code beautifiers

Jakub Kucharski jakubkucharski97 at gmail.com
Mon Jun 27 17:09:33 UTC 2016


Hello, everyone!

Poppler has a very diverse codebase if it comes to coding style. In
some places it gets really weird, e.g. the qt frontends, where we have
code like this ("▸---" marks a tab):

    bool Document::unlock(const QByteArray &ownerPassword,                                                                                                                
▸---▸---▸---  const QByteArray &userPassword)                                                                                                                             
    {                                                                                                                                                                     
▸---if (m_doc->locked) {                                                                                                                                                  
▸---    /* racier then it needs to be */                                                                                                                                  
▸---    DocumentData *doc2;                                                                                                                                               
▸---    if (!m_doc->fileContents.isEmpty())                                                                                                                               
▸---    {                                                                                                                                                                 
▸---▸---doc2 = new DocumentData(m_doc->fileContents,                                                                                                                      
▸---▸---▸---▸---▸---new GooString(ownerPassword.data()),                                                                                                                  
▸---▸---▸---▸---▸---new GooString(userPassword.data()));                                                                                                                  
▸---    }                                                                                                                                                                 
▸---    else                                                                                                                                                              
▸---    {                                                                                                                                                                 
▸---▸---doc2 = new DocumentData(m_doc->m_filePath,                                                                                                                        
▸---▸---▸---▸---▸---new GooString(ownerPassword.data()),                                                                                                                  
▸---▸---▸---▸---▸---new GooString(userPassword.data()));                                                                                                                  
▸---    }                                                                                                                                                                 
▸---    if (!doc2->doc->isOk()) {                                                                                                                                         
▸---▸---delete doc2;                                                                                                                                                      
▸---    } else {                                                                                                                                                          
▸---▸---delete m_doc;                                                                                                                                                     
▸---▸---m_doc = doc2;                                                                                                                                                     
▸---▸---m_doc->locked = false;                                                                                                                                            
▸---▸---m_doc->fillMembers();                                                                                                                                             
▸---    }                                                                                                                                                                 
▸---}                                                                                                                                                                     
▸---return m_doc->locked;                                                                                                                                                 
    }

With code like this I just end up copy-pasting things hoping that I
manage to guess the right way to format the code. So I've thought we
could make things easier by using a source code beautifier and
providing config files for it. We could either unify the coding style
or we could have different config files for core, goo, qt etc. (I'd be
in favor of unification.)

Two source code beautifiers that I know of are Uncrustify[1] and
ClangFormat[2]. For the second one there is a web page[3] which makes
its configuration a piece of cake and there is a python script making
it easy to integrate it with vim or any other highly configurable
editor. However Uncrustify seems to be more configurable. Flatpak devs
have a useful shell script making it easier to invoke Uncrustify[4].

What do you think?

Jakub

[1] http://uncrustify.sourceforge.net/
[2] http://clang.llvm.org/docs/ClangFormat.html
[3] http://clangformat.com/
[4] https://github.com/flatpak/flatpak/blob/master/uncrustify.sh


More information about the poppler mailing list