Review, suggestion etc?

Bischoop Bischoop at vimart.net
Thu Dec 17 11:10:44 EST 2020


On 2020-12-17, Michał Jaworski <swistakm at gmail.com> wrote:

Thanks for feedback and useful tips. 
I couldn't use any OOP here because have not a clue about it, just going
to go toward it.


> I've made a quick look at the code and even executed it. It looks pretty
> clear and is easy to understand, although it has some structural problems.
> I won't do a thorough review but highlight the most important problems.
>
> First, the recursive user input pattern you use:
>       def marriage():
>         maritals = input('Married: Yes/No ?: ').title()
>         while maritals != 'Yes' and maritals != 'No':
>             return marriage()
>         return maritals
>
>
>     def marriage():
>         ...
>

Could you expand here, I rather don't know how I could do it different
way apart from if maritals == 'Yes' or maritals == 'No' or is it what
you meant?


> You shouldn't be doing that unless you need a closure with nonlocal
> variables to read from. Otherwise it really harms the readability. I
> understand the urge to keep relevant code close to the usage but you would
> have better results with modules. If you really want to keep everything in
> a single module, keep functions close together in the file but don't nest
> them. Use relevant naming conventions instead. Simply think of how you
> would write that in C. You could use some object-oriented approach too, but
> I would recommend polishing structural programming first.
>

Well I don't know C, the only other language I was learning it was basic
for Atari :-) So in other words I shoudn't nest functions like in
changes(), add_people() etc but keep
everything in one functions. 

> There are also other issues like not always closing files, and not
> validating the user input in specific places. Still, these will be more
> evident as you improve the structure of application and do thorough
> testing. Anyway, the code doesn't look bad. It of course needs improvement
> but I've also seen worse specimens from people being actually paid for
> writing the code.
>
> Remember that "how to make things better" is a function of few parameters:
> - what you want to achieve
> - what are you able to do
> - how much time do you have
>
> If your sole goal is to learn and improve skills, I would recommend
> polishing this in current procedural fashion to some extent, but not trying
> to make it perfect. Then I would start from scratch and experiment with
> different paradigms (OOP for instance). Then I would try to make a smaller
> project that has some actual utility.
>

Yes, I was pretty much interested in Python at the end 90s however life
made me putting this hobby away and now life changed again so I've more
free time and I'm happy be back with Python so after couple months
learning it again and writing few liners this is first thing that got me
to use what I've learnt so far and gave opportunity to solve moany
problems I had to deal with (had few nights without sleep ) :-)
Now I'll learn OOP as you said and then try to made this program again
with OOP from scratch.

--
Thanks



More information about the Python-list mailing list