Open-event-server: Many variables have name of Python Built-in Functions

Created on 13 Jun 2018  路  4Comments  路  Source: fossasia/open-event-server

Describe the bug
Many variables used throughout the codebase have names that are used to call Python's built-in functions (BIFs), e.g., the hash() BIF here: https://github.com/fossasia/open-event-server/blob/1e442e4539339dda46ae93933fff0201310a76f1/app/models/invite.py#L14

To Reproduce
Explore the codebase, and search for common BIF names

Expected behavior
These names should be different from BIFs' names, otherwise at some point later, the codebase might function unexpectedly, e.g, it can return the hash attribute of some object when what we really need is the hash() BIF. However, this practice doesn't usually confuse the interpreter but is still considered bad for multiple reasons.
Learn more.

I'm working on changing this.

Most helpful comment

I think it would take a lot of effort since Python is loosely typed and will introduce a lot of bugs. Right now, we may tackle bugs related to this as they pop up

All 4 comments

Since many models have attributes with the same names of BIFs', the simplest solution would be to append an underscore (as is the standard practice). However, this will change the corresponding column names in the DB as well. To avoid changing names in the DB, we can do something like

id_ = db.Column('id', db.Integer, nullable=False)

But this will cause a mismatch between attribute names and DB columns, so I think just appending an underscore (both in the codebase and the DB) would be the way to go.

Thoughts @srv-twry @iamareebjamal @mayank8318?

I think it would take a lot of effort since Python is loosely typed and will introduce a lot of bugs. Right now, we may tackle bugs related to this as they pop up

@iamareebjamal Okay, thanks. So should I close this now or perform the name changes for some of the variables I observed?

Also, just curious, how is this problem related to Python being loosely typed?

Because if it wasn't, you could change all the variable names and compilation errors would occur. If you solved all compilation errors, you'd be confident that the refactoring is complete. Now, if you change variable names, there is no way to know if there is a bug or not until and unless that particular file and code runs and throws a runtime exception

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dr0pdb picture dr0pdb  路  4Comments

mariobehling picture mariobehling  路  4Comments

CosmicCoder96 picture CosmicCoder96  路  3Comments

Aju100 picture Aju100  路  4Comments

Masquerade0097 picture Masquerade0097  路  3Comments