Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
return in a function
#11
i've had larger cases that if done this way would involve at least 10 variables being passed. i would probable have to pass locals().
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#12
If a function takes so many parameters, that's usually a sign that it's doing too much and that it should be broken down.
Reply
#13
there definitely is "too much". but having all that code duplicated in 15 places makes it "way too much". but when i reduce it, i want each of the 15 places to be real simple like
    perform_all_the_profile_checks_and_return_if_needed()
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#14
Yeah, functions should be doing one thing. I find test-driven development a great way to design - by starting with a test, you're focussing on the "what" before the "how" (that is, what the component does and its interface before how that is implemented). Obviously if you have existing code to refactor, then getting tests in place first (if you don't have them) will allow you to refactor safely.
Reply
#15
(Mar-06-2021, 01:04 PM)snippsat Wrote: Need or not,so to we get switch case version in Python 3.10.
Called Structural Pattern Matching which is more powerful that just simple switch case.
Nice! I would have liked structural pattern matching in function definitions as well. I loved the pattern matching in Haskell, Miranda, Standard ML and other functional programming languages with tail recursion and guards.
Reply
#16
(Mar-15-2021, 01:31 AM)Skaperen Wrote: there definitely is "too much". but having all that code duplicated in 15 places makes it "way too much". but when i reduce it, i want each of the 15 places to be real simple like
    perform_all_the_profile_checks_and_return_if_needed()

Maybe wrap those variables/functions up into a class? That way you don't need to pass 20 variables, you can just do the_thing.perform_checks_and_notify_if_needed(), and the function can just reference whatever it needs via self.
Gribouillis and Serafim like this post
Reply
#17
(Mar-15-2021, 06:33 AM)ndc85430 Wrote: Yeah, functions should be doing one thing.
yes, i do agree ... for most cases. but here, the "one thing" is to reduce a sequence of things. suppose you have 15 complicated things to do. reducing this to 15 functions, each doing one thing, makes sense. but the you still have 15 function calls to do. now you have 12 places to do the 15 calls. i now consider the sequence of 15 calls to be the 16th "one thing" and make a 16th function to all that. now the returns have to go back another calling level. maybe this what exceptions are for.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is that possible to have a new feature: dynamic return with using function argument kouui 2 2,012 Aug-26-2019, 10:05 AM
Last Post: kouui

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020