(Title and contents updated after reading Alex's answer)
In general I believe that it's considered bad form (un-Pythonic) for a function to sometimes return an iterable and sometimes a single item depending on its parameters.
For example struct.unpack always returns a tuple even if it contains only one item.
I'm trying to finalise the...
This works nicely:
// Return all objects with code 'code'.
static List<? extends ICode> getObjects(String code, List<? extends ICode> list)
{
<ICode> retValue = new ArrayList<ICode>();
for (ICode item : list)
{
if (item.getCode().equals(code))
{
retValue.add(item);
}
}
return retValue;
}
The 'singular' v...
When your in a situation where you need to return two things in a single method, what is the best approach?
I understand the philosophy that a method should do one thing only, but say you have a method that runs a database select and you need to pull two columns. I'm assuming you only want to traverse through the database result set onc...
hi im trying to get the rel value of a button that is click:
function forwardStep()
{
$("#forwardStep").bind("click", function(){
var page = $(this).attr('rel');
thats pretty much the basis but is return "undifined". Do you know why?
Regards Phil Jackson
...
Is there anything returned from MySQL/PHP on a INSERT query being executed? Here is my function which I have in a CLASS.
function mysqlQuery($query) {
// Gets the results from the query
$results = mysql_query($query, $this->connection);
// Loops through the queried results as an multi-dimensional array
while($rows = mysql_f...
I have seen conflicting advice on whether the following code is better
def function():
ret_val = 0
if some_condition():
ret_val = 2
else:
ret_val = 3
return ret_val
or whether this is better:
def function():
if some_condition():
return 2
else:
return 3
This is a simple example...
I was wondering if there are any languages that allow for named tuples. Ie: an object with multiple variables of different type and configurable name.
Eg:
public NamedTuple<double:Speed, int:Distance> CalculateStuff(int arg1, int arg2)
var result = CalculateStuffTuple(1,2);
Console.WriteLine("Speed is: " + result.Speed.ToString())
Co...
How do you run an executable with parameters passed on it from a C++ program and how do you get the return value from it?
Something like this:
c:\myprogram.exe -v
...
I am converting C# code to VB.Net and the C code has this above the function:
[return: System.Xml.Serialization.XmlElementAttribute("Name", IsNullable=true)]
...
In some situations using C/C++, I can syntactically indicate to the compiler that a returnvalue is purposely ignored:
int SomeOperation()
{
// Do the operation
return report_id;
}
int main()
{
// We execute the operation, but in this particular context we
// have no use of the report id returned.
(void)SomeOperatio...
Hi!
I don't know if this could be done, but I have a WCF service that should return a custom object, the object has a collection of another custom object that contains a stream.
when I try to return this object I get
System.Runtime.Serialization.InvalidDataContractException: Type 'System.ServiceModel.Dispatcher.StreamFormatter+Message...
Hello,
I will just come right to it.
I need to know how I can return false or true to a submitbutton.
I read some other post here, that says it cannot be done from within a ajax success function
because it wil return to the ajax context and not the submit event.
Maybe someone has a workaround for this??
also in the context that I am...
I want to have a single custom section header, with the rest being the default header.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return ???;
}
What do I return to just give the default header view?
...
I notice that almost all scheme functions can only return one list as output.
In the following, I would like to return multiple values of all the adjacent nodes of neighbors.
(define (neighbors l w)
(if (and (= 1 l) (= 1 w))
(list (and (l (+ 1 w))) (and (+ 1 l) w)))) ; how to output 2 or more values?
In this case I'm first t...
Okay this is my 4th question today on Scheme, still pretty new to Scheme, as I needed for one of my sub-function I asked earlier in the day.
Basically this will return me the difference of 2 lists. Say you've got (1,5) and (5,1) this function should return me 8. As that's the distance between l to w
Here is what I have. Note: if I cha...
What is the best practice when returning data from functions. Is it better to return a Null or an empty object? And why should one do one over the other?
Consider this:
public UserEntity GetUserById(Guid userId)
{
//Imagine some code here to access database.....
//Check if data was returned and return a null if none found
...
Hi,
I'm making a basic ajax function in jquery which echoes the number of rows found in a MySQL Query.
function checkEventIDClass(id) {
var params = 'method=checkEventIDClash&table=test&id=' + id;
$.ajax({
type: "POST",
url: "ajax.php",
data: params,
...
For my application, I am trying to add entries without having a duplicate entry, and if there are a duplicate notify the user and have him try again. Using SQLite, which I know very very little about, I have tried these two ways and want to know which one is better, more efficient or a better way to develop it?
First way:
db.execSQL("I...
Please tell me what will the call to given function return and how? The code:
typedef struct {
int size;
ptrdiff_t index;
void (*inlet) ();
int argsize;
ptrdiff_t argindex;
} CilkProcInfo;
/*
* Returns a pointer to the slow version for a procedure
* whose signature is p.
*/
/* the function definition is - */
st...
Hi,
I am trying to record the success or failure of a number of copy commands, into a log file. I'm using shutil.copy() - e.g.
`str_list.append(getbitmapsfrom)
game.bigbitmap = "i doubt this is there.bmp"
str_list.append(game.bigbitmap)
source = '\\'.join(str_list)
shutil.copy (source, newbi...