Feedback for time calculator project

Hello, I was wondering if someone could provide me some feedback on my solution to the time calculator project, as I feel it has become quite the Spaghetti code here, (And maybe a bit over-commented.)

link: https://replit.com/@guilhermejuvent/boilerplate-time-calculator-1#time_calculator.py

Any feedback would be appreciated.

Spaghetti no. Overally I’d say it’s relatively clean. The complexity is rather limited, what is a good thing. Variable names try to be descriptive, although it seems like you might be thinking some of them are still not precise enough - hence the comments.

Comments are sticking out, and also some places with repeats, that could be simplified. This is especially visible at the end, where can be found:

new_time = f"{total_hours}:{total_minutes} {meridiem}"
new_time = f"{total_hours}:{total_minutes} {meridiem} (next day)"
new_time = f"{total_hours}:{total_minutes} {meridiem} ({amount_of_days:.0f} days later)"
new_time = f"{total_hours}:{total_minutes} {meridiem}, {weekday_result}"
new_time = f"{total_hours}:{total_minutes} {meridiem}, {weekday_result} (next day)"
new_time = f"{total_hours}:{total_minutes} {meridiem}, {weekday_result} ({amount_of_days:.0f} days later)"

    start_time = start.split(" ")[0]
    meridiem = start.split(" ")[1]

Fragments like this could be written in a single line, using a so-called unpacking, what would add some readability.

Thanks for the feedback, I did some cleaning as you suggested.

link: https://replit.com/@guilhermejuvent/boilerplate-time-calculator-1#time_calculator.py

Much better already. For comments, generally if comment is saying what is happening in code, then it might be obsolete. If somebody reads code, then code would tell the same thing as is in comment, unless there’s something really complex. If comment is saying why something is written like that, it could be beneficial.


[start_time, meridiem] = start.split(" ")[0], start.split(" ")[1]

I could have been more specific in my comment. I was thinking more about something like below, for example:

date = '2022-01-28'
year, month, day = date.split('-')

That could work even better, mine was just the first solution that came in my mind after I googled for unpacking in python.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.