Reddit Reddit reviews The Elements of Matlab Style

We found 2 Reddit comments about The Elements of Matlab Style. Here are the top ones, ranked by their Reddit score.

Computers & Technology
Books
The Elements of Matlab Style
Used Book in Good Condition
Check price on Amazon

2 Reddit comments about The Elements of Matlab Style:

u/angrmgmt00 · 14 pointsr/matlab

Exception handling is vital in code that you intend to be used by others. This is true in any language. The old paradigm of "garbage in, garbage out" is dead for 1-2 decades now, when it comes to the user experience. Input validation is a minimum requirement, and try...catch is a good solution to exception handling.

Now that you're using MATLAB professionally, if your office has a house style then follow it as best you can, but if not, or if you're looking for more, check out Richard K. Johnson's Elements of MATLAB Style. You can get it on the File Exchange as a PDF, or you can buy it (here's one on Amazon, you can try to find it elsewhere if you want a copy).

Here's what he has to say about handling errors:

> Both data and code are potential error sources. Write defensive code to check for errors early and often. Try to provide a graceful way to deal with errors. In general, errors should be caught in low-level routines and fixed or passed on to higher-level routines for resolution. A useful tool for protection against error conditions is the try catch construct:

try
thisSample = data(iSample);
catch IndexError
index = min(iSample, nSamples);
thisSample = data(index);
end

> Another line of defense is to use properly ordered expressions in if statements so that evaluation short circuiting can avoid evaluation of expressions that will trigger an error:

if exist('a') && ~isempty(a)
:
end

Your code is only "cluttered" if its intent is not apparent. The try...catch block signals a very clear intention to handle potential errors gracefully, and even points out what types of errors might occur. That's very good code in my book - and in Johnson's!

u/AndreaonReddit · 1 pointr/ItalyInformatica

Esatto! Non sapevo si chiamassero style guide ma è sicuramente una delle cose che cerco.

Una rapida ricerca mi ha portato a questo sito e questo libro

Alla fine farò un update della domanda per tenere tutto in archivio