New ask Hacker News story: How to Prepare for Refactoring in Python?
How to Prepare for Refactoring in Python?
2 by matjazdrolc | 1 comments on Hacker News.
Refactoring is inevitable in any sufficiently complex piece of software. Type system in Java, C++ or C# helps the process immensely. Automated tooling can do most of the heavy lifting there. In Python type hints are optional. Additionally, many libraries are written such that typing is hard (example: Flask's g object, or SQLAlchemy's models). How to anticipate refactoring in Python and write code that is easy to refactor? Things that worked well so far: - verbose names. Longer variable or function name is less likely to collide with others within a project. Helps to quickly find all places in the project where the variable or function is used. - ending variable names with _type. Example: `current_user`. Searching for `user.last_login_date` will surface `current_user.last_login_date` too.
2 by matjazdrolc | 1 comments on Hacker News.
Refactoring is inevitable in any sufficiently complex piece of software. Type system in Java, C++ or C# helps the process immensely. Automated tooling can do most of the heavy lifting there. In Python type hints are optional. Additionally, many libraries are written such that typing is hard (example: Flask's g object, or SQLAlchemy's models). How to anticipate refactoring in Python and write code that is easy to refactor? Things that worked well so far: - verbose names. Longer variable or function name is less likely to collide with others within a project. Helps to quickly find all places in the project where the variable or function is used. - ending variable names with _type. Example: `current_user`. Searching for `user.last_login_date` will surface `current_user.last_login_date` too.
Comments
Post a Comment