[OT] Auto code reformating / one coding style enforcment.

Jarrett Billingsley kb3ctd2 at yahoo.com
Sat Aug 12 14:05:42 PDT 2006


"Dawid Ciezarkiewicz" <dawid.ciezarkiewicz at gmail.com> wrote in message 
news:eblf6h$1vo6$1 at digitaldaemon.com...

> Most of the time of my coding work I'm dealing with code that I didn't
> wrote. What is most irritating is when I just can't reformat code using
> indent or astyle because I need to work on little change and produce diff
> that will fit into original repository. And sometimes code is completely
> mess - I don't care if someone likes breaking brackets here and there,
> but ... I thing you all know what I'm talking about.
>
> My thoughts are always like this: why creators of C language allowed 
> people
> to format code freely? Wouldn't world be a better place if languages would
> enforce their one-true-coding-style? If there would be no choice there
> would be no reason to argue.

I always thought it'd be cool if there were an IDE which could read in code, 
parse it into tokens, then display the tokens in any format you wished, and 
you could change things like indentation, spacing, bracket styles etc.  Then 
when you saved, it'd write it back out as a text file.  Of course, like you 
said, when dealing with things like diffs for repositories, you can't really 
do that..

> "If I'd write my own language ..." (don't get it too serious - it's only
> hypothetical ;-) ) there would be no way to code same code in two 
> different
> ways (except of identifier names, comments and such ...). There would be
> one standard and compiler would enforce it - throwing errors about code
> formating or even reformat code in the fly if asked to (optional switch or
> something like that).
>
> The users would have to adopt to code in such language - get used to one
> coding style, which probably wouldn't be what they were doing before in
> every aspect, but ...
>
> ... after some time they would discover that when they look at someone 
> else
> code in that language - there is no difference. Working with patch/diff
> tools is nicer, reading code pleasure is bigger. Everything is better ...

Most Basic languages are pretty much this way.  Whitespace and newlines are 
a lot more significant, and as such, you can pretty much only write 
constructs one way.

> Python code tries to enforce coding style rules - I like that aspect of 
> it.
> What I don't like is not enforcing to use tabs for indentation and which 
> is
> even worse - not enforcing on _any_ standard about indentation, only to be
> consistent in whole source file. Except that I'm not aware of any language
> (except Whitespace ;-) ) that do something similar. Have anybody even
> tried? Did such language succeed?
>
> What do you think?

I think you're on target with the idea that it's stupid to have such a 
freeform language style.  All that happens is everyone develops their own 
styles and everyone gets into religious debates about which is better.  In 
other words, it's a lot of argument over nothing.

What seems to be the most common solution to this problem is that 
programming teams / companies will often adopt a single coding style.  To 
this end, it would be very useful if there were a "dtidy" tool that everyone 
would have to run on their code before submitting it to everyone else.  This 
tool would optimally be powerful on its own, but with scriptability so that 
really obscure coding styles (like lining up braces with the left paren of 
the owning construct.. wtf) could still be generated.  Or, this tool would 
just look at the input and complain if it doesn't match the given coding 
style spec.  Kind of like a style lint tool.

Oh, and spaces should die.  Hard tabs for LIFE. 





More information about the Digitalmars-d mailing list