Which is a better practice, generally speaking, and why? Under what circumstances would you change your mind?
function foo1(int x) {
int result;
if (x > 5) {
result = 2;
} else {
result = 7;
}
return result;
}
OR
function foo2(int x) {
if (x > 5) {
return 2;
} else {
return 7;
}
}
...
Here is my code:
// Function code
public static int something(){
int number1 = 1;
int number2 = 2;
return number1, number2;
}
// Main class code
public static void main(String[] args) {
something();
System.out.println(number1 + number2);
}
Error:
Exception in thread "main" java.lang.RuntimeException: Uncompilable sou...
hi im tryin to use the return from a jquery ajax call in my own function, but it keeps returning undefined.
function checkUser2(asdf) {
$.ajax({
type: "POST",
async: false,
url: "check_user.php",
data: { name: asdf },
success: function(data){
return data;
//alert(d...
I'm writing my thesis/dissertation and since its an on-going work I don't always have the actual images ready for the figures I put into my document, but for various reasons want to automatically have it substitute a dummy figure in place when the included graphics file doesn't exist. E.g. I can do something like \includegraphics[width=8...
My variable looks like:
name = "Lola "; // notice the whitespace
How can I delete the whitespace at the end to leave me with just "Lola"?
Thank you all, but .Trim() don't work to me.
I read the text from a file, if that is any help.
...
Hi there.
I'm recieving that wonderfuly ambiguous error message when using one of my webmethods on my WCF webservice. As that error message doesn't provide any explanation whatsoever allow me to post my theory.
I believe it may have something to do with the return type I'm using
I have a Types DLL which is refrenced in both the webser...
Suppose you have a function, and you call it a lot of times, every time the function return a big object. I've optimized the problem using a functor that return void, and store the returning value in a public member:
#include <vector>
const int N = 100;
std::vector<double> fun(const std::vector<double> & v, const int n)
{
std::vect...
I have enum list and method and i get error: " not all code paths return a value"
Some idea whats wrong in my method ? I am sure I always return STANY type :/
Thanks for help :)
private enum STANY { PATROL, CHAT, EAT, SEARCH, DIE };
private STANY giveState(int id, List<Ludek> gracze, List<int> plansza)
{
// Spraw...
As far as I understand it, there is no way in Scala to have multiple return points in an anonymous function, i.e.
someList.map((i) => {
if (i%2 == 0) return i // the early return allows me to avoid the else clause
doMoreStuffAndReturnSomething(i) // thing of this being a few more ifs and returns
})
raises an error: return outs...
function isNewUsername(str){
var result;
$.post('/api/isnewusername',
{username:str},
function(data) {
result = data.result;
},
"json");
return result;
}
So , my problem is very simple but I can not figure it out . I want to access result from the isnewuserna...
From Herb Sutter's GotW #6
Return-by-value should normally be const for non-builtin return types. ...
Note: Lakos (pg. 618) argues against returning const value,
and notes that it is redundant for builtins anyway
(for example, returning "const int"), which he notes may
interfere with template instantiation.
While Sutte...
What happens, step by step, when a variable is returned. I know that if it's a built-in and fits, it's thrown into rax/eax/ax. What happens when it doesn't fit, and/or isn't built-in? More importantly, is there a guaranteed copy constructor call?
edit: What about the destructor? Is that called "sometimes", "always", or "never"?
...
Hello! I've go a very simple question, but unfortunately I can't figure the answer myself.
Suppose I've got some data structure that holds settings and acts like a settings map.
I have a GetValue(const std::string& name) method, that returns the corresponding value.
Now I'm trying to figure out - what kind of return-value approach woul...
Hi all,
I am trying to use a Stored Procedure which takes two parameters (login, pw) and returns the user info.
If I execute the SP manually, I get
Session_UID User_Group_Name Sys_User_Name
------------------------------------ -------------------------------------------------- -
NULL Administrators NTMSAd...
Hi, I am currently working on a project using NHiberate as the DAL with .NET 2.0 and NHibernate 2.2.
Today I came to a point where I had to join a bunch of entities/collections to get what I want. That is fine.
What got me was that I do not want the query to return a list of objects of a certain entity type but rather the result woul...
I have the following statement in a Stored Procedure:
DECLARE @Count INT
EXEC @Count = GetItemCount 123
SELECT @Count
Which calls another stored procedure with the following statement inside:
SELECT COUNT(Item) FROM tblItem WHERE ID = @ID
However when I test the call the EXEC outputs the value correctly but it
is not assigned to th...
I'm trying to convert some code from Javascript to c. The function creates an array (which always has a fixed number of items) and then returns the array. I've learned that in c it's not straightforward to return an array, so I'd like to return this as a struct instead. My c is not all that great, so I'd like to check that returning a st...
So I've started looking at ruby, and a lot of things look nice but I'm quite put off by implicit return statements. I understand making everything return self or nil by default but not the last value of a statement.
To me it looks horribly fragile (especially) if you are working with a method that doesn't plan to return something (espec...
I am using the MySQL Connector.
using (MySqlConnection connection = new MySqlConnection("..."))
{
connection.Open();
MySqlCommand command = new MySqlCommand();
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "FN_NEW";
command.Parameters.AddWithValue("P_SES...
Is it ever possible for the C send function to return zero when using TCP sockets? The man page just says that it will return the number of bytes sent, but I am not sure if it will just return -1 when it can't send any data.
...