Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Is code formatting still too complicated

Asked by Jan Simon on 12 Jul 2012

The formatting of code in the forum is easy and improves the readability. Newcomers in the forum seems to have problems to apply it, although the new layout has added further instructions. Do you have the impression that the number of unformatted code has increased or decreased?

How could new users instructed more efficiently to format code?

I know, this question is as old as the forum itself and has been asked multiple times already. But I still do not loose the hope that there are new ideas.

I do not think that badly formatted code is enough to flag a question to be deleted. What about offering 1 reputation point, if a new user is instructed personally to follow the forum standards? Or adding a standard comment like "Please format your..." triggered by a button?

4 Comments

Jan Simon on 12 Jul 2012

A good answer, thanks, Albert. Please post it in the answers section, not as comment, such that I can vote it. You see there are even more conventions besides the code formatting... ;-)

per isakson on 12 Jul 2012

Formatting, does that have something to do with markup ;-)

Jan Simon on 12 Jul 2012

Almost, Per, it is more makeup.

Jan Simon

Products

No products are associated with this question.

2 Answers

Answer by Albert Yam on 12 Jul 2012
Accepted answer

For my transition, it had a lot to do with figuring out that you need to put things not only on different lines but to also add another new line before AND after the code. I have caught myself just highlighting some code, hitting the {}Code button, and nothing happens in the Preview.

For some forum users, (perhaps such as yourself) this might be second nature, but for new users, the {}Code button might not seem to do anything.

Suggestion would be to add the new lines above and below the highlighted sections when hitting the {}Code button.

Edit: Started off not having a suggestion (answer to the question), so thought to just comment, but ended up with a suggestion after writing it. Yep, perpetual student of Matlab.

1 Comment

Jan Simon on 12 Jul 2012

Even describing your experiences with the "{} Code" button is valuable already, thanks. It should be easy to add the empty lines automatically. Even a test for already existing blank lines is not required, because the number of empty lines does not matter.

Albert Yam
Answer by Ryan on 12 Jul 2012

I would recommend implementing an "open code" and "close code" tag system similar to the other features in the comment section (**,_ _,< >, etc). The idea of an opening and closing tag is something that most users should be comfortable with and it creates more uniformity in the formatting markup. I wouldn't be opposed to do it bb-style either: [code]LOTS OF FUN MATLAB THINGS![/code].

4 Comments

per isakson on 12 Jul 2012

The markup here in Answer is a subset of "Markup for Publishing MATLAB Files", which I think is a good thing.

Ryan on 12 Jul 2012

I did not realize that. The uniformity is certainly a good thing but the annoyingness of the code mark-up should be fixed. For example...

Output from just hitting the {}Code button:

if true
  % code
end % Note the "if" and "end" are indented 2 spaces
% This line of code has no indentation
% This line has 1 space
% This line has 2 spaces
 % This line has 3 spaces!

New block of code:

 % This line has the 1 required space to initiate code but I cannot align this to the left hand side as above
% But now I can align the next line of code
Jan Simon on 14 Jul 2012

Another example:

if x == 1    % 2 leading spaces
  disp(x);   % 4 leading spaces, empty line follows
    disp(1)    % 4 leading spaces
  end          % 2 leading spaces

Empty liens are helpful to separate blocks of code and to increase the readability. While Per is right with the formatting is based on "Markup for Publishing MATLAB Files", I think, that optical penalties for empty lines are a bad idea.

Ryan

Contact us