Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[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

-- 

"If it's not broken, let's fix it till it is."

41A9 2BDE 8E11 F1C5 87A6  03EE 34B3 E075 3B90 DFE4

Attachment: pgpSprYx5HupJ.pgp
Description: PGP signature


Back to the top