I think the point is whitespace is good. Well, good to some extent. Gosh, like whitespace, water is good for me, or so my doctor says. But too much water, and it can kill a person. To extend the simile, some of us need more water than others.
So, yes, whitespace is good to the extent it makes your code easier to read. Tightly packed code is difficult to read, especially if it is complicated code. Your example however, overdoes it for me.
scDSI (:, theta+1) = scRadius * [ cosd(theta); sind(theta); 0.0 ]
I prefer to use some white space, but NEVER between a function and the parens in a function call. So I would eliminate the first blank you had in there, and maybe a few more. I'll usually have space between operators and their operands. So for me, + and - deserve spaces around them. I tend not to use whitespace around * and ^ operators.
scDSI(:,theta+1) = scRadius*[cosd(theta); sind(theta); 0.0]
Anyway, you were inconsistent! If you want a space after scDSI, then why not want to put one after the calls to sind and cosd? Of course, that screws up the parser. Remember that when you use whitespace it is also the equivalent of a comma. So you might also cause confusion by too much whitespace. How should this next line be interpreted?
X = [ cosd (1:10) ];
Error using cosd
Not enough input arguments.
Yes, MATLAB gets upset there. So my point is, for consistency, whitespace between a function and the paren that follows it is a bad idea, because it may SOMETIMES be interpreted incorrectly.
temp2=[13.796, 13.863, 13. 865, 13.893, 13.881];
Clearly there is a typo in the line. It might better have been written as:
temp2=[13.796, 13.863, 13.865, 13.893, 13.881];
But arguably, the typo would have been even easier to see if no whitespace at all was inserted!
temp2=[13.796,13.863,13. 865,13.893,13.881];
WHOOPS! To me, that seems a clear typo now.
Whitespace is good. But don't overdo it. And recognize that everyone has a different tolerance for whitespace. Just like comments in code, and in a function header. Personally, I like them. I think more of them are better than less. But some people think I overdo it, that I write too much, too complete help. Either way, it is not worth getting upset over because we need to recognize that everyone is different, and has different programming styles.
2 Comments
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/169406-not-so-rhetorical-question-why-the-common-practice-of-writing-lines-of-code-without-white-space#comment_259965
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/169406-not-so-rhetorical-question-why-the-common-practice-of-writing-lines-of-code-without-white-space#comment_259965
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/169406-not-so-rhetorical-question-why-the-common-practice-of-writing-lines-of-code-without-white-space#comment_259983
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/169406-not-so-rhetorical-question-why-the-common-practice-of-writing-lines-of-code-without-white-space#comment_259983
Sign in to comment.