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 6532561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:01:11+00:00 2026-05-25T10:01:11+00:00

Suppose I’ve a very long method chaining object.SetA(123).SetB(234).SetC(345) … what’s the best indentation? All

  • 0

Suppose I’ve a very long method chaining

object.SetA(123).SetB(234).SetC(345) ...

what’s the best indentation? All compilers supports them?

object.
   SetA(123).
   SetB(234).
   SetC(345) ...

or

object
  .SetA(123)
  .SetB(234)
  .SetC(345) ...
  • 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-25T10:01:12+00:00Added an answer on May 25, 2026 at 10:01 am

    Assuming that we’re talking about method chaining on the same object (each function retuns *this), how about:

    object.setA().setB().setC();
    object.setD().setE().setF();
    

    Long lines aren’t just bad because your screen isn’t wide enough to contain them. If that’s all there was to it, just buy a bigger monitor or reduce the font size. They’re bad because people read code one line at a time, and if you’re doing too much in one line you break their tiny little carbon-based brains.

    If all else fails, personally I’d indent it this way:

    object
        .setA()
        .setB()
        ...
    ;
    

    but I’d prefer:

    object.setA();
    object.setB();
    ...
    

    Method chaining is a way to cram more onto a line, so if we’re then going to split the lines back out again, I don’t see the advantage. Sometimes we’re forced because object is actually a temporary (result of a function call rather than a named variable) or something and we can’t take a reference to it.

    You could perhaps just let the line run off the right-hand side. It’s annoying to have to scroll sideways or to have lines wrapping, but then again it’s already annoying to have to do this in one statement, so clearly there’s some incredibly important reason.

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

Sidebar

Related Questions

Suppose I have a custom object set up in a class similar to this.
Suppose I had a query select name from tbl where dept = 123 which
Suppose you have the following object hierarchy: class Vehicle { public: virtual ~Vehicle() {}
Suppose I have a class module clsMyClass with an object as a member variable.
Suppose you're developing a software product that has periodic releases. What are the best
Suppose I want a string, say 123, to fill a given rectangle, like so:
Suppose I have an API that returns a Task as an object: private static
Suppose that I have the following python base class: class BaseClass(object): def a(): This
Suppose I have an integer array like this: {5,3,5,4,2} and I have a method
suppose you have the following method: double * myMethod(double (*f)(double[]), double *x, int size)

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.