this post was submitted on 04 Jul 2023
1 points (100.0% liked)
Programming
13376 readers
1 users here now
All things programming and coding related. Subcommunity of Technology.
This community's icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Thank you. Just the fact that you took all the effort into commenting is enough for me, thank you.
I didn't really implement comments since I didn't think it would expand that much (same goes for the namespace). As for some things which are unclear,
number_matrix
is a matrix I used to randomly generate the numbers that each horse would have to represent how fast they go, I didn't know exactly how to create a random matrix where each number was unique using random, so I just added each previous number into a vector and checked if that number already exists there. The reason I did this (at the time) was because I REALLY didn't want for the programmer to have access to the numbers, so I'd rather them being in a class that they can't even access (protected constructor) and otherwise the numbers were hidden in the Horse private structure with the only way to interact with them being the two Race function (essentially sort functions)Also, I didn't use sets, because I remember doing a problem in LeetCode and when I used them there the Memory part of the submission was so bad that it essentially said that it only beats 0.5%, when I replaced them with a vector for the same function the memory recuperated back to 56% (I know that really the difference is only a few KBs of memory, but it still traumatized me haha )
I'll try to adress these issues and then I'll try to make another release on Github, although you might think that might be a waste of time on such a problem, I have nothing better to do since it's summer vacation.
I'm trying to learn programming, and it's more of a hobby for now since I'm still not in University yet, although this year might be if they accept me (still waiting for admission results)
My personal preference is to leave comments where it's not directly clear what the code does. Using "good" variable & function names can make the code usually somewhat self-documenting, but that's not always enough.
Yeah I understood why you used that approach, and I'm not a c++ expert myself, just wanted to point out some other options.
It makes no difference visibility-wise if you have a variable that is local to a function vs a private member of a class that's just used by said function.
Huh, that sounds odd. Never done anything with LeetCode, but would be interested into seeing what was going on there. If you want to use sets, check whether you need ordering (most likely you don't) and go with
std::unordered_map
.Absolutely not. I see lots of value of optimizing and cleaning up code, there is so much to learn which will help you write better code in the future. I have a bunch of programming projects that I never fully finished and you could also call them a waste of time - who would play with my gameboy emulator without gui etc? No one besides me :) But it was more about the journey and learning things. So go for it and code things you find interesting, that's a good way to stay motivated.
Good luck with admissions. Putting effort into it in your spare time and as a hobby is great and shows dedication, exposing your code to "the internet" and asking others for feedback is also a great way to grow - way to go!