Date: Wed, 20 Jul 2011 22:05:33 +0300 From: Shinnok <admin@...nnok.com> To: john-dev@...ts.openwall.com Subject: Re: coding styles for c/c++? indenter? emacs settings? Hi all, It's time that I chip into this discussion as well, didn't have time till now. First a question, what do you mean by *hands*("indent and hands"), is it indent and manual changes? Because I couldn't find any indenting tool by that name. Next let's draw the line where we are talking about C and when we are talking about C++, since the latter is vastly more complex when it comes to coding style and conventions. C is out of scope for our Johnny and Qt project and what comes next in this e-mail applies only to C++ and in Qt development context. About using indent or any other tools for automatic style, this is a bad idea in my opinion. Automatic tools don't understand certain code style changes that are required on a case by case fashion that you often run into when coding in C++, for e.g. if you need to break a really long line on multiple lines and align it properly, then running indent or any other automatic tool would break that custom alignment for good. These tools are infamously bad for C++ code and all of its quirks. The only valid use case when I would use an indenter tool is when I write an entire piece of code(or file) from scratch in a hackish way and then I need *only* that piece of code or file initialized to something closer to a required standard style and then apply further changes manually, but I would never run such tools on existing code, especially if it belongs to someone else. The line width I usually follow is 80 chars. But one can break that in justified cases. About the tabs, I don't recommend and never use(unless I'm forced by an existing rule or style) 8 width tabs for C++, since lines easily get over the 80 chars limit in OOP style languages, especially when following coding conventions like camelCase, PascalCase, m_ for class members and properly named classes and methods. I also recommend chars instead of tab characters. For general C++ and Qt coding style and conventions I recommend you read these links: http://developer.qt.nokia.com/wiki/Qt_Coding_Style http://developer.qt.nokia.com/wiki/Coding_Conventions http://qt.gitorious.org/qt-creator/qt-creator/blobs/master/doc/api/coding-style.qdoc Useful for reading(mainly for the conventions, ignore the style): http://techbase.kde.org/Policies/Kdelibs_Coding_Style http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml (read the conventions, ignore the coding style) We should follow the Qt Coding Style, as for more specific rules, I think this ones are the most important for now: * PascalCase for slass, struct and enum names. * camelCase for slass members. * ALL_CAPS for defined macros(and underscores for word breaks) * for constants: const int kDaysInAWeek = 7; * If ever a need for simple C function shall arise(most probably in a global space), use this_global_function(). * For local storage temporary data you can use whatever naming you want(like google's one above), but make it suggestive and consistent. I use camelCase here too. * White space should follow the Qt Coding Style. * m_ prefixes class data members - I have to think a bit about this one, if it is needed in Johnny's context. * White space should follow the Qt_Coding_Style wiki page. * Bracing K&R. That's what I use for C++ and Qt, if you feel different, let's debate since this is nothing near to set in stone. :) I would also not recommend using Vim or Emacs for long Qt coding sessions when it comes to Johnny. You should use Qt Creator. Regards, Shinnok On Fri, Jul 15, 2011 at 1:44 AM, Aleksey Cherepanov <aleksey.4erepanov@...il.com> wrote: > I want to know how to indent the code right. > > Owl/doc/CONVENTIONS says that good (not perfect) way to indent is > 'indent -kr -i8 -nlp -nbbo -l79 -lc79' > (http://cvsweb.openwall.com/cgi/cvsweb.cgi/~checkout~/Owl/doc/CONVENTIONS?rev=1.33;content-type=text%2Fplain > ). > > But documentation for indent says that it is not suitable for c++. For > instance template > 'func<T>(arg);' > will be formatted as > 'func < T > (arg);' > that is not good (i saw similar code in Johnny). > > Are there any known or already used alternative of indent for c++? > > May it be easier to use indent and hands? Because as i understand it is > needed to use hands even with indent as of it is not perfect. > > By the way why indent is not perfect? What does indent miss? Or what is the > difference between indent and the preferred coding style? Or what is the > preferred coding style? > > Also i want to set my editor up to support such style. Does anyone have > such settings for emacs? Probably set up editor could replace indenter. > > Regards, > Aleksey Cherepanov > -- Shinnok <http://shinnok.com>
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.