Jul 24, 2021 10:03 PM
(This post was last modified: Aug 18, 2021 12:42 AM by Canonsx130.)
no longer require answersto this thread. deleting the contents for some reasons
|
Python
How good is my code/code structure? |
|
Jul 24, 2021 10:03 PM
(This post was last modified: Aug 18, 2021 12:42 AM by Canonsx130.)
no longer require answersto this thread. deleting the contents for some reasons
Your code is just fine, it's readable and most important - working.
The structure is OK, there is more than one way to do that, the one you did is pretty much the straightforward way, which is OK. The only thing I have in mind is that you didn't take care of the wrong input in "accept_values" function. Yes, I can see that the very last option of the "if section" is saying "Invalid input" but think about that, for given invalid output, the program will ask 6 times "if" before it understands the value is invalid. "accept_values" function name describes itself very well, that function is there to get the values and for sure taking care of all the "bad stuff", that means when you make "return a, b" those values should be valid in any case. There are for sure better ways to create a menu, or even making the whole logic of the program more efficient, I personally love to use "meta-programming" for Menu kind of stuff, but im just mentioning another way to do that, for example, "meta-programming" in that case will be much more efficient in resources but less readable and harder to debug, it's all about the balance :) All in all, well done, keep practicing you're on the right way
Dude .
(Jul 27, 2021 04:25 AM)3phase Wrote: The only thing I have in mind is that you didn't take care of the wrong input in "accept_values" function. Well spotted! Thanks! (Jul 27, 2021 04:25 AM)3phase Wrote: There are for sure better ways to create a menu, or even making the whole logic of the program more efficient, Took a quick look into it and meta-programming looks interesting. However, for this particular challenge, I just wanted an efficient and structured barebones implementation. Giving it another review, perhaps I could've created the hex_grid class as a separate file. Other than that, I couldn't find any problems with my limited knowledge. Perhaps there are better algorithms to generate the grid or calculate distances. But I'm not too bothered about that kind of detail if that makes sense. But anyways, you have been really helpful and have given me some reassurance about my code. Thanks :)
First off, much obliged for commenting what most things do. Always nice to scan through before running just to follow the path and see if it makes sense. :)
The wall of if conditionals bothers me a bit, but is essentially unavoidable in this scenario even with switch/case. No big deal on that. Other than error spec/correction within each operation, it reads and runs fine for me. I'm slowly transitioning into spacing out function arguments and long combinations of conditionals, which that's on a preference basis, but it still reads fine. Far as functionality goes, if it does what it was meant to do, it'll do. (Jul 28, 2021 07:19 PM)Sajuuk Wrote: First off, much obliged for commenting what most things do. Always nice to scan through before running just to follow the path and see if it makes sense. :) Thank you, much appreciated :) |
|
|
| Possibly Related Threads... | |||
| Thread / Author | Replies | Views | Last Post |
| [C] by LynxMay 9, 2021 07:27 AM | 1 | 168 |
May 9, 2021 07:27 AM Last Post: donatellaversace |
| [Python] by Wiked™Sep 19, 2020 10:28 PM | 7 | 223 |
Sep 19, 2020 10:28 PM Last Post: ethelooking |
| [C] by aeiroAug 18, 2018 01:57 PM | 9 | 352 |
Aug 18, 2018 01:57 PM Last Post: aeiro |