Posts: 4,647
Threads: 1,494
Joined: Sep 2016
i'm still hoping to see a real world example of avoiding a big long stack of if/elif statements. in a script i am working on now where there is a log stack of if/elif statements, the code for each varies in size from just 1 line to 7 lines, so the functions would be not large. but how would the functions be named?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
(Jun-18-2019, 07:33 PM)ichabod801 Wrote: (Jun-18-2019, 06:48 PM)Skaperen Wrote: how would the functions be named?
How would we have any clue how to name functions for code we haven't seen?
Why don't you give us a sample of the if/elif chain, save five to ten elifs. Then maybe we could provide some coherent responses.
if you happen to have an example,
it would have its own names for what
it does. then i could see if
those names have a pattern that may be helpful, perhaps for better readability (
maybe with an
underscore character). maybe they are defined as nameless
lambdas that are just assigned into a class or dictionary. or maybe a
def is repeated with the
same name and assigned after each definition is complete like this:
def foo():
...
...
return
action.alpha = foo
def foo():
...
...
return
action.beta = foo
...
...
i'm not expecting someone to code up an example for me. maybe someone has an existing example.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
i'm just wanting to see the naming pattern in the example code so i can use the same pattern in my code to name my functions. i do not envision any need for the code to get the name string once it has a reference, unless i want it to print out a debugging message saying what function is being called. at this point i am ruling out any use of lambda functions. now i need to see (by looking at example code) if the intended design uses anonymous names or distinct names.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.