Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sat, 16 Jul 2011 23:50:05 +0400
From: Aleksey Cherepanov <aleksey.4erepanov@...il.com>
To: john-dev@...ts.openwall.com
Subject: Re: coding styles for c/c++? indenter? emacs settings?

> This is a very good page IMO:
> http://www.emacswiki.org/emacs/SmartTabs

Thanks! It looks interesting. By the way I saw that uncrustify
(indenter) had an option for such indentation.

> I use emacs and settings that are included (or linked) in that page
> but I believe they mention how to get the same result for other
> editors too.

Yes, there are links about similar indentation for other editors: Vim,
IntelliJ IDEA and Anjuta.

> I use a tab width of 4, but because of the basic idea of "tabs for
> indentation, spaces for alignment", anyone reading my code with *any*
> other tab setting will get it right.

I think it may be bad with long lines when change of tab width from 4 to
8 makes some lines too long.

Currently I stoped with Qt style (was not approved by Shinnok yet) and 2
additional settings for emacs:
(c-set-style "stroustrup")
(setq indent-tabs-mode nil)

I reformatted existing Johnny's code with Qt style so I think I will
stop searching indenter. However I think it is important to have
indenter that can do indentation perfectly. May be i will come back to
that later. Now I just say what I tried and what ideas I have.

For Qt style I found that there are settings for emacs and Vim in kdesdk
package. I did not try emacs settings. But I tried Vim settings thinking
about non-interactive mode. I tried `ex -c 'args *.cpp *.h' -c 'argdo
exe "normal! gg=G" | update' -c 'q'` with different settings. But such
way provide only indentation but does not provide formatting ('a+b' ->
'a + b', 'if (a)\n{' -> 'if (a) {'). I think it is possible to make Vim
do formatting. But settings from kdesdk seems to lack this feature.

I tried astyle and bcpp. In my opinion they are not enough flexible for
Openwall style.

But i found uncrustify that seems to me to be more flexible. However I
did not try it good because it has too many options to read about.

I found UniversalIndentGui that is suitable for trying different
indenters by hands. It has somewhat big list of supported indenters that
could be interesting to check.

I think it is possible to bruteforce indenter settings to obtain
autoindented code that is close to code indented by hands. If we have
alot of code indented by hands we try to indent it with indenter with
each settings set and remember lengths of diffs. Settings set that has
smallest diff is that we want. However set of settings sets are too
big. So we could try only one setting and check lengths with and without
that option. If diff with setting is smaller than diff without that
option then setting is needed. This way also have problems. For instance
if all strings should be affected by two options and without one of them
diff's sizes are equal. I guess that when we have alot of code it should
not occur. This method avoids a need to know about each option indenter
has but needs some coding.

I guess that probably some indenters can do it itself. I did not see
any. May be they use other logic to detect style.

Another way is to write special indenter for only Openwall style with
hardcoded logic. It is the most flexible way and may be the only 100%
solution but it seems to be the most hard way too. I think it is
possible to use a full parser from any modular program that deals with
code in smart fashion. I think that very possible that only compilers
are so smart. For instance clang could be used.

Of course these are only thoughts now.

Regards,
Aleksey Cherepanov

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.