All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ed Bartosh <ed.bartosh@linux.intel.com>
To: Andreas Reichel <Andreas.Reichel@tngtech.com>
Cc: Jan Kiszka <jan.kiszka@siemens.com>,
	Andreas Reichel <andreas.reichel.ext@siemens.com>,
	Daniel Wagner <daniel.wagner@siemens.com>,
	openembedded-core@lists.openembedded.org
Subject: Re: [wic patch 5/5] wic: Use enum like dicts for string constants
Date: Wed, 3 May 2017 15:18:02 +0300	[thread overview]
Message-ID: <20170503121802.GA21326@linux.intel.com> (raw)
In-Reply-To: <20170503084745.GB1431@tng>

On Wed, May 03, 2017 at 10:47:45AM +0200, Andreas Reichel wrote:
> On Tue, May 02, 2017 at 04:36:22PM +0300, Ed Bartosh wrote:
> > On Fri, Apr 21, 2017 at 02:11:45PM +0200, Andreas J. Reichel wrote:
> > > To increase code maintainability, use dictionaries
> > > as enum-like container for parameter string comparisons.
> > > 
> > > Signed-off-by: Andreas Reichel <andreas.reichel.ext@siemens.com>
> > > Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> > > Signed-off-by: Daniel Wagner <daniel.wagner@siemens.com>
> > > 
> > > ---
> > >  scripts/lib/wic/engine.py | 16 +++++++++++++---
> > >  1 file changed, 13 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
> > > index 647358287f..1428a73ba8 100644
> > > --- a/scripts/lib/wic/engine.py
> > > +++ b/scripts/lib/wic/engine.py
> > > @@ -35,6 +35,16 @@ from wic import WicError
> > >  from wic.pluginbase import PluginMgr
> > >  from wic.utils.misc import get_bitbake_var
> > >  
> > > +class StrEnum(dict):
> > > +    __getattr__ = dict.get
> > > +
> > > +ListType = StrEnum({
> > > +    'LIST_IMAGES': "images",
> > > +    'LIST_SRC_PLUGINS': "source-plugins" })
> > > +
> > > +HelpArg = StrEnum({
> > > +    'HELP': "help" })
> > > +
> > >  logger = logging.getLogger('wic')
> > >  
> > >  def verify_build_env():
> > > @@ -204,14 +214,14 @@ def wic_list(args, scripts_path):
> > >      if args.list_type is None:
> > >          return False
> > >  
> > > -    if args.list_type == "images":
> > > +    if args.list_type == ListType.LIST_IMAGES:
> > >  
> > >          list_canned_images(scripts_path)
> > >          return True
> > > -    elif args.list_type == "source-plugins":
> > > +    elif args.list_type == ListType.LIST_SRC_PLUGINS:
> > >          list_source_plugins()
> > >          return True
> > > -    elif len(args.help_for) == 1 and args.help_for[0] == 'help':
> > > +    elif len(args.help_for) == 1 and args.help_for[0] == HelpArg.HELP:
> > >          wks_file = args.list_type
> > >          fullpath = find_canned_image(scripts_path, wks_file)
> > >          if not fullpath:
> > 
> > I'm not sure if this increases maintainability, but it definitely increases code complexity and
> > decreases readability. Can you explain the idea in a bit more detailed way?
> > 
> In general, if string constants are used as keys, it is better do define them as
> constants. Maintainability increases because if you have to change them,
> you only change them in one place. You have a central place for this
> definition and not scattered them all over the code. That's the idea.
>

Not sure I'm convinced. From my point of view this patch changes quite
simple and readable code to something more complex and less readable for
no visible reason.

If I have to change 'images' or 'source-plugins'(why would I want to do that?)
I'd just go and change them in one place as they're not used anywhere else.

--
Regards,
Ed


  reply	other threads:[~2017-05-03 12:31 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-21 12:11 [wic patch 0/5] Add option to wic and use argparse Andreas J. Reichel
2017-04-21 12:11 ` [wic patch 1/5] wic: Catch errors during image files clean-up Andreas J. Reichel
2017-05-02 12:56   ` Ed Bartosh
2017-05-03  8:45     ` Andreas Reichel
2017-05-03 10:32       ` Ed Bartosh
2017-04-21 12:11 ` [wic patch 2/5] wic: Use argparse instead of optparse Andreas J. Reichel
2017-04-23 19:58   ` Burton, Ross
2017-04-26 10:34     ` Andreas Reichel
2017-04-26 13:03       ` Burton, Ross
2017-04-21 12:11 ` [wic patch 3/5] wic: Add missing text to usage and help strings Andreas J. Reichel
2017-04-21 12:11 ` [wic patch 4/5] wic: Add option to keep partition images Andreas J. Reichel
2017-04-21 12:11 ` [wic patch 5/5] wic: Use enum like dicts for string constants Andreas J. Reichel
2017-05-02 13:36   ` Ed Bartosh
2017-05-03  8:47     ` Andreas Reichel
2017-05-03 12:18       ` Ed Bartosh [this message]
2017-05-02 14:37 ` [wic patch 0/5] Add option to wic and use argparse Ed Bartosh
2017-05-03  8:49   ` Andreas Reichel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170503121802.GA21326@linux.intel.com \
    --to=ed.bartosh@linux.intel.com \
    --cc=Andreas.Reichel@tngtech.com \
    --cc=andreas.reichel.ext@siemens.com \
    --cc=daniel.wagner@siemens.com \
    --cc=jan.kiszka@siemens.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.