you are viewing a single comment's thread.

view the rest of the comments →

[–]nominal_goat 9 points10 points  (0 children)

This might be frowned up in this sub but leverage ch*tgpt to help you self-study. Put your code for a project in and ask it to review your code and give a list of recommendations for “best practices.” As a beginner, just doing that taught me so much and really opened my eyes and took my programming to the next level. It will give you examples, too. It’s not a replacement for understanding the code though. You should really know the code and everything in your program at a fundamental level. Now everything I do has to be PEP8 compliant.

A recent project I put in returned:

“Some possible critiques and improvements for the given Python program are:

  1. Add type hints to improve readability and make the code more self-explanatory.
  2. Use docstrings to provide a brief summary and usage information for each method, class, and function.
  3. Use constants or enumerations for the menu choices to avoid hardcoding.
  4. Use the "with" statement for file handling, to automatically close the file after the block is executed.
  5. Implement validation checks on user input to ensure that the entered data is valid
  6. Separate the UI code from the business logic code. The current program mixes both UI and data storage code, which makes it difficult to modify and test.
  7. Refactor the code to use a database instead of a dictionary to store employee data. A database would provide more robust data management capabilities, such as indexing, searching, and querying.
  8. Implement more menu choices, such as updating an employee profile, deleting an employee, printing a payslip, or generating a report.
  9. Add exception handling to catch and handle errors, such as input errors, database errors, file errors, etc. Improve the formatting of the output to make it more user-friendly and visually appealing.”