#๐ Code review
16 messages ยท Page 1 of 1 (latest)
@tulip quail
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.
Appreciate any edits or review to make the program run faster or fix any innacuracies.
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
I had it because I was trying to diagnose problems trying to make the program more multiprocessed and using queue
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.
Fair enough, what would you recommend for the multiprocessing part? I'm able to generate results quickly with my producer function pretty easily, its the consumer function thats screwed up because I cant process the results fast enough and I think I need to restucture my entire system for logging data and Im not sure what to do about that.
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.