10

Since we have decided that pasted code is favorable to pasted images of code, I think there's another issue to resolve: How should the code be pasted? A good examle are Greek letters. A code sprinkled with \[CurlyTheta] is very hard to read in "copy as plain text" form.

Now while I think it may be too much to ask people do this themselves every time, my question is of more concern to people with edit rights: are we encouraged to edit those posts, replacing things like \[CurlyTheta] with something like th for easier readability?

3 Answers 3

9

I'd say the chance of breaking something by accident is too big (it will happen without doubt), and most people will paste the code back to Mathematica anyway. Also, \[Alpha] is not that unreadable (I've been fine with it on SO). It's not the same as these things:

\!\(
\*SubscriptBox[\(\[PartialD]\), \(x\)]\(f[x, y]\)\)

which are truly unreadable.

I vote to leave these alone, and not edit them, unless the code is really terribly unreadable.

4
  • 1
    Personally, the \[UndirectedEdge]s in mathematica.stackexchange.com/questions/356/… drives me nuts... Commented Jan 24, 2012 at 1:07
  • 1
    @Brett Well, you're right about that. I wonder why <-> isn't produced when converting yo InputForm, after all it's accepted as input!
    – Szabolcs
    Commented Jan 24, 2012 at 1:14
  • @Szabolcs is that true? Can I edit \[UndirectedEdge] to <-> and preserve code integrity? (Side note: you can apply such a copy rule using ExportAutoReplacements in the Option Inspector -- I mention this for anyone reading.)
    – Mr.Wizard Mod
    Commented Jun 18, 2012 at 17:13
  • @Mr.Wizard Yes, in v8.
    – Szabolcs
    Commented Jun 18, 2012 at 17:47
5

Sometimes I find this kind of "coding style" in snippets

  Return[(b - a)/2 \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 1\), \(n\)]\(
\*SubscriptBox[\(weights\), \(i, 2\)]\ f[
\*FractionBox[\(a + b\), \(2\)] + 
\*FractionBox[\(b - a\), \(2\)] 
\*SubscriptBox[\(weights\), \(i, 1\)]]\)\)]];

While the following is roughly the same, and much more readable as a mathematica.stackexchange snippet:

% /. Subscript[a_, b__] :> a[[b]] // InputForm
(* ->
Return[((-a + b)*Sum[f[(a + b)/2 + ((-a + b)*weights[[i,1]])/2]*weights[[i,2]],{i, 1, n}])/2]
*)

Of course there is no problem if you have Mma at hand and copy/paste the code, but when you are reading the Q without access to the front end, decoding the <Esc>...<Esc> notation adds some neural overhead.

I think we should encourage users to use the cleaner possible code in their examples, which must be thought for posting here and not as a lazy pasting of their actual program.

3

I have no qualms at all replacing special characters, as long as it doesn't change the behavior of the code.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .