[MonoDevelop] New code formatter joins line to aggressively

Oskar Berggren oskar.berggren at gmail.com
Fri Sep 11 07:30:27 EDT 2009

I was very happy to learn that MD 2.2 will include a code formatter.
This is a feature I've really missed from visual studio.

I've done some experimenting with it, and have a number of opinions:

* Apart from "Format document", there should also be a "Format
selection". The latter one would operate on the current line only, if
there is no selection.

* It joins lines way to aggressively.

For example, this manually formatted code (best viewed in monospace...):

    ICriteria criteria =
            .Add( Restrictions.Eq("Name", connectionName) );

becomes this unreadable thing:

    ICriteria criteria = session.CreateCriteria
(typeof(RegisterRequest)).CreateCriteria ("Connection").Add
(Restrictions.Eq ("Name", connectionName));

Maybe it shouldn't join lines at all. Rather, if a statement is
manually divided over several lines, it should probably remain on as
many lines with all lines except the first indented one more step than
the first line. Possibly, if it is inside parentheses then perhaps the
subsequent lines should align with the parentheses, like they did in
the MD 2.0's indentation mode:

    var recent_not_infinite_enddate =
        Restrictions.And(Restrictions.Ge("EndDate", earliestChangeTime),
                         Restrictions.Lt("EndDate", DateTime.MaxValue));

Now.... another question is: Should it wrap lines that are too long?


More information about the Monodevelop-list mailing list