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

  • Home
  • SEARCH
  • 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 6004387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:15:23+00:00 2026-05-23T01:15:23+00:00

I prefer to use long identifiers to keep my code semantically clear, but in

  • 0

I prefer to use long identifiers to keep my code semantically clear, but in the case of repeated references to the same identifier, I’d like for it to “get out of the way” in the current scope. Take this example in Python:

def define_many_mappings_1(self):
    self.define_bidirectional_parameter_mapping("status", "current_status")
    self.define_bidirectional_parameter_mapping("id", "unique_id")
    self.define_bidirectional_parameter_mapping("location", "coordinates")
    #etc...

Let’s assume that I really want to stick with this long method name, and that these arguments are always going to be hard-coded.
Implementation 1 feels wrong because most of each line is taken up with a repetition of characters. The lines are also rather long in general, and will exceed 80 characters easily when nested inside of a class definition and/or a try/except block, resulting in ugly line wrapping. Let’s try using a for loop:

def define_many_mappings_2(self):
    mappings = [("status", "current_status"),
                ("id", "unique_id"),
                ("location", "coordinates")]
    for mapping in mappings:
        self.define_parameter_mapping(*mapping)

I’m going to lump together all similar iterative techniques under the umbrella of Implementation 2, which has the improvement of separating the “unique” arguments from the “repeated” method name. However, I dislike that this has the effect of placing the arguments before the method they’re being passed into, which is confusing. I would prefer to retain the “verb followed by direct object” syntax.

I’ve found myself using the following as a compromise:

def define_many_mappings_3(self):
    d = self.define_bidirectional_parameter_mapping
    d("status", "current_status")
    d("id", "unique_id")
    d("location", "coordinates")

In Implementation 3, the long method is aliased by an extremely short “abbreviation” variable. I like this approach because it is immediately recognizable as a set of repeated method calls on first glance while having less redundant characters and much shorter lines. The drawback is the usage of an extremely short and semantically unclear identifier “d”.

What is the most readable solution? Is the usage of an “abbreviation variable” acceptable if it is explicitly assigned from an unabbreviated version in the local scope?

  • 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-23T01:15:24+00:00Added an answer on May 23, 2026 at 1:15 am

    I would go with Implementation 2, but it is a close call.

    I think #2 and #3 are equally readable. Imagine if you had 100s of mappings… Either way, I cannot tell what the code at the bottom is doing without scrolling to the top. In #2 you are giving a name to the data; in #3, you are giving a name to the function. It’s basically a wash.

    Changing the data is also a wash, since either way you just add one line in the same pattern as what is already there.

    The difference comes if you want to change what you are doing to the data. For example, say you decide to add a debug message for each mapping you define. With #2, you add a statement to the loop, and it is still easy to read. With #3, you have to create a lambda or something. Nothing wrong with lambdas — I love Lisp as much as anybody — but I think I would still find #2 easier to read and modify.

    But it is a close call, and your taste might be different.

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

Sidebar

Related Questions

I prefer to use OOP in large scale projects like the one I'm working
Do you have a default type that you prefer to use in your dealings
I prefer to keep our SSIS packages in a solution on the server, not
I'm working on an iPhone application which will use long-polling to send event notifications
In django, which should I generally prefer, and why? long template variable names, passing
I frequently use Moose to make sure my data have suitable default values, like
I prefer dark backgrounds for coding, and I've downloaded a jar file containing an
Which way do you prefer to create your forms in MVC? <% Html.Form() {
I would much prefer to do this without catching an exception in LoadXml() and
I would prefer that a console app would default to multithreaded debug. warning level

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.