Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1067499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:09:54+00:00 2026-05-16T20:09:54+00:00

I have some functions in my code that accept either an object or an

  • 0

I have some functions in my code that accept either an object or an iterable of objects as input. I was taught to use meaningful names for everything, but I am not sure how to comply here. What should I call a parameter that can a sinlge object or an iterable of objects? I have come up with two ideas, but I don’t like either of them:

  1. FooOrManyFoos – This expresses what goes on, but I could imagine that someone not used to it could have trouble understanding what it means right away
  2. param – Some generic name. This makes clear that it can be several things, but does explain nothing about what the parameter is used for.

Normally I call iterables of objects just the plural of what I would call a single object. I know this might seem a little bit compulsive, but Python is supposed to be (among others) about readability.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:09:54+00:00Added an answer on May 16, 2026 at 8:09 pm

    I have some functions in my code that accept either an object or an iterable of objects as input.

    This is a very exceptional and often very bad thing to do. It’s trivially avoidable.

    i.e., pass [foo] instead of foo when calling this function.

    The only time you can justify doing this is when (1) you have an installed base of software that expects one form (iterable or singleton) and (2) you have to expand it to support the other use case. So. You only do this when expanding an existing function that has an existing code base.

    If this is new development, Do Not Do This.

    I have come up with two ideas, but I don’t like either of them:

    [Only two?]

    FooOrManyFoos – This expresses what goes on, but I could imagine that someone not used to it could have trouble understanding what it means right away

    What? Are you saying you provide NO other documentation, and no other training? No support? No advice? Who is the “someone not used to it”? Talk to them. Don’t assume or imagine things about them.

    Also, don’t use Leading Upper Case Names.

    param – Some generic name. This makes clear that it can be several things, but does explain nothing about what the parameter is used for.

    Terrible. Never. Do. This.

    I looked in the Python library for examples. Most of the functions that do this have simple descriptions.

    http://docs.python.org/library/functions.html#isinstance

    isinstance(object, classinfo)

    They call it “classinfo” and it can be a class or a tuple of classes.

    You could do that, too.

    You must consider the common use case and the exceptions. Follow the 80/20 rule.

    1. 80% of the time, you can replace this with an iterable and not have this problem.

    2. In the remaining 20% of the cases, you have an installed base of software built around an assumption (either iterable or single item) and you need to add the other case. Don’t change the name, just change the documentation. If it used to say “foo” it still says “foo” but you make it accept an iterable of “foo’s” without making any change to the parameters. If it used to say “foo_list” or “foo_iter”, then it still says “foo_list” or “foo_iter” but it will quietly tolerate a singleton without breaking.

      • 80% of the code is the legacy (“foo” or “foo_list”)

      • 20% of the code is the new feature (“foo” can be an iterable or “foo_list” can be a single object.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code in a couple of different functions that looks something like
I have some setup code in my functions.php file that sets permalinks and adds
I'm trying to do an input that only accept digit. I can have some
I have some code that looks like this: var MyObject = function () {
I have some jQuery code that intercepts links clicked on a page: $(document).ready(function() {
Inside my .aspx I have some JSON code that looks like this: function someFunctionName()
I'd like to write a function that would have some optional code to be
I have some html5 postMessage code: window.addEventListener(message, FA.recieveMessage, false); That listener invokes this function:
I have a main function in javascript that is function a() { some code
In the process of changing some code, I have spilt some functions into multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.