Thinking about python and programming in general

A little reflection on the principles of programming. There will be no solid works, just a few thoughts on this topic.

Maybe I’ll write this article. Maybe…

Don’t use weird solutions

The more standardized the better. Then you won’t get confused.

For example, in a DB it is necessary to store date. Always save in format datetime, even though it may seem redundant. But then there will be no confusion.

Because if in one place datetimeand in the other string – this will create extra code and bugs.

Do not write unnecessary checks

It’s good to check everything, but excessiveness is not needed where it is not needed.

@categories_bp.route(‘/update-category/’, methods=[‘POST’])
@login_required
def update_category():
user_id = flask_login.current_user.id
if not userid:
return error_message(‘user_not_found’)

In this example, checking for a user is superfluous, because there are already @login_required.

If the code can be shortened, it must be shortened

No need to spare your code. If once you wrote very long, but now you see what can be made shorter: delete the old one and write shorter.

Don’t overdo the cut

It is better not to overdo it in code reduction. And the readability of the code may deteriorate and a person with less experience may not understand what is happening there.

Avoid abbreviations to letters.

Avoid multiple booleans on the same line.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *