MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/91ol3u/me_doing_my_cs_projects/e38ncs5/?context=3
r/Python • u/iFocus • Jul 25 '18
213 comments sorted by
View all comments
Show parent comments
3
Can you elaborate on using functions to avoid indendation errors? Thank you!
2 u/jsalsman Jul 29 '18 edited Jul 29 '18 Sure.def messy(): if booleanA: if booleanB: doA() else: doB() else: doC()can be refactored intodef subroutine(): if booleanB: doA() else: doB() def neat(): if booleanA: subroutine() else: doC() 2 u/Saiboo Jul 29 '18 Thank you so much for the code example, much appreciated! 2 u/jsalsman Jul 29 '18 No problem. I edited it to put the subroutine definition before its call, which isn't always necessary depending on whether the source file is parsed before neat() gets called, but is almost always more readable with real production code.
2
Sure.
def messy(): if booleanA: if booleanB: doA() else: doB() else: doC()
can be refactored into
def subroutine(): if booleanB: doA() else: doB() def neat(): if booleanA: subroutine() else: doC()
2 u/Saiboo Jul 29 '18 Thank you so much for the code example, much appreciated! 2 u/jsalsman Jul 29 '18 No problem. I edited it to put the subroutine definition before its call, which isn't always necessary depending on whether the source file is parsed before neat() gets called, but is almost always more readable with real production code.
Thank you so much for the code example, much appreciated!
2 u/jsalsman Jul 29 '18 No problem. I edited it to put the subroutine definition before its call, which isn't always necessary depending on whether the source file is parsed before neat() gets called, but is almost always more readable with real production code.
No problem. I edited it to put the subroutine definition before its call, which isn't always necessary depending on whether the source file is parsed before neat() gets called, but is almost always more readable with real production code.
3
u/Saiboo Jul 25 '18
Can you elaborate on using functions to avoid indendation errors? Thank you!