r/learnpython • • Mar 30 '21

How are you ‘planning’ your code?

There’s a thousand videos on Youtube on how to code Python - but they seem to be more like function references - which you can look up in the documentation?

How you guys and girls think through what you’re about to write?

Should I write 90 lines of code then reorganise it into functions? Or start writing functions and then finally ‘use’ the functions at the bottom of your code/script?

Is there a best practice way of doing this? I’m trying to make it easier for myself so everything works like ‘lego’ - otherwise I find I get really confused

Should I write down the steps as comments and then fill in the code after?

‘’’ getjson() Function will accept json string and return TSV def getjson():

‘’’ getinputs() function will read argv[1:] and return the first parameter, or exit with error message if none specified def getinputs():

‘’’ writetosql() function will accept TSV and write it to final.db def writetosql():

‘’’ Run the functions inputs=getinputs() tsv=getjson(inputs) writetosql(tsv)

349 Upvotes

107 comments sorted by

View all comments

14

u/fergal-dude Mar 30 '21

I learned a lot about planning my code from taking a single ‘Talk Python To Me’ course. He shows you how to plan and structure code well. Something lacking in most youtuber tutorials.

Also, the more you code the less you’ll have to comment. Comments are for when the code isn’t obvious, the great thing about python is that the code is obvious most of the time.

I came from an html/css background where you use big honking comments to section out your code, I still kinda miss that.

4

u/inglandation Mar 30 '21

Which course exactly?

4

u/fergal-dude Mar 30 '21

I've done quite a few, but Python Jumpstart was my first. Choose one you are interested in, if it's Michael Kennedy that's the presenter, you'll be fine. (not that the others are bad, it's just that I've only taken his)

1

u/inglandation Mar 30 '21

Thanks. I don't think I'll start with a beginner course, but they offer a few more advanced course that I'll probably buy.

1

u/ScotchLeSaint Mar 31 '21

1

u/fergal-dude Mar 31 '21

You bet, that's the first one of his I've taken. I've picked up others cheap in humble bundles, I think he's great for learning how to structure files and build things for scalability.