r/Python • • Jul 25 '18

Use an IDE Me doing my CS projects.

Post image
1.2k Upvotes

213 comments sorted by

View all comments

Show parent comments

14

u/vortexofdeduction Jul 25 '18

Agreed. If you use a good IDE, you’ll catch all the basic stuff before you even hit run, and it will be easy to indent correctly. (I like Pycharm, but there are lots of good options out there)

7

u/jsalsman Jul 25 '18

I don't know. If OP is running into indentation errors enough to complain about them in coursework, I'd suggest refactoring into function calls over getting an IDE. IDEs can't solve all indentation bugs, and the kind of bugs that beginners make are different.

3

u/Saiboo Jul 25 '18

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 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.