[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [stellation-res] Audit: overly complicated expression
|
On Wed, Sep 04, 2002 at 06:11:45AM -0400, Jonathan Gossage wrote:
>
>
> > >-----Original Message-----
> > >From: stellation-res-admin@xxxxxxxxxxxxxxx
> > >[mailto:stellation-res-admin@xxxxxxxxxxxxxxx]On Behalf Of Florin Iucha
> > >Sent: September 4, 2002 12:23 AM
> > >To: stellation
> > >Subject: [stellation-res] Audit: overly complicated expression
> > >
> > >
> > >org.eclipse.stellation.workspace.List#listVersions contains the
> > >following snippet:
> > >
> > > String branchName =
> > > getArguments().size() > 0 ? getArguments().remove(0)
> > > : getWorkspace().getProject() != null ?
> > >getWorkspace().getProject().getBranchName()
> > > : null;
> > >
> > > if (branchName==null) branchName = "main";
> > >
> > >Personally I find ?: expressions where the alternatives are something
> > >other than constants or literals hard to parse. When I scan code my eyes
> > >get "stuck" to that expression...
> > >
> > >I think this should be reworked as:
> > >
> > > String branchName = "main";
> > > if (getArguments().size() > 0)
> > > {
> > > branchName = getArguments().remove(0);
> > > }
> > > else if (getWorkspace().getProject() != null)
> > > {
> > > branchName = getWorkspace().getProject().getBranchName();
> > > }
> > >
> > >florin
> > >
>
> An alternative formatting using conditionals is:
>
> String branchName =
> (getArguments().size() > 0) ? getArguments().remove(0)
> : ((getWorkspace().getProject() != NULL)
> ?
> getWorkspace().getProject().getBranchName()
> : null);
>
> The guidelines that enhance readibility and reliability are
> a) Enclose the condifional in parentheses to avoid tripping over operator
> precedence.
> b) Align the two action clauses for each conditional under each other.
> c) Enclose entire nested conditionals in parentheses to avoid possible
> problems with operator precedence.
> d) Indent nested conditionals.
e) Limit the line length to 78 characters.
I have weak eyes and an aging laptop so I use vim sometimes instead of eclipse.
florin
--
"If it's not broken, let's fix it till it is."
41A9 2BDE 8E11 F1C5 87A6 03EE 34B3 E075 3B90 DFE4
Attachment:
pgpchu81wtLUI.pgp
Description: PGP signature