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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:19:04+00:00 2026-06-17T18:19:04+00:00

This is not a homework question. If I were to describe the exact differences

  • 0

This is not a homework question.

If I were to describe the exact differences between the following two methods and their use in the caller, how would I do so?

Method 1:

public void WriteSpace(int numSpaces) {
        if (numSpaces <= 0) return;
        for (var x = 0; x < numSpaces; x++) {
            Response.Write(" ");
        }
    }

Method 2:

public String WriteSpaceReturn(int numSpaces) {
        var space = "";
        if (numSpaces <= 0) return space;
        for (var x = 0; x < numSpaces; x++) {
            space += " ";
        }
        return space;
    }

Caller:

WriteSpace(4); //1
Response.Write(WriteSpaceReturn(4)); //2

The end result is the same from both. So I realize obviously that the first method does not return a value to the caller whereas the second does, but beyond that, how else would I describe these?

Is there a difference in atomicity between the first & second methods? Scope? Blocking? Is there a name for the fact that the first method writes output inside the method, whereas the second lets the caller do that? If these were writing significant amounts of data, would one be preferred to the other? I suspect since the first is making a call to Response.Write for each character, it would be slower?

  • 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-06-17T18:19:05+00:00Added an answer on June 17, 2026 at 6:19 pm

    Main difference in terms of performance: the second version of the code uses string concatenation in a loop, which is inefficient. I would hope that Response.Write would be more efficient than that.

    Main difference in terms of encapsulation: the second form is a pure method – it has no side-effects. This makes it easier to test in isolation, and in this particular case makes it easier to use in multiple situations.

    That’s not to say the second version is better for being pure, necessarily – it depends on the context.

    (In both cases you should remove the redundant check for numSpaces being non-positive.)

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

Sidebar

Related Questions

I'm trying to solve this problem, its not a homework question, its just code
This IS NOT a Homework question! While building my current student database project I
This is NOT a homework question, actually I am doing this for fun. Here
Firstly this is not a homework question. I am practicing my knowledge on java.
This is not a homework question, just something at work that's bugging me. I'm
Yes, this will be a homework (I am self-learning not for university) question but
This is not a homework question, rather an exam study guide question. What is
(This is NOT a homework help question) I was asked by my professor to
This is not homework, just a question about my code (I'm learning C++). I
This is not a homework question, but rather my intention to know if this

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.