r/learnpython • u/brushygiraffe • 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)
69
u/IDontLikeBeingRight Mar 30 '21
Start by doing whatever workflow you want. But be aware of things that aren't going well, and what you could change, and why any particular element of any best practice might be there.
Don't expect gold from your first programs, and expect to have a lot more to learn the first time you share a project rather than just coding by yourself. Even start a project in a deliberately different way just because, to see where which things go wrong. (Uh, maybe don't collaborate for that one). Don't get attached to any particular project (also: have projects that you can avoid being attached to), learn from the mistakes & inefficiencies, and try to understand the best practices rather than simply implementing them.