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

1

u/umognog Mar 30 '21

I scanned through and didn't see a single offering of this;

UML

Start with your use case diagrams, use that to generate your activity diagram and from there class/state diagrams as necessary.

Usually these are enough for most projects and you can get pretty efficient at creating them during requirements gathering.

1

u/smurpau Mar 30 '21

I don't know anyone who uses UML anymore. It costs more in overhead than it saves.

1

u/umognog Mar 30 '21

I'd disagree. I can sit in a meeting, the notes taken are in UML and immediately afterwards the team can start dev with a structure available, no further discussion is needed.

That same UML can be understood by less technical purse holders without creating new proposals and write up especially for them and easily used for progress updates without having to write anything new for this purpose either.

That said, I am open to learning better ways; what is your suggestion that can fulfil these requirements in the same or less time?