|
Knyteguy posted:That's the only thing the parameter does . I'm quite sure that out of all the horrors created by OOP, using complex types as function arguments is one of the least.
|
# ? Jun 17, 2016 01:55 |
|
|
# ? May 21, 2024 05:47 |
|
Ithaqua posted:Maybe more properties from that object used to be referenced. I've missed your gentle optimism, Ithaqua.
|
# ? Jun 17, 2016 03:55 |
|
JavaScript code:
|
# ? Jun 17, 2016 11:34 |
|
|
# ? Jun 17, 2016 12:10 |
|
But he can tell his boss he cranks out 1200 lines of code a day!
|
# ? Jun 17, 2016 13:55 |
|
Literate Programming, JRR Tolkien style.
|
# ? Jun 17, 2016 14:06 |
|
Knyteguy posted:
Counterpoint that I've seen quite a bit of recently: C# code:
C# code:
|
# ? Jun 17, 2016 14:30 |
|
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.
|
# ? Jun 17, 2016 14:51 |
|
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.
|
# ? Jun 17, 2016 15:20 |
|
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:
code:
|
# ? Jun 17, 2016 15:46 |
|
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.
|
# ? Jun 17, 2016 19:45 |
|
( The latest xkcd)
|
# ? Jun 17, 2016 21:48 |
|
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.
|
# ? Jun 17, 2016 21:56 |
|
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}.
|
# ? Jun 17, 2016 21:59 |
|
Copy pasted from a Dhali fever dream
|
# ? Jun 17, 2016 21:59 |
|
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)
|
# ? Jun 17, 2016 22:01 |
|
Knyteguy posted:Oh man... student code but lol. Plot twist: his actual homework submission is a script that generates that code for any value of n up to UINT_MAX.
|
# ? Jun 17, 2016 22:05 |
|
Knyteguy posted:Oh man... student code but lol. 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.
|
# ? Jun 17, 2016 22:40 |
|
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.
|
# ? Jun 17, 2016 22:41 |
|
Except no, there's nothing wrong at all with using out or ref parameters.
|
# ? Jun 17, 2016 23:18 |
|
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.
|
# ? Jun 18, 2016 09:56 |
|
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.
|
# ? Jun 18, 2016 15:13 |
|
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 |
# ? Jun 18, 2016 18:07 |
|
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#
|
# ? Jun 18, 2016 20:10 |
|
HappyHippo posted:C# is nice because it forces you to write "ref" or "out" at the function call as well. are there any languages other than lisp that do
|
# ? Jun 18, 2016 23:34 |
|
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:
|
# ? Jun 19, 2016 00:01 |
|
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:
e;f,b
|
# ? Jun 19, 2016 00:03 |
|
destructuring is cool
|
# ? Jun 19, 2016 00:04 |
|
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)
|
# ? Jun 19, 2016 00:07 |
|
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.
|
# ? Jun 19, 2016 00:55 |
|
weird posted:are there any languages other than lisp that do Does Forth, technically.
|
# ? Jun 19, 2016 01:06 |
|
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.
|
# ? Jun 19, 2016 01:17 |
|
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
|
# ? Jun 19, 2016 01:26 |
|
Yeah, that is less a feature and more a positive consequence of a bug.
|
# ? Jun 19, 2016 01:28 |
|
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.
|
# ? Jun 19, 2016 03:35 |
|
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.
|
# ? Jun 19, 2016 06:40 |
|
My wild guess is that in some Lisp implementations its advantage was that it returned the values unboxed.
|
# ? Jun 19, 2016 07:00 |
|
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.
|
# ? Jun 19, 2016 07:16 |
|
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 |
# ? Jun 19, 2016 07:28 |
|
|
# ? May 21, 2024 05:47 |
|
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 |
# ? Jun 19, 2016 07:29 |