One thing that I like about the more recent versions of the Mathematica front-end is that I think it does a good job indenting code. The language's functional nature, in my experience, leads to a lot of nesting, and the small indentation works well for this pupose. However, for some reason, the rules used for Wolfram Workbench (at least as of version 2.0) are evidently completely different, and the results look much worse. This can be helped somewhat by adjusting editor settings for Eclipse, but it still needs a lot of work. For example, here's a really silly approach for determining whether an integer is even or not, which I picked because it has a lot of indentation, as it's formatted in a Mathematica notebook:
Module[{even, odd, withoutLimit},
even[0] = True;
odd[0] = False;
even[n_Integer] := odd[n - 1];
odd[n_Integer] := even[n - 1];
Attributes[withoutLimit] = {HoldFirst};
withoutLimit[expr_] :=
Block[{$IterationLimit = Infinity},
expr];
With[{test =
Function[n,
n >= 0]},
Pillsy`EvenQ[n_Integer] := withoutLimit@even[n] /; test[n];
Pillsy`EvenQ[n_Integer] := even[-n];
Pillsy`OddQ[n_Integer] := withoutLimit@odd[n] /; test[n];
Pillsy`OddQ[n_Integer] := odd[-n]]];
I find this quite readable. Here's the same code, copied into Workbench and formatted using its automatic source formatting (I added some whitespace between logically related definitions, which I'm used to doing manually):
Module[ {even, odd, withoutLimit},
even[0] = True;
odd[0] = False;
even[n_Integer] :=
odd[n - 1];
odd[n_Integer] :=
even[n - 1];
Attributes[withoutLimit] = {HoldFirst};
withoutLimit[expr_] :=
Block[ {$IterationLimit = Infinity},
expr
];
With[ {test =
Function[n,
n >= 0]},
Pillsy`EvenQ[n_Integer] :=
withoutLimit@even[n] /; test[n];
Pillsy`EvenQ[n_Integer] :=
even[-n];
Pillsy`OddQ[n_Integer] :=
withoutLimit@odd[n] /; test[n];
Pillsy`OddQ[n_Integer] :=
odd[-n]
]
];
I'd like to make the second example look a lot more like the first example. In particular, the insistance that trailing square brackets from With
, Module
and Block
should get lines all to themselves, like they're curly braces from C, makes me crazy.