Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [return-type]

The tag has no usage guidance.

7
votes
2answers
363 views

Class that returns multiple unrelated values, are there better way to accomplish this?

I have a "tracker" class. This class tracks objects from a given input image. But in addition to this, there is another parameter that corresponds to a value used in generating the image. The ...
0
votes
1answer
83 views

C# Unit Testing: Mock a Return Type

What is the best way to Mock a return type if we don't care about the actual state of the object. For example, I am Mocking a method whose return type is: IEnumerable<Document> Now, I can add ...
3
votes
2answers
138 views

Callback pattern - return value confusion

I have a ConstraintsResolver class which resolves a queue of Constraints. This is done when a ConstraintsResolver object calls meetConstraint() on a Constraint one. Most of meetConstraint() ...
2
votes
3answers
289 views

In languages without exception-handling, should error codes be returned from the function or in function parameters?

I'm writing a CSV parsing library in C and am considering whether to express error codes as return values or as parameters passed by reference. For example, here are the signatures for the function ...
6
votes
3answers
857 views

What do you need Covariant Return Types for?

In this article, it is written that in C# 8.0 new feature of convariant return type will be included as the community asking for this feature for quite a long time. Can anybody explain why and when ...
45
votes
6answers
14k views

Why do many functions that return structures in C, actually return pointers to structures?

What is the advantage of returning a pointer to a structure as opposed to returning the whole structure in the return statement of the function? I am talking about functions like fopen and other low ...
52
votes
9answers
21k views

Why does Java have `void` methods?

Does / why does Java need to have void methods? Reference: Any method declared void doesn't return a value. As far as I can think, every use of void would be better served by returning a status ...
1
vote
3answers
5k views

Converting Method to Return Generic Type

I would like to ask how to convert a method so that it can return any type depending on what happens within it. What I have is the start of an application which will visit a number of webpages (and ...
1
vote
2answers
118 views

Should I return true in a method that casts null from one object type to another?

I'm writing a very simple extension method that attempts to cast objects from one type to another. The intent of having this method is very similar to Int32.TryParse(string, out int), which allows the ...
2
votes
1answer
219 views

In a JavaScript method signature what is meant by a return type of `typeof blahBlahBlah`?

I've seen an API list methods with both of the following signatures: methodA(...) : ReturnType methodB(...) : typeof ReturnType I understand the first but not the second. My question comes ...
0
votes
0answers
266 views

Difference between RAISE and RETURN HTTPResponse in bottle framwork

I am using Bottle framework to implement API's. There is code return before I started, and they use from bottle import HTTPResponse @api.get('/some/api/url') def some_method(...): ... ... ...
2
votes
3answers
2k views

Difference between passing by values/address and returning a values through functions?

According to a book I read you can pass variables from one function to another by passing by value/address. When you pass by address it will no longer preserve the variable if it is changed in a ...
25
votes
7answers
4k views

How to return warnings alongside result of calculation to caller of a Java method? [duplicate]

I have a class, lets call it Calculator, with a method like this: public double[] performCalculation(double[] someInData) This method can generate a number of non fatal warnings (represented as an ...
-3
votes
1answer
2k views

Is it possible for $this to return a __construct?

I am currently working on my PHP skills and at the moment I'm working with classes. What I want to do is to create a class for which I can echo the object. I have the following example: class ...
3
votes
1answer
103 views

Within an interface specified by a core component, should it request IReadOnlyCollection or IEnumerable?

In thinking about the principle of "be conservative in what you send and liberal in what you accept", I generally try to make my methods receive IEnumerable parameters, but emit a IReadOnlyCollection (...
-1
votes
2answers
154 views

“Separate Query from Modifier” and return values [closed]

I've heard it said that you should keep query and modifier functions separate from one another, and I agree with the sentiment. When trying to apply it, I often run into two issues/questions: What, ...
4
votes
1answer
1k views

Lambda Return Type Inference

Writing my own JVM compiler, I am facing a giant problem that I am desperately unable to solve: Lambda Return Type Inference 1. Overview of the compiler lifecycle More specifically, the order in ...
2
votes
2answers
335 views

Lesser of two evils regarding return types

I'm implementing a system in PHP where values are represented with objects that implement an Amount interface. I'm building two different implementations of this interface, one using a simple integer ...
3
votes
4answers
2k views

Quit a program in main or in function?

Lets say I have a void method/function to check the arguments of the program: void check(int argc, String argv){ //some irrelevant code } In this function I have some checks to validate the ...
30
votes
7answers
6k views

Should I validate a method call's return value even if I know that the method can't return bad input?

I'm wondering if I should defend against a method call's return value by validating that they meet my expectations even if I know that the method I'm calling will meet such expectations. GIVEN User ...
5
votes
2answers
756 views

Using subroutines to return values?

I'm currently learning FORTRAN (I am familiar with MatLab) and I am very confused about the point of subroutines. Why would anyone use them as opposed to functions. Also, how is it that they can ...
-1
votes
1answer
359 views

What's the returning a value in Java?

public void warning(){ System.out.println("Watch out!"); } public void warning(){ System.out.println("Watch out!"); return; } We must use "return" statement with void methods. Bot of ...
4
votes
1answer
1k views

Should I declare the most specific type as return type of method?

In Android I can put only ArrayList of Parcelable objects in Intent: Intent putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value); I can't put in there a List<? ...
4
votes
2answers
16k views

Java: how can I make the return type, of an inherited method in a subclass, the same as the subclass?

I am rather inexperience in Java, and I'm having a problem in forming a subclass of a class I have created. The class I have made, called Vector2D, contains methods, such as add(Vector2D addend), that ...
8
votes
4answers
9k views

When should a method of a class return the same instance after modifying itself?

I have a class that has three methods A(), B() and C(). Those methods modify the own instance. While the methods have to return an instance when the instance is a separate copy (just as Clone()), I ...
1
vote
3answers
7k views

Make Return Type an Interface - Problem with Initialization

I would like to make the return type of my method an interface rather than a class for similar reasons stated in c# List or IList, however I am having trouble figuring out how to initialize the ...
1
vote
2answers
207 views

Pros and cons for choosing between different return types

This is in context of a client-server architecture, although I don't think the architectural setting is needed to put up the problem. I have a function whose output can be classified into different ...
33
votes
9answers
7k views

How to name a method that both performs a task and returns a boolean as a status?

If there is a method bool DoStuff() { try { // doing stuff... return true; } catch (SomeSpecificException ex) { return false; } } should it rather be called ...
3
votes
1answer
239 views

For instance methods, would always returning self or this, instead of using a void return type, be a clean coding style? [closed]

I just came across this article, and in particular, this answer. Essentially they're talking about returning self from instance methods to allow for method chaining. That being said, one of the ...
0
votes
1answer
203 views

If a variable containing a function gave the function's return instead of a reference to the function, what would an array of functions return? [closed]

I'm creating a prototype scripting language similar to something like Javascript. In my language, every single reference to a variable is actually a function call (a getter function), whether it has ...
2
votes
3answers
1k views

What's the best way to retrieve a value and a status [closed]

Given that all else is equal, and there are no coding standards defining the best approach, what would be the recommended way in C++ to check that a value exists and return it if it does? For ...
5
votes
2answers
4k views

Why a function returning by address can not be a lvalue?

Why is it not possible to set a function returning an address while it is possible to set a function that returns a reference. int* returnByAddress() { int x = 20; return &x; } int& ...
4
votes
1answer
7k views

Return values for CRUD methods?

I'm writing a basic web API in Java that does what almost all others do: take input, validate it, then do CRUD operations on the DB. I've written several APIs before, and I've pretty much already ...
5
votes
2answers
3k views

Should I return Collection or ImmutableCollection from a method?

When writing an API in Java, returning an immutable collection of some sort, I've got the option of returning Collection (or List, Map, etc) from the method, or guava's ImmutableCollection (or ...
5
votes
3answers
1k views

Intersection of geometric entities

I was trying to design a small C++ geometric API for learning purposes, but came across a problem when dealing with intersections of geometric entities. For example, the intersection of a line and a ...
3
votes
6answers
498 views

use areFoo or isFoo?

I have never seen the use of "are" for boolean methods, but the use of "is" is very common. When I want to use "are" is usually because I am passing multiple variables, or a list of objects. I ...
2
votes
1answer
129 views

php return values

I have a codeigniter app and in my model, I always return true or false for all functions, and if I have data that needs to be passed, I also set a property that contains my data. The only trouble ...
1
vote
1answer
571 views

Wrapping Primitives to Enable Returning null — Bad Practice?

I am frequently tempted to wrap integers, etc, solely for the purpose of writing methods that can return null. Negative 1 can work in many cases, but too often (especially in sound) it's a valid ...
1
vote
3answers
2k views

When should one use “out” parameters?

In Objective-C, there are several methods like initWithContentsOfFile:encoding:error: where one passes in a reference to an NSError object for the error: parameter. In this example, the value of the ...
4
votes
2answers
3k views

Naming methods that do the same thing but return different types

Let's assume that I'm extending a graphical file chooser class (JFileChooser). This class has methods which display the file chooser dialog and return a status signature in the form of an int: ...
3
votes
4answers
609 views

Is conditional return type ever a good idea?

So I have a method that's something like this: -(BOOL)isSingleValueRecord And another method like this: -(Type)typeOfSingleValueRecord And it occurred to me that I could combine them into ...
1
vote
3answers
7k views

function works fine without return value in c++ [closed]

I forgot to write return 'a'; in function and return 0; in main function but its works fine in Code::Blocks. #include <iostream> using namespace std; char show() { cout<<"this is show ...
11
votes
4answers
3k views

C# return variables

In a debate regarding return variables, some members of the team prefer a method to return the result directly to the caller, whereas others prefer to declare a return variable that is then returned ...
15
votes
9answers
3k views

Which statically typed languages support intersection types for function return values?

Initial note: This question got closed after several edits because I lacked the proper terminology to state accurately what I was looking for. Sam Tobin-Hochstadt then posted a comment which made ...