Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there excessive use of whitespaces in expressions in most sample code? [closed]

A statement that could be written as:

foo=(bar*5)+baz;

is usually written in sample code (documentation, tutorials etc) as:

foo = ( bar * 5 ) + baz;

This appears to require extra work and seems counter-productive to me. Is there a rational reason for this? Is this a good coding practice, or just for sample code?

(The reason I ask this is to make sure my coding style is right, and understand why most code I see online is written like this).

like image 863
Shailesh Tainwala Avatar asked Nov 27 '22 01:11

Shailesh Tainwala


1 Answers

I don't put spaces after ( or before ), but I know people that do; other than that it's how I would write it:

foo = (bar * 5) + baz;

I think it's easier to read, and about the tiniest amount of "extra work" you could possibly create. I used to code without much spacing and now I look back and think it looks terrible. There is no "right" coding style though; if it's your project format the source code however you want

like image 141
Michael Mrozek Avatar answered Feb 15 '23 07:02

Michael Mrozek