Timeline for Compressed output of set in Python
Current License: CC BY-SA 4.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 26, 2023 at 9:28 | comment | added | Looser User |
I'm still not completely decided whether I use the class or the proc approach. I's not that I object the proc approach. It's just that I was confronted very often with repetitive code which spreads pod's and dict accesses all over and I wished people used more type sane and reusable code being it a set of classes or even procedures. Anyway, there's a drawback in my derived class I didn't see before. The intersection , union and such do not work as expected, returning the original set instead of the PrettySet . A proc would free me from the need to implement those overloads.
|
|
Jan 25, 2023 at 23:27 | comment | added | AJNeufeld |
@LooserUser Based on the usage shown in the question as posted, with print(PrettySet(data)) , the "Stop Writing Classes" feedback is correct. In future questions, post all relevant code (ie, both the utility and usages of the utility) to get feedback relevant to your real question instead of a toy example.
|
|
Jan 25, 2023 at 13:58 | comment | added | Looser User |
The actual usecase of this class is to be used as a set . However, I needed some improved output for logging purposes to prevent sth like: WARNING:root:Something happened on ports {1, 2, 3, 4, 5, 6, 7, 8, ..., 20} . Therefor, I replaced the original set containing a subset of ports by the PrettySet class. This way I can log failing ports without thinking about output format on each and every logger.warning(f"blabla {failing_ports}") . I also watched the video, which makes some good points, but I think it's biased as it misses any discussion of the drawbacks of the procedural approach.
|
|
Jan 23, 2023 at 8:51 | comment | added | M472 |
When I first saw the original code I also thought this was yet another class that should actually be just a function. But in this case I see a real benefit of the class because you can pass the PrettySet instance around and it will pretty print everywhere it is printed.
|
|
Jan 23, 2023 at 4:26 | history | answered | AJNeufeld | CC BY-SA 4.0 |