« first day (2076 days earlier)      last day (1147 days later) » 

12:57 AM
@AndrasDeak You are right. It could return one or more outputs depending on some condition. Is that common in Python? (In Matlab, the typical use case is return only as many outputs as the function call expects, which can be known within the function with nargout)
 
1:11 AM
@LuisMendo depends on the function. From a purity point of view it's better if it always returns the same number and type of objects. But it can still happen, normally with some input parameters that instruct it to do so.
 
 
3 hours later…
3:50 AM
Seems like really bad practice to return a different number of outputs depending on some condition not explicitly stated by the caller.
on the other hand, you can always accept all arguments as a tuple in a single variable, and then figure out how many outputs you got.
MATLAB is so nicely explicit, in that the caller requests a specific number of outputs, and the function can choose to do so, or error out.
 
 
7 hours later…
11:00 AM
@CrisLuengo yes
@CrisLuengo MATLAB does some really weird "extrospection"
I see how one can make good use of it but that's MATLAB's quirk
 
11:56 AM
Allowing a function to know how with many output arguments it has been called can hardly be considered "extrospection". inputname, on the other hand...
Dec 2 '16 at 22:46, by Luis Mendo
I consider inputname uglier than eval. I mean, evaluating a string as code is of course dangerous, but it may make sense sometimes, or at least it may seem to. But to know the caller's workspace variable name?? Why-T-H does a function need to know the name in the caller's workspace? That goes against the very essence of the function paradigm
@CrisLuengo Also, that can help save computations (for output variables that have not been requested)
 
@LuisMendo yeah, that's also what I had in mind. I'm no software engineer but in my head return values are the private business of the function.
So knowing what the caller does with the function call is extrospection to me
 
12:40 PM
I see your point, but I see it differently. When you call a function you should be able to know how many ouputs it's going to return. And the function should know how many outputs it has been requested. It's like implementing two different functions y = find(X) or [ii, jj] = find(x) with the same code. The code has to know what to do, depending on how it was called
 
I find it is very rare to have a function with a variable amount of things to be returned. I think the reason is that there is a great variety of containers wrap a "set" of returned values in a more meaningful way than it is in matlab.
 
@LuisMendo yes, but the way you should be telling a function what to do (i.e. how it's called) should be in the signature :P
 
 
2 hours later…
2:24 PM
@AndrasDeak I don't follow. Wasn't that my point since the beginning? :-) To have all that info in the first line that defines the function. Or do you mean that functions should not have variable input/output arity, i.e. should have a "fixed" signature?
 
2:37 PM
@AndrasDeak “should” is a big word there. Just because most languages do overloading etc based only on input arguments doesn’t mean that is the only way to do it.
I happen to really like this aspect of MATLAB, and miss it in other languages. In other languages you need to pass an extra input argument to specify what outputs to produce, or have a different function name depending on the number of arguments. There’s a redundancy there, MATLAB’s solution is most elegant IMO.
a = foo(x);
[a,b] = foo(x,”two output args please”);
(Damn, the phone version of chat sucks balls, that was hard to post!)
 
 
3 hours later…
6:05 PM
@CrisLuengo There is probably a dupe somewhere, but SO search is... less than optimal so I don't usually bother
 
6:49 PM
@LuisMendo yeah. I usually search like this: google.com/search?q=site:stackoverflow.com+matlab
 
7:09 PM
Yeah, I do that when I'm really interested. But most of the time I'm too lazy. Sometimes I even justify my laziness thinking: "if the OP didn't bother, am I supposed to?"
 
7:43 PM
@LuisMendo I don't consider the return value to be part of the signature. That might be a terminology error on my part.
@CrisLuengo as I said I'm not a programmer so when I say "should" I mean "how I think it should be" :D
As I said I can see how it's useful, but my point is that it's MATLAB being the odd-one-out here, so it's not python's fault for behaving differently
@LuisMendo with duckduckgo you can search "!ddso how to parfor" and it will expand to such a search
 
 
2 hours later…
9:21 PM
Good to know, that's shorter :-)
 

« first day (2076 days earlier)      last day (1147 days later) »