#๐Ÿ”’ Code review

16 messages ยท Page 1 of 1 (latest)

heady crystalBOT
#

@tulip quail

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

tulip quail
#

Appreciate any edits or review to make the program run faster or fix any innacuracies.

formal ether
#

you are not using that is_pickleable helper function anywhere? nor using pickle at all for that matter

though tbh I would recommend against using pickle overall, and even if you were using it somewhere, it'd probably make more sense to try: except: directly there instead of using that helper function

tulip quail
#

I had it because I was trying to diagnose problems trying to make the program more multiprocessed and using queue

formal ether
#

instead of r = result, I'd just use result - you should be able to duplicate a line, copy/paste or use autocomplete instead of having to type the entire word

collections.Counter might let you do some more operations in fewer lines of code and marginally faster, but would be more complexity overall, e.g. ```py
self.hole_card_stats[player_hole_string]['wins'] += player_hole_stats[player_hole_string]['wins']
self.hole_card_stats[player_hole_string]['losses'] += player_hole_stats[player_hole_string]['losses']
self.hole_card_stats[player_hole_string]['ties'] += player_hole_stats[player_hole_string]['ties']
self.hole_card_stats[dealer_hole_string]['wins'] += dealer_hole_stats[dealer_hole_string]['wins']
self.hole_card_stats[dealer_hole_string]['losses'] += dealer_hole_stats[dealer_hole_string]['losses']
self.hole_card_stats[dealer_hole_string]['ties'] += dealer_hole_stats[dealer_hole_string]['ties']

iirc could be a single line counter += counter

what is that `d` variable doing in `results_compiler`?

You have a **lot** of imports that are not being used?
#

there also seems to be a lot of code duplication overall, see if you can use loops for some similar operations in some more places

#

that comment style makes it feel a bit rather AI Generated

if it actually is, try to rely less on it and make sure you actually understand what it is doing, and can use it in your own code (e.g. from a quick look at it it seems like the only places that use list compehensions are those that feel likely to be ai generataed)

#

in that topic, I'd also recommend using fewer comments and more docstrings ; potentially splitting your code into more functions and/or classes

#

if you aren't using it yet, also look into tools like ruff

#

and lastly... poorly using multi processing is going to leave you with worse performance than not using it at all

#

oh. came accross one more thing I just cannot ignore```py
except Exception as e:
print(f"Error in deal_hand: {e}")
return None

**never** do that

at the very least do
```py
    except Exception:
        import traceback
        traceback.print_exc()
        return None
``` but preferably don't just `return None` and ignore the error
#

but yeah...... overall you're better off asking for help with specific things and keeping it < 100 lines at a time if possible

It is hard and takes a while to look over entire projects with hundreds/thousands of lines of code, I only looked at it relatively quickly and most of the time we just ignore it given how much commitment it can take to review things properly.

tulip quail
heady crystalBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.