Re: Side effect and return value
Albert-Jan Roskam <[email protected]> Fri, 20 Sep 2024 17:02:45 +0200
| Newsgroups | gmane.comp.python.tutor |
|---|---|
| Message-ID | <DB9PR10MB6689C8F3528D391457F0A5FE836C2@DB9PR10MB6689.EURPRD10.PROD.OUTLOOK.COM> |
On Sep 20, 2024 02:06, dn via Tutor <[email protected]> wrote: On 20/09/24 08:40, Albert-Jan Roskam wrote: > Hi, > I've just read "Code that fits into your Brain". > The author says a function with a side effect should not have a return > value. But how would one write this function in order to do that? It took me a moment to realise that what I was (trying to) remembering is Mark Seemann's book, "Code that fits in your Head". === That's indeed the book I meant. Loved reading it. He also mentioned that learning/using functional principles had also been very useful for his OOP skills. But I think you're right, one has to be pragmatic sometimes. 1 Pure Functions: A pure function is one where the output is determined solely by its input values, without observable side effects. 2 Avoiding Side Effects: Functional programming aims to minimize side effects, which are changes in state that occur outside a given function's scope. ==== Hmmm, the function in my example was not pure in two ways: the GUIDs in the json make the return value impossible to predict AND it has a side effect (a record is INSERTed in a table). Oh well. :-) @Cameron's post illustrates such very neatly. === Did Cameron also reply to my post? I didn't see anything. Is there also a news group for Python Tutor? The mailing lists have been so quiet lately. Comp.lang.python has more traffic the mirrored mailing list _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor