Is coding style mostly for readability or are there other factors?
NickName: Ask DateTime:2009-08-08T18:58:58

Is coding style mostly for readability or are there other factors?

I remember reading in Douglas Crockford's "Javascript the Good Parts" book that there is potential for error with blockless statements because of automatic semicolon insertion.

if (condition)
   foo = true;

vs

if (condition) 
{
   foo = true;
}

In the second the example it will work consistently, in the first example a semicolon will be automatically inserted by the interpreter and can lead to ambiguity in the code. As Douglas points out this is potentially bad and hard to debug, which I agree. But it got me thinking are there examples where coding "style" actually has syntax implications? In other words, examples where failing to follow a certain indentation or apparent style actually results in a bug or error. I suppose Python with its significant whitespace is an example, YML with its requirement for no tabs is another.

Feel free to respond in a wide variety of languages and idioms. I am curious to hear about the paradigm cases. In your answer I would like to know the WHAT and the WHY of the coding style or syntax behavior. I don't want to start any coding style flame wars, just matter of fact scenarios where the uninitiated would get tripped up.

Copyright Notice:Content Author:「」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/1248560/is-coding-style-mostly-for-readability-or-are-there-other-factors

More about “Is coding style mostly for readability or are there other factors?” related questions

Is coding style mostly for readability or are there other factors?

I remember reading in Douglas Crockford's "Javascript the Good Parts" book that there is potential for error with blockless statements because of automatic semicolon insertion. if (condition) f...

Show Detail

gnu makefile coding style

Every time I need to touch a nontrivial makefile it takes time to adjust eyes/brain to the syntax. In attempt to make adaptation smoother I am looking for a good coding style (essentially line brea...

Show Detail

Odd coding style of IF block in PL/SQL

Where I work, I see lot's of the following type of code written in PL/SQL, IF a>b THEN NULL; ELSE c:=a*b; END IF; I find this odd because a C equivalent would look like this, if (a>b) .

Show Detail

Coding Style: Two activities with mostly same code but different content view

I have two activities that have the same code. The main difference is that they have different content views (and therefore a few different elements). What is recommended? Should I leave it like i...

Show Detail

LINQ or foreach - style/readability and speed

I have a piece of code for some validation logic, which in generalized for goes like this: private bool AllItemsAreSatisfactoryV1(IEnumerable<Source> collection) { foreach(var foo in

Show Detail

Does any style guide prefer < over > for readability?

For coding a relational expression, do any authoritative standards or style guides or field studies recommend less-than over greater-than? For example, prefer (0 &lt;= x &amp;&amp; x &lt; 1) to (x...

Show Detail

Good Haskell coding style of if/else control block?

I'm learning Haskell in the hope that it will help me get closer to functional programming. Previously, I've mostly used languages with C-like syntax, like C, Java, and D. I have a little question...

Show Detail

Monadic coding style?

I find myself writing my programs more and more in the style like this: myList .map(el =&gt; ...) .filter(_....) .map { el =&gt; ... ... } .zipWithIndex .foreach(println) Ofte..

Show Detail

Is there a verilog coding style checker or formatter?

Verilog is a unique language, compare with other programming language or description language. But it is very easy to write some buggy code if you don't follow good coding style like "Don't combine

Show Detail

if/else coding style consequences

I am a novice programmer and was in lecture one evening, we were studying the "if,else" coding section from my professor and I was curious about an aspect of it. What I was curious about was if we ...

Show Detail