Timeline for Return considered harmful? Can code be functional without it?
Current License: CC BY-SA 4.0
63 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 11, 2022 at 18:41 | history | edited | candied_orange | CC BY-SA 4.0 | Comments use this abbreviation |
| Dec 16, 2021 at 23:07 | comment | added | davidbak | sounds like you've discovered an O-O "workaround" to provide continuations - i.e., "continuation passing style" - something that is totally natural in functional languages (where you use closures for that, with a nice clean syntax) yet is still considered unwieldy to use exclusively instead of functions returning results - suitable only for special purposes like compilers or other situations where you absolutely must have explicit control flow - oh wait, explicit control flow? I thought that's what you were trying to get away from? | |
| Dec 16, 2021 at 22:16 | history | edited | candied_orange | CC BY-SA 4.0 | deleted 101 characters in body |
| Jul 7, 2020 at 4:40 | vote | accept | candied_orange | ||
| Jul 7, 2020 at 4:27 | history | edited | candied_orange | CC BY-SA 4.0 | edited body |
| Jul 4, 2020 at 12:06 | history | edited | candied_orange | CC BY-SA 4.0 | added 43 characters in body |
| Dec 25, 2018 at 16:00 | answer | added | user321630 | timeline score: 1 | |
| Feb 19, 2018 at 3:47 | history | tweeted | twitter.com/StackSoftEng/status/965432659005657088 | ||
| Feb 17, 2018 at 19:03 | history | edited | candied_orange | CC BY-SA 3.0 | deleted 7 characters in body |
| Feb 15, 2018 at 22:49 | history | edited | candied_orange | CC BY-SA 3.0 | added 1 character in body |
| Feb 15, 2018 at 22:44 | history | edited | candied_orange | CC BY-SA 3.0 | added 1 character in body |
| Feb 15, 2018 at 12:29 | comment | added | Flater | When I use return I have no idea what called me. I can't speak it's protocol, I have to force it to deal with my protocol. Not necessarily. A clear and simple counterexample of this is JSONP. JSONP only really asks for the callback method name, but you can expand this to include a full on formatter with specific implementations for every needed protocol. If the protocol is included as a parameter, then the method itself doesn't need to care what the exact protocol is. | |
| Feb 15, 2018 at 10:54 | comment | added | FacticiusVir | It's possible that the programming paradigm you're looking for is something like destroyallsoftware.com/talks/boundaries | |
| Feb 15, 2018 at 0:04 | comment | added | Bill K | @CandiedOrange I don't think it's possible--In a way "Tell Don't ask" is the opposite of Immutable. Another way to put it: A function MUST have a return value or it's not a function. However remember in real life--you can integrate the two styles very successfully by coding most of your methods as functions and most of your objects as immutable, avoiding most getters and pretty much all setters.... You can combine the two styles pretty well. It still leans towards OO more than functional. | |
| Feb 14, 2018 at 21:56 | comment | added | candied_orange | @BillK hey I'm not trying to force it. I'm wondering if it's even possible. That's why I'm asking if getting the benefits functional purity is possible without using return. For that, is return the only way? | |
| Feb 14, 2018 at 21:42 | comment | added | Bill K | Functional and OO are different approaches and solve slightly different problems. OO is mostly focused in code organization and data encapsulation and enables a designer to get a good overview of their code more quickly... Functional is an amazing way to eliminate concurrency problems and is a good way to break down complex problems. They can be used in combination but going to an extreme with either is probably harmful (Like, say, trying to forcefully combine "tell don't ask" with immutability...) | |
| Feb 14, 2018 at 21:33 | comment | added | candied_orange | @Danikov strangely enough, another reason comes from "favor composition over inheritance". One of the nice things about composition is you use what you're composed of from the outside not the inside. You use it through it's normal interface. That's also true when I use an output port. It's not true when I use return or throw exceptions at my client. | |
| Feb 14, 2018 at 21:27 | comment | added | candied_orange | @Danikov It came from a few sources. Tell don't ask leaves me inclined to not ask questions. Nor provide a way to ask questions. But instead provide ways for objects to tell each other things. Clean Architecture tells me to use plugins with input and output port interfaces. These don't use return. What I've discovered is that I can solve just about any problem without using return. Which surprised me. So now that I have this strange power, I'm trying to figure out how to use it wisely. I'm looking for downsides. Purity? You're right about isPushed(). I could avoid that too. Should I? | |
| Feb 14, 2018 at 20:34 | answer | added | yoniLavi | timeline score: 1 | |
| Feb 14, 2018 at 15:44 | comment | added | Danikov | "public boolean isPushed() { return pushed; }" I see a return in that example. You still haven't justified your reason for avoiding return. What's the motivation, beyond the vague title statement that return is "considered harmful"? 'Considered harmful' and 'should never be used' are very different things. If it's just a flying fancy to see if it can be done, then it wouldn't hurt to state that explicitly, but it'd be nice to understand the thinking behind how you got to that idea. | |
| Feb 14, 2018 at 12:51 | comment | added | guillaume31 | "X considered harmful" statements 101: find out the implied context. Consider X to be totally fine except in that particular context. | |
| Feb 14, 2018 at 12:50 | history | protected | gnat | ||
| Feb 14, 2018 at 12:44 | answer | added | Zazaeil | timeline score: 0 | |
| Feb 14, 2018 at 12:27 | review | Close votes | |||
| Feb 19, 2018 at 3:04 | |||||
| Feb 14, 2018 at 12:21 | history | edited | candied_orange | CC BY-SA 3.0 | added 48 characters in body |
| Feb 14, 2018 at 11:56 | history | reopened | Robert Harvey Karl Bielefeldt Doc Brown candied_orange Bart van Ingen Schenau | ||
| Feb 14, 2018 at 11:52 | history | edited | candied_orange | CC BY-SA 3.0 | added 6 characters in body |
| Feb 14, 2018 at 11:45 | history | edited | candied_orange | CC BY-SA 3.0 | added 6 characters in body |
| Feb 14, 2018 at 11:28 | comment | added | candied_orange | @ChrisWohlert Thanks, and please help me figure it out. Wish I knew what needs clarifying to remove the hold. | |
| Feb 14, 2018 at 9:39 | comment | added | Chris Wohlert | @CandiedOrange That is pretty much how TDD came about. Beck had a intuition that testing first, like in other engineering disciplines could work. So he went on a "kick", and tried it out. However, you need to convince others to join your trip down the rabbit hole, if you want to battle your own predisposition. I might suggest not using reason to achieve this, but instead say "I don't know why this works, want to help me figure it out?" But I must say, excellent thread, threads like this is what I joined this community to be a part of. | |
| Feb 14, 2018 at 8:57 | history | edited | candied_orange | CC BY-SA 3.0 | added 74 characters in body |
| Feb 14, 2018 at 8:49 | history | edited | candied_orange | CC BY-SA 3.0 | added 264 characters in body |
| Feb 14, 2018 at 8:42 | history | edited | candied_orange | CC BY-SA 3.0 | added 264 characters in body |
| Feb 13, 2018 at 18:23 | comment | added | candied_orange | @Blrfl my personal inclination to be predisposed is exactly what I'm trying to check myself against. I've come come to like this and I want to be sure my reasons why aren't simply fantasies. | |
| Feb 13, 2018 at 17:33 | comment | added | Blrfl | @jameslarge Experimentation with something to see if it's going to produce good results in a given situation is reasoning. Predisposition to use it is going off on a kick. | |
| Feb 13, 2018 at 17:22 | comment | added | Solomon Slow | @NicolBolas, I never meant to suggest that "dogma-driven design" and "The Wild West" were the only two possibilities. In fact, I was trying to lead to exactly the opposite conclusion. Blrfl thinks that dogma-driven is bad. I agree. You think that the Wild West is bad. I agree. IMO, experimenting with a style (e.g., going off on a "tell-don't-ask kick") is a better choice than either of the above. | |
| Feb 13, 2018 at 17:21 | review | Reopen votes | |||
| Feb 14, 2018 at 12:00 | |||||
| Feb 13, 2018 at 17:01 | comment | added | candied_orange | @Danikov I've constructed working flexible programs following TDA and avoiding use of return in an exploration of how much I can do working this way. Where before I had always reached for return thinking it was the only way. Here's an example I created without even thinking about TDA or functional purity. I look at it now though and it seems to follow TDA very well. I'm trying to look at it while thinking about functional purity. Is it crazy to think it could be described as pure? Even parts of it? | |
| Feb 13, 2018 at 16:47 | history | closed | gnat Mason Wheeler 17 of 26 Nicol Bolas Peter Taylor | Needs details or clarity | |
| Feb 13, 2018 at 16:32 | comment | added | Danikov | There's one thing for me that's unclear in your question: you say you've sworn off using 'return', but as far as I can tell you don't explicitly relate that to your other concepts or say why you've done this. When combined with the definition of a pure function including producing a result, you create something that is impossible to resolve. | |
| Feb 13, 2018 at 16:22 | answer | added | Robert Harvey | timeline score: 40 | |
| Feb 13, 2018 at 16:05 | comment | added | Nicol Bolas | @jameslarge: False dichotomy. Not allowing yourself to be driven to designs by dogmatic thinking is not the same thing as the Wild West/everything goes approach you're talking about. The point is to not allow dogma to get in the way of good, simple, obvious code. Universal law is for lackies; context is for kings. | |
| Feb 13, 2018 at 15:59 | comment | added | Solomon Slow | @Blrfl, which would you rather try to read and understand? A system where every method, every class, every module and every interface is designed according to the same guiding principles? or a system where each of the above was designed by a different person with a different idea about how the parts should fit together? There can be benefits to limiting yourself to one particular style/paradigm/philosophy/whatever-you-may-call-it. (And, you can triple that, or maybe quadruple it, if the language is C++.) | |
| Feb 13, 2018 at 15:55 | comment | added | Theodoros Chatzigiannakis | @Random832 Yes — essentially, this is the function's closure. | |
| Feb 13, 2018 at 15:14 | comment | added | Random832 | As for "state beyond their input parameters", generally "this" or closure state is either considered an input parameter or part of the function definition (the function is a distinct function from other functions with other "this"es, even if they have the same body). | |
| Feb 13, 2018 at 15:09 | comment | added | Random832 | In general when people talk about "return" being harmful they're saying it's against structured programming, not functional, and a single return statement at the end of the routine (and maybe at the end of both sides of an if/else block that is itself the last element) is not included in that. | |
| Feb 13, 2018 at 14:59 | answer | added | Bergi | timeline score: 8 | |
| Feb 13, 2018 at 14:32 | comment | added | Blrfl | Consider that finding yourself on a kick might be an indication that you're engaging in dogma-driven design rather than reasoning out the pros and cons of each specific situation. | |
| Feb 13, 2018 at 12:16 | answer | added | Jared Smith | timeline score: 5 | |
| Feb 13, 2018 at 11:48 | answer | added | JacquesB | timeline score: 107 | |
| Feb 13, 2018 at 11:15 | history | edited | candied_orange | CC BY-SA 3.0 | deleted 4 characters in body |
| Feb 13, 2018 at 10:55 | comment | added | candied_orange | @PieterB strictly speaking I'm talking about methods or closures (same dif for this issue) that have access to state beyond their input parameters. I'm merely pointing out the need for that state to be immutable to fulfil the first requirement of pure functional programing that I mentioned. Being globally accessible or not is an encapsulation issue but not relevant here. | |
| Feb 13, 2018 at 10:30 | comment | added | Pieter B | I don't think you should call a function immutable. What you should be referring to is that a pure function doesn't rely on things like global variables. | |
| Feb 13, 2018 at 10:20 | answer | added | Timothy Truckle | timeline score: 30 | |
| Feb 13, 2018 at 8:13 | comment | added | candied_orange | @rwong I can see how to follow CQS under OO just fine. It's following it under the requirements of pure functional programming that has me scratching my head. If you can see it please explain. | |
| Feb 13, 2018 at 8:07 | comment | added | rwong | If you choose not to ignore Command Query Separation, would you consider your problem solved? | |
| Feb 13, 2018 at 7:52 | history | edited | Laiv | CC BY-SA 3.0 | added 7 characters in body |
| Feb 13, 2018 at 6:42 | review | Close votes | |||
| Feb 13, 2018 at 16:49 | |||||
| Feb 13, 2018 at 6:21 | history | edited | candied_orange | CC BY-SA 3.0 | deleted 3 characters in body |
| Feb 13, 2018 at 6:18 | answer | added | Doc Brown | timeline score: 19 | |
| Feb 13, 2018 at 6:12 | history | edited | candied_orange | CC BY-SA 3.0 | added 100 characters in body |
| Feb 13, 2018 at 6:05 | history | edited | candied_orange | CC BY-SA 3.0 | added 100 characters in body |
| Feb 13, 2018 at 5:56 | history | asked | candied_orange | CC BY-SA 3.0 |