-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible minor code improvements #63
Comments
Looking through the code I ran into # This
def contains_order(self, order_id):
for _, _, other_order_id, _ in self.queue:
if other_order_id == order_id:
return True
return False
# Might look like this
def contains_order(self, order_id):
for other_order in self.queue:
if other_order.id == order_id:
return True
return False |
https://github.com/Tribler/anydex-core/blob/master/anydex/core/database.py#L128 def get_order(self, order_id):
"""
Return an order with a specific id.
"""
db_result = next(
self.execute(
"SELECT * FROM orders WHERE trader_id = ? AND order_number = ?",
database_blob(bytes(order_id.trader_id), str(order_id.order_number))
),
# This is an optional default value which can be returned
None,
)
return None if db_result is None else Order.from_database(db_result, self.get_reserved_ticks(order_id)) This prevents the need to set up a try-except for Edit: Replace
|
Thanks for your suggestions! Recently, the ideas implemented in this repository (low-risk, universal asset trading) have been accepted for publication. Also, the matchmaking logic has recently been published. I think further improvements can be made to the exchange mechanism but we consider the fundamental work as finished. As such, the future plans of this repository are not clear yet. Even though we highly value any contribution, your time might be better spent working on one of our other projects, for example, Tribler, our mobile superapp or our accountability toolbox. This would also depend on how much time you would like to invest into one of our projects, and your interests/expertise 👍 . Do you have any preferences/ideas? |
Gotcha. Happy to help! I have just above beginner skills in python, and I can read C code, but that's it. Do you have any suggestions? |
It depends also on what you like to work on. You can, for example:
|
In mind I have a small number of possible (minor) improvements:
Replace
%
string operators with f-stringsUsing the
%
operator is somewhat brittle AFAIK, and can arguably be less readable.Example:
https://github.com/Tribler/anydex-core/blob/master/anydex/core/tickentry.py#L144
Replace list comprehensions in
str.join
with generator expressionsBuilding a list for a
str.join
statement is an operation which can be skipped. Instead it can be replaced with a generator expression.Example:
https://github.com/Tribler/anydex-core/blob/master/anydex/core/match_queue.py#L13
Remove
object
as parent classSince the default parent class of new classes in Py3 is
object
by default, such a declaration became redundant. Such declarations can be deleted with no adverse effects.Example:
https://github.com/Tribler/anydex-core/blob/master/anydex/core/settings.py
Are points 1 and 3 artifacts from transitioning from Py2 to Py3?
I know these are all minor points. I don't mind creating one or more PRs for what I suggested, and in fact I'll be glad to make them since I am aware that such issues are of a low priority.
Edit:
Replace two argument form calls to
super()
with the zero argument form when appropriatehttps://docs.python.org/3/library/functions.html#super
https://stackoverflow.com/a/576183
Code such as
can be replaced with
The two are equivalent.
Example:
https://github.com/Tribler/anydex-core/blob/master/anydex/core/message.py#L13
The text was updated successfully, but these errors were encountered: