DZone
Performance Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Performance Zone > PR Review: Avoid Too Many Parameters

PR Review: Avoid Too Many Parameters

Check out two sections of code that raised some flags while the author was doing a code review and learn what you should do to fix these problems.

Oren Eini user avatar by
Oren Eini
·
Jun. 25, 17 · Performance Zone · Review
Like (1)
Save
Tweet
1.74K Views

Join the DZone community and get the full member experience.

Join For Free

During a code review, I ran into these two sections, which raised some flags. Can you tell why?

image

image

The problem with this type of code is two-fold. First, we add optional parameters to reduce the number of breaking changes we have. The problem with this is that we already have parameters on the call, and eventually, you’ll get to something like this:

image

...which is the queen of the optional parameters method, and you can probably guess how it looks internally.

In the first case, we can add the new optional parameter to the options variable that we are already sending this method. This way, we don’t have to worry about breaking changes, and we already have a way to setup options, determine defaults, etc.

In the second case, we are passing two bools to the method, and there isn’t a preexisting parameters object. Instead of creating one, we can use a Flags enum, whose bits we can set to determine what exactly the behavior of this method should be. That is generally much easier to maintain in the long run.

Object (computer science)

Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Modern REST API Design Principles and Rules
  • Migrating From Heroku To Render
  • How to Upload/Download a File to and From the Server?
  • AWS Serverless Lambda Resiliency: Part 2

Comments

Performance Partner Resources

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo