Doug's MATLAB Video Tutorials

October 22nd, 2010

Formatting code for readability

The use of whitespace can make your code more pleasant to read. This is not just a nicety, it actually makes it easier to see the structure of your code and makes it more clear where code breaks the established patterns to help find bugs (like copy and paste bugs). Though not presented in this video, Scott pointed out that comments and cell dividers are also excellent ways to format code.

One Response to “Formatting code for readability”

  1. the cyclist replied on :

    I have used whitespace in this way for a long time, and I teach rookie developers to do the same. Another advantage to coding in this way is that when portions of code that are logically parallel are written in a visually parallel way, it helps avoid simple typos and other bugginess.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


MathWorks

Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.

Doug's picture

These postings are the author's and don't necessarily represent the opinions of The MathWorks.