File Exchange Pick of the Week

Our best user submissions

Code wash

Note

The file submission referenced in this post is no longer available on File Exchange.

Computers do not care about beautiful code. Anyone can write code that a computer will like. However, the challenge is to write code that both the computer and a computer programmer will like. Much of that comes from good formating. This tool is good for helping with that.

Compare the following:

a = [72 69 76 76 79 12 0 87 79 82 76 68 1]; b=32;
obsficate=1;
for i=numel(a):-1:1; a(i)=a(i)+b+floor(.5); end
if (nnz(obsficate)==2)|(obsficate==1)
char(a)
end

Then put it through codeWash to get this:

a = [72 69 76 76 79 12 0 87 79 82 76 68 1];
b = 32;
obsficate = 1;
for i=numel(a):-1:1;
   a(i)=a(i)+b+floor(0.5);
end
if (nnz(obsficate) == 2)|(obsficate == 1)
   char(a)
end

It is still horrible code, but at least it is now well formatted. I have been wanting a ‘beautify’ function added to the editor for a while now. The next time someone hands me some ugly code I will run this so that I can have a fighting chance at understanding it.

Also, as you may have noticed, I have not been selecting picks for a while. Scott has been good about doing it while I have been extra busy. I will be making a follow up video when things slow down a little around the office. Thanks.

|
  • print
  • send email

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.