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

How can code formatting be made more intuitive for newcomers?

Asked by Jan Simon on 27 Jul 2011

We suggest to apply a proper code formatting 10 times per day. Not formatted is nearly unreadable and it is actually not hard to apply it - if you know how.

How can the interface be improved to let newcomers comprehend the formatting style directly and intuitively?

2 Comments

Fangjun Jiang on 30 Jul 2011

For bring up the good topic.

Jan Simon on 15 Nov 2011

Bump.
It would save a lot of time for the editors, and increase the quality of a noticable part of the questions, if the code formatting is made easier. Beginners seem to be overstrained by the "{} Code" button and something seems to impede, that they read the formatting instructions.

Jan Simon

Products

No products are associated with this question.

5 Answers

Answer by Image Analyst on 30 Jul 2011
Accepted answer

I'd like to see that too. I post code all the time and I hate it that when the code has a blank line in there (to separate distinct sections of code) that I have to highlight each and every section and click the code icon. What a pain!

2 Comments

Walter Roberson on 30 Jul 2011

Which part would you like to see "too" ?

When I post code, I just select the entire section of code and click on the code button, rather than doing it paragraph by paragraph.

Image Analyst on 30 Jul 2011

What I'd like to see too is "code formatting be made more intuitive."

Image Analyst
Answer by Walter Roberson on 27 Jul 2011

If "code" mode were made the default, with a way to switch to paragraph mode (that supported character-level markup) then there might be less problem, perhaps.

5 Comments

Fangjun Jiang on 30 Jul 2011

I can live with copy and paste the hyper-link. Other fancy formatting is rarely used.

Fangjun Jiang on 30 Jul 2011

Embedded graphics is nice. I remember seeing a few. I have not figured out how to use it my self. If that can be done, why users are still asking how to post figures on other website?

Jan Simon on 30 Jul 2011

@Jiang: Exactly - *all* formatting is too rarely used, because it seems to be too complicated.
A graphic can be embedded by using << and >> around the link. See my own answer.

Walter Roberson
Answer by Jan Simon on 30 Jul 2011

What about a more pushy design?

Original:

 

New - exaggerated:

With a link to a best-of how to ask a good question, get help on homework questions and TUTORIAL: how to ask a question

1 Comment

Jan Simon on 30 Jul 2011

Or a text description:
"Matlab code has two leading spaces"
"Include links in < and >"
"Include URLs to graphics in << and >>"
"Enumerations start with #"
"Lists start with *"

Jan Simon
Answer by Image Analyst on 30 Jul 2011

Walter, here is what you get if you paste in 5 lines of code with the third line of code being a blank line between the 2nd and 4th line of code, and then highlight all 5 lines and click the "code" icon. In the "markup" box my clc is on a separate line below this, while in the Preview box it's on the same line and not formatted as code even though I highlighted all 5 lines and clicked the code icon: clc; close all;

workspace;
clear;

2 Comments

Walter Roberson on 30 Jul 2011

You need an empty line before the code. Which is the case for all of the paragraph-level markups. Self-consistent, but I for one would not complain if the Code button added an empty line if the previous line was not already empty.

Image Analyst on 30 Jul 2011

OK that works, as long as you have the blank line first and start right before the first character of the code (unlike using control R and control T in MATLAB to comment/uncomment code where it will act upon the whole line.) Thanks.

Image Analyst
Answer by Daniel on 15 Nov 2011

Maybe the question is wrong. I think a better question is why is unformatted code so unreadable? I cannot believe that there isn't a better comprise between the readability of text and the readability of code without any need to apply formatting. Sure this might mean that getting optimal formatting is harder (e.g., you might need to mark all paragraphs as either text or code). I would take this added inconvenience if it means the default (i.e., unformatted) is readable for both code and text.

0 Comments

Daniel

Contact us