I just wanted to throw this topic out there to share how I format my flex
code and see what other people think. We all know how Flex does it by
default. But I find those long lines hard to read as code. They are
especially problematic for version control, as a change to any part of the
line looks like a change to the whole line in a difference viewer.
So, here's a fragment of my code. If you are using an email reader that
changes this email to plain text, you may lose a bit of the point of it.
<mx:HDividedBox id="historyBox"
label="Activity"
width="100%"
height="100%"
styleName="tabBox"
>
<mx:VBox
height="100%"
minWidth="240"
width="240"
>
<mx:TabNavigator id="usersViewTabNav"
height="100%"
width="100%"
change="usersViewTabChange()"
>
<mx:VDividedBox id="detailUserListTeam"
label="Teams"
width="100%"
height="100%"
>
<mx:DataGrid id="teamGrid"
dataProvider="{WAT.teams}"
height="20%"
width="100%"
minHeight="100"
verticalGridLines="false"
change="detailUserListTeamSelectionChange()"
>
<mx:Button id="editTeamsBtn"
label="Edit Teams"
click="editTeamClick()"
/>
I leave the id on the same line as the component declaration because that
way it shows up in the Outline view (why it doesn't always put the id on the
Outline view no matter what the formatting is, I have no idea).
Otherwise, I put each attribute on a single line. This means any change
shows up quite nicely in a difference viewer. I put the closing > or /> on
a line of its own for the same reason.
Unfortunately, Flex doesn't really respect this style and when working with
the property editor it can tend to rearrange it. I then have to go back in
and fix the formatting.
What I really wish is that I could somehow make Flex/Eclipse aware of how I
like to format things so that it would help me out. I also wish I could do
something like alphabetically sort the attributes (leaving the id at the
top) with a keystroke (kind of like the Organize Imports command). Would be
great to have a command that would pretty-print all the source code in the
open file.
--
Jason