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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:33:11+00:00 2026-05-26T18:33:11+00:00

I have a question that I cannot answer myself, but it seems like a

  • 0

I have a question that I cannot answer myself, but it seems like a fundamentally good question to clear up:

Why do some languages restrict the data returned from a function to a single item?

Is this serving some benefit? Or is it a practice brought over from Maths?

An example being (in Scala):

def login(username: String, password: String): User

If I wanted to return multiple items I cannot say it in the same manner as I just did for the input arguments (now entering imaginary Scala land)

def login(username: String, password: String): (User, Context, String)

Or even with named data returned:

def login(username: String, password: String): (user: User, context: Context, serverMessage: String)
  • 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-26T18:33:12+00:00Added an answer on May 26, 2026 at 6:33 pm

    There is no relationship: as observed, an arbitrary number of values can be returned, even if they must be “packaged” into a single value.

    Imagine a language that can only accept a single tuple and can only return a single tuple from a function (the tuples can be any size). These functions then resemble math function transforming a vector from one space to another.

    However, some reasons why it might be so:

    1. Most functions only return one value, which may be a collection of values (object, sequence, etc.) Decompositions of the single value is supported in a number of languages, even though “only one value is returned”.
    2. The calling conventions and signatures are simpler: there is no special case/overhead to signal that n-values are being returned: there is no need to use part of the stack to return multiple values, a single register will do.
    3. The need to fit in with the target architecture: earlier, especially lower-level languages, were heavily influenced by the computer architecture. In the case of Scala, for instance, it must work on the JVM.
    4. It’s just how the language was designed. Many (most?) languages borrow heavily — syntax and/or methodologies — from existing languages. Sometimes this is good, sometimes it is not so good. C# appeased Java appeased C++ appeased C, for instance: it’s all about the market share.
    5. It Just Works.

    Even while “returning only one value”, programming languages already have different ways of dealing with it. As noted in the post, some languages allow decomposition (the tuple returned as “decomposed” into it’s two values during an assignment):

    def multiMath (i):
      return (i + i, i * i)
    
    double, squared = multiMath(4)
    # doubled is 8
    # squared is 16
    

    Additionally, other languages like C# which lacks decomposition, allow pass-by-reference (or emulate it in with mutation of an object):

    void multiMath (int a, out int doubled, out int squared) {
      doubled = a + a;
      squared = a * a;
    }
    
    int d, s;
    multiMath(4, out d, out s);
    // d is now 8
    // s is now 16
    

    And, of course… 😉

    class ANewClassForThisFunctionsReturn {
      ...
    }
    

    There are likely more methods I am not aware of.

    Happy coding.

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

Sidebar

Related Questions

I have a relatively simple question that I cannot seem to find the answer
A question that seems to have quite a few options for Python, but none
I have a question that is probably very simple, but I cannot find an
I did a lot of reading but I cannot answer one question I have
I would have another question I cannot find answer on. I know that the
I have a very simple question but cannot find a simple answer. I have
HI, I have a question but cannot find the answer for a long time,
I have a really simple question that I cannot find a straightforward answer for.
I have a question that's so simple I cannot believe I can't answer it
I have a question that I cannot find an answer. I'm constructing a very

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.