Skip to content
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

WIP: Minor code improvements #67

Closed
wants to merge 11 commits into from
Closed

WIP: Minor code improvements #67

wants to merge 11 commits into from

Commits on Feb 26, 2021

  1. Use empty call to super() and use str.format

    Use an emptry call to `super()` instead of hardcoding the arguments.
    Also use str.format instead of the % operator. This was chosen instead
    of f-strings since it allows to use the equivalent of %g.
    Solomon1732 committed Feb 26, 2021
    Configuration menu
    Copy the full SHA
    32d3cde View commit details
    Browse the repository at this point in the history
  2. Modify loop structures in some functions

    Modified loop structures in some functions. Instead of constructing the
    lists one element at the time, iterators, genexprs, and list comprehensions are used in order to make the list building more efficient.
    Solomon1732 committed Feb 26, 2021
    Configuration menu
    Copy the full SHA
    c83089d View commit details
    Browse the repository at this point in the history
  3. Modify functions' internal list handling

    Modified functions' internal list handlings. Instead of using
    temporary lists or building lists by repeatedly appending items, the
    modified functions now use list comprehensions, `list.extend`,
    genexps, and iterators to more efficiently build lists.
    
    Removed some declarations of `object` as parent class.
    
    Modified `PriceLevelList.insert` to use `bisect.insort` to avoid having
    to sort the list at each item insertion.
    
    Replace explicit super() calls with no args calls
    
    Replaced explicit calls to `super()` with either the no arguments
    version or outright deleted.
    
    Minor refractoring to reduce code reduplication
    
    Minor refractoring to reduce code reduplication.
    Solomon1732 committed Feb 26, 2021
    Configuration menu
    Copy the full SHA
    f6c1f26 View commit details
    Browse the repository at this point in the history
  4. Change % string oprator to alternatives

    Changed % string operator occurances to f-string when possible, or to
    `str.format` when not.
    Solomon1732 committed Feb 26, 2021
    Configuration menu
    Copy the full SHA
    3c641b6 View commit details
    Browse the repository at this point in the history
  5. Change the structure of a few functions

    Changed the structure of a few functions, namely orderbook's __str__
    function. Reduces code duplication. Also changed _get_order_ids_iter and
    _get_price_level_iter.
    Solomon1732 committed Feb 26, 2021
    Configuration menu
    Copy the full SHA
    1d9ada2 View commit details
    Browse the repository at this point in the history
  6. Remove object as parent class

    Removed `object` as parent class from various classes. This is because
    it is redundant in python 3.
    Solomon1732 committed Feb 26, 2021
    Configuration menu
    Copy the full SHA
    ae7be16 View commit details
    Browse the repository at this point in the history
  7. Change function to use list comprehention

    Changed function to use list comprehention instead of appending to the
    list one element at a time.
    
    Change how some functions work
    
    In `BlockCache.get_missing_in_range` used list comprehention instead of
    manually appending to a new list in a loop.
    
    In `OrderBook._get_order_ids` used `map` instead of manually yielding
    in a loop.
    
    In `MatchPriorityQueue` used a `namedtuple` as the element of the internal
    `queue` list. Used `any` with a generator expression in `contains_order`
    instead of the loop with `_, _, other_order_id, _` destructuring,
    utilizing the introduced `namedtuple`. In `insert` utilized the new
    `namedtuple` in the internal `cmp_items` function for maintainability
    and readability. Also in `insert` instead of creating a new sorted list
    for `self.queue` the queue is sorted in-place.
    Solomon1732 committed Feb 26, 2021
    Configuration menu
    Copy the full SHA
    0c5f2c9 View commit details
    Browse the repository at this point in the history
  8. Use next with default value None

    Used `next` with a default value of `None` instead of using `try-except`
    on `StopIteration`.
    
    Removed `u` prefix from string. The prefix is superfluous in python 3.
    
    Instead of checking `current_version` against individual numbers it is
    checked against a tuple of values.
    
    Change parameterized `super()` to empty `super()`
    
    Instead of calling `super()` with explicit parameter, an empty call to
    it is made instead.
    Solomon1732 committed Feb 26, 2021
    Configuration menu
    Copy the full SHA
    21d790a View commit details
    Browse the repository at this point in the history
  9. Change ValueError to TypeError when appropriate

    Changed the raising of ValueError to TypeError when appropriate. Namely
    when an argument's type is checked. Likewise changed the tests to match
    the new exceptions thrown.
    
    In `bitcoinlib_main.py` moved some software structures out of a file's
    `with` statement in order to not hold the file open longer than
    necessary. In addition restructured a for-loop in a minor way in order
    to decrease the indentation level of the loop's body.
    Solomon1732 committed Feb 26, 2021
    Configuration menu
    Copy the full SHA
    15c965a View commit details
    Browse the repository at this point in the history
  10. Modify PriceLevelList to utilize bisect

    Modified PriceLevelList to utilize bisect for various methods. In
    addition, modified the class to raise IndexError manually in some cases
    so as to hide implementation details.
    Solomon1732 committed Feb 26, 2021
    Configuration menu
    Copy the full SHA
    6d2fa62 View commit details
    Browse the repository at this point in the history
  11. Add a comment to improve code readability

    Added a comment to improve code readability and highlight the difference
    between the two if cases.
    
    Also made the two cases one-liners.
    Solomon1732 committed Feb 26, 2021
    Configuration menu
    Copy the full SHA
    b451598 View commit details
    Browse the repository at this point in the history