[Tutor] A Question about coding style

Mats Wichmann mats at wichmann.us
Fri Sep 17 10:30:10 EDT 2021


On 9/17/21 02:18, Alan Gauld via Tutor wrote:

> The thing about coding style is that it is subjective (within limits).
> But in the real world it will be set by the organisation for which you
> work. They will likely have a set of coding guidelines that you must
> follow. In one place they may ban single line constructs. In another
> they may mandate them. It probably won't be your choice, it will be set
> by the QA team. They may even have built tools that reformat your code
> to comply.

I'll reiterate this.  There have been coding style arguments since there 
was coding, probably. Some earlier languages (Fortran on punchcards) had 
quite a rigorous requirement on the syntax, so less flexibility on 
"style", so less arguments? Well, not so much...

Nowadays, people are tired of arguments - public code reviews and code 
review tools have surfaced no end of style arguments - so there's 
increasingly the use of tools to enforce a style and try to take the 
argument out of it.  So that would be the advice: don't worry about it, 
let a code formatter answer those questions for you.

Aside as to multiple statements on one line: I work on a project that 
actually says don't do it, *except* for debug/trace statements, where 
it's encouraged to have those provide less visual impact on the function 
they may be used in, so you might see this:

T = self.tm.trace

if T: T.write(self.trace_message,...

in an area that's complex and has lots of tracing msgs, to keep so many 
of the interesting bits from being pushed off the screen.  That's going 
to go by the wayside when automatic reformatting comes in, which in 
discussion.



More information about the Tutor mailing list