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)
1
u/[deleted] Mar 30 '21
Open a notebook ( physical or some app like evernote, onenote, etc.) and write down your targets and requirements. Follow that up with a flowchart of how you want to proceed with the program. Go back to the notebook and start writing on how the steps in the flowchart will be actually done (some pseudocode). Return to the flowchart if necessary and keep going through this loop until you are quite certain what your code should look like. I don't think it is a good idea to have to think something when you are typing your code unless absolutely necessary (even then I feel that you should go back to the notebook and sort out everything before getting back to typing your code).