Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
john donne
Apr 10, 2016

All suitors of all sorts themselves enthral;

So on his back lies this whale wantoning,

And in his gulf-like throat, sucks everything

That passeth near.

Knyteguy posted:

That's the only thing the parameter does :psyduck:.

I'm quite sure that out of all the horrors created by OOP, using complex types as function arguments is one of the least.

Adbot
ADBOT LOVES YOU

boo_radley
Dec 30, 2005

Politeness costs nothing

Ithaqua posted:

Maybe more properties from that object used to be referenced.

I've missed your gentle optimism, Ithaqua.

qntm
Jun 17, 2009
JavaScript code:
                                            errors.push(error);

                                        }//if

                                    }//if
                                    else {

                                        //
                                        // target property type is string, so it can accept any other data type
                                        //
                                        continue;

                                    }//endif


                                }//if
                                else {

                                    //
                                    // this is a function
                                    //


                                    continue;//go onto next rule

                                }//endif
                            }//if
                            else {
                                //
                                // this is a concatenate function of several DATA items, or series of functions, or user typed in text in the field
                                //


                                //
                                //see if user simply typed text in the field
                                //
                                if (

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.
:barf:

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

But he can tell his boss he cranks out 1200 lines of code a day!

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Literate Programming, JRR Tolkien style.

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

Knyteguy posted:

C# code:
public ProcessPaymentResult ProcessRecurringPayment(ProcessPaymentRequest processPaymentRequest)
{
    var result = new ProcessPaymentResult();

    var authentication = PopulateMerchantAuthentication();
    if (!processPaymentRequest.IsRecurringPayment)
    {
        ...
    }
}
That's the only thing the parameter does :psyduck:.

Counterpoint that I've seen quite a bit of recently:

C# code:
public void CalculateNewFooValue(Foo foo, int fooStartValue, bool isExoticFoo, string fooName)
{
	//...
}

public void CallingMethod()
{
	var foo = GetAFoo();

	CalculateNewFooValue(foo, foo.Value, foo.IsExotic, foo.Name);
}
Bonus method!

C# code:
public void DoAThing(Foo foo, ref newFoo)
{
	foo.Name = "Whatever";
	foo.Value = 1;
	foo.IsExotic = true;

	newFoo = foo;
}

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Ugh, I've recently been digging around in one of our older codebases and patterns like that are rampant. Extraneous parameters are dumb and annoying but at least they're easy to refactor. Ref and out can go die in a fire, however.

eth0.n
Jun 1, 2012

Bognar posted:

Ugh, I've recently been digging around in one of our older codebases and patterns like that are rampant. Extraneous parameters are dumb and annoying but at least they're easy to refactor. Ref and out can go die in a fire, however.

I'll take those over Java's "take an argument to a single element array" idiom. They even do this in at least one place in the standard API.

No Safe Word
Feb 26, 2005

Bognar posted:

Ugh, I've recently been digging around in one of our older codebases and patterns like that are rampant. Extraneous parameters are dumb and annoying but at least they're easy to refactor. Ref and out can go die in a fire, however.

The only real use I've seen for out params (other than TryParse stuff) is to get around the very understandable fact that you can't have two methods of the same name with the same argument list but different return types. So if I'm building a message adapter to convert a common model into the corresponding message for multiple versions of a messaging API, I can't do this:

code:
static public V1.FooMessage Convert(Foo model) { // ... }
static public V2.FooMessage Convert(Foo model) { // ... }
So instead, you do this:

code:
static public void Convert(Foo model, out V1.FooMessage message) { // ... }
static public void Convert(Foo model, out V2.FooMessage message) { // ... }
Granted you don't even have to do this because you can just name the methods differently obviously, but I actually kind of like this pattern.

sarehu
Apr 20, 2007

(call/cc call/cc)
It's also often much nicer to add an out parameter than to rejigger everything into two return values. I mean if C# doesn't support var (x, y) = foo(); yet.

Absurd Alhazred
Mar 27, 2010

by Athanatos


( The latest xkcd)

csammis
Aug 26, 2003

Mental Institution
Code looks like a mad doctor turned Wordpress inside out.

Did you pry that code off a dead Cold Fusion developer or what?

Radium-rear end code.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

sarehu posted:

It's also often much nicer to {tack on a quick hack} than to rejigger everything into {well-structured code that correctly represents the domain problem}. I mean if {the language} doesn't {make doing the right thing easier than the wrong one}.

Dirty Frank
Jul 8, 2004

Copy pasted from a Dhali fever dream

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal
Oh man... student code but lol.



That for loop contains the expected output.

But hey... student code (a student who didn't watch the lectures)

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Knyteguy posted:

Oh man... student code but lol.



That for loop contains the expected output.

But hey... student code (a student who didn't watch the lectures)

Plot twist: his actual homework submission is a script that generates that code for any value of n up to UINT_MAX.

raminasi
Jan 25, 2005

a last drink with no ice

Knyteguy posted:

Oh man... student code but lol.



That for loop contains the expected output.

But hey... student code (a student who didn't watch the lectures)

Mocking this kind of feels like mocking the road worthiness of a Big Wheel. That only counts as source code if you're a compiler.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Generating code with a script that you never test even once and whose output is a mixture of gibberish and code that does absolutely nothing sounds like student code to me.

I'm so glad I don't teach anymore.

sarehu
Apr 20, 2007

(call/cc call/cc)

Except no, there's nothing wrong at all with using out or ref parameters.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

sarehu posted:

Except no, there's nothing wrong at all with using out or ref parameters.

I have to work with them every day, because my coding predecessors of the past six years all loved them, and I can only aggressively refactor so fast. Let's just say I disagree in the strongest possible terms.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

NihilCredo posted:

I have to work with them every day, because my coding predecessors of the past six years all loved them, and I can only aggressively refactor so fast. Let's just say I disagree in the strongest possible terms.

If you ever find yourself with a strong opinion about programming it's time to sit back and ask yourself "why".

Sometimes ref or out is the only way to so what you need on a concise manner. As long as the behavior is clearly documented it's fine.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
C# is nice because it forces you to write "ref" or "out" at the function call as well.

Although I don't know why more languages don't allow multiple return values. It's not that complicated of an idea.

HappyHippo fucked around with this message at 18:12 on Jun 18, 2016

comedyblissoption
Mar 15, 2006

ref and out and other shenanigans are absurd constructs to work around mainstream programming language intransigence against sum types

their only justification is language interop with languages that aren't C#

weird
Jun 4, 2012

by zen death robot

HappyHippo posted:

C# is nice because it forces you to write "ref" or "out" at the function call as well.

Although I don't know why more languages don't allow multiple return values. It's not that complicated of an idea.

are there any languages other than lisp that do

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

weird posted:

are there any languages other than lisp that do

It's usually pattern matching with tuples. I guess it's not technically multiple return values but it's close enough
For example in python I can do
code:
def test(x):
    return x, x+1
    
a,b = test(7) #a = 7, b = 8
You can do similar things in haskell, rust, etc.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

weird posted:

are there any languages other than lisp that do

Python lets you return tuples, which you can then unpack into independent variables when you receive the return value. E.g.
code:
def func():
  return (42, 17)

foo, bar = func()
Python also lets you have default argument values and lets you indicate parameter names when you call the function, which makes reading code so much easier.

e;f,b

weird
Jun 4, 2012

by zen death robot
destructuring is cool

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

weird posted:

are there any languages other than lisp that do

Where are you going to draw the line for what counts as really "returning multiple values"? Does Python's "return a, b, c" (really just returning one object, the tuple (a, b, c)) count or not?

Been a while since I used it but I'm pretty sure that in Maple you can return a sequence of values, which is in principle a single object but isn't distinguishable from the individual items in the sequence separately.

as in, suppose MyFunction() returned 5, 6; then if you do MyOtherFunction(4, MyFunction()) then MyOtherFunction has no way of knowing that you did that and not MyOtherFunction(4, 5, 6)

Eggnogium
Jun 1, 2010

Never give an inch! Hnnnghhhhhh!

weird posted:

are there any languages other than lisp that do

Lua. It's a common way that errors are returned and also fundamental to for loops and iterators.

Zopotantor
Feb 24, 2013

...und ist er drin dann lassen wir ihn niemals wieder raus...

weird posted:

are there any languages other than lisp that do

Does Forth, technically.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
The concept that an expression produces one value is fundamental to the syntax of expressions. Returning multiple values in some way that isn't just a decomposable tuple, but actually requires some weird alternative syntax for receiving the values in the caller, is just being pointlessly obscure.

weird
Jun 4, 2012

by zen death robot

rjmccall posted:

The concept that an expression produces one value is fundamental to the syntax of expressions. Returning multiple values in some way that isn't just a decomposable tuple, but actually requires some weird alternative syntax for receiving the values in the caller, is just being pointlessly obscure.

having a different syntax for grabbing multiple values means that in the general case you can pretend that it does only return one value, because you can silently ignore any number of return values, so if you use the regular single value syntax, you get the primary return value. multiple return values are for 'extra' information that you normally don't care about, like gethash has two return values, the first is the (possibly default) value from the hash, the second is whether or not that key was actually in the hash

destructuring is a cooler feature

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Yeah, that is less a feature and more a positive consequence of a bug.

Dylan16807
May 12, 2010

rjmccall posted:

The concept that an expression produces one value is fundamental to the syntax of expressions. Returning multiple values in some way that isn't just a decomposable tuple, but actually requires some weird alternative syntax for receiving the values in the caller, is just being pointlessly obscure.

There's not much weird or obscure about "a, b =". You don't make expressions produce multiple values, you allow a comma-separated list of expressions. Which is the same thing you use every time you call a function with multiple parameters.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
This is not advanced theory here. The universally-standard formula / expression syntax used in both math and programming languages allows a formula / expression to have one result. Allowing certain expressions to instead have multiple results is not some brilliant generalization, it just makes those expressions awkward, non-composable special cases that can only be written in the select positions that have the magic power of handling the extra results. Tuples are just a superior way of solving the problem.

sarehu
Apr 20, 2007

(call/cc call/cc)
My wild guess is that in some Lisp implementations its advantage was that it returned the values unboxed.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Yeah, it's pretty easy to see how a naive implementation could implement a special thing easier. On the other hand, I'm not sure why a naive implementation wouldn't suffer the same problem with arguments. :shrug:

Nude
Nov 16, 2014

I have no idea what I'm doing.

HappyHippo posted:

Although I don't know why more languages don't allow multiple return values. It's not that complicated of an idea.

Something must of went over my head here; any reason why returning arrays would not be a solution? Sample code. I guess I'm just trying to wrap my head around a concept of returning multiple values, but not considered an array/object and why someone would want that.

Nude fucked around with this message at 07:33 on Jun 19, 2016

Adbot
ADBOT LOVES YOU

sarehu
Apr 20, 2007

(call/cc call/cc)
Because if it's not a Scheme then you statically know the arity of the function you're calling. But also non-naive implementations can't just return a cons pointer or whatever unboxed. Edit: I guess the implementations had to be pretty naive anyway, if you wanted it to fit on a mini-computer. Edit edit: I'm wondering if any lisp predates Common Lisp with multiple return values.

sarehu fucked around with this message at 07:52 on Jun 19, 2016

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply