Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
iterator -> const_iterator #299
@zigurana Not sure how to answer that when you ask for something more readable and suggests something less readable. Also using auto leaves it up to the compiler to figure out what you want, which has a negative effect on compile time, and adds the risk of the compiler choosing wrong ( which it did )
Sorry, didn't mean to come across rude. Sunday mornings are not my best
Regarding readability: the
It might just be my personal preference getting in the way, but this seems to me a change that has little or no functional effect, but comes at the cost of legibility.
In any case, while I really appreciate your ongoing effort to further optimize the code base, I would like some discussion on what other things are on your roadmap, other than the final destination (world domination, I believe?). I'd like to be a part of that new world order as well, please.
@zigurana I really don't understand what your problem is with this PR, I changed 296 lines, 2 of those were auto -> whatever::const_iterator, did you even bother to read the changes? Did you even notice that 99% of the changes are begin/end -> cbegin/cend that return to an auto? The 2 auto changes was due to std::find always returning ::iterator so auto always became that, and it needed to be a const_iterator, so I changed those 2 lines.
(sigh), now I've antagonised you, which was never my intention .
Yes, I've looked at your changes, and yes I saw that only few were about the auto keyword.
My reason for asking was to understand why you would want to take the effort to make those changes (to const_iters). Maybe for you this is an obvious thing to do, but for me it's not. I was reaching out clarify that. My initial message was somewhat terse, for which I do apologize again.
But my question still stands. In my view the biggest problem with the codebase at the moment is a lack of readability, and so I assess most of the changes in that perspective.
If you have another reason to make these changes, please explain. I am only trying to learn here.
I'm sorry I overreacted, my plan is not fully laid out yet, it changes every day. But it's a huge task to go through.
Anyway, const is useful because it ensures the coder didn't make a mistake and does changes to a variable that shouldn't be changed, and it shows the reader of the code that this variable is not something that he should be changing.
And regarding auto, I never liked auto, it tells me nothing, I have no idea what type the variable is if it's just auto. I also dislike things like, as example:
It's way too long, what I would do is add a typedef to CollectionSystemManager:
That would shorten down a lot of code in a lot of places, and it would still tell me what it is, which auto wouldn't. Sure auto would be even shorter, but it can't be used everywhere, like here:
And this instead of auto would compile faster because the compiler doesn't have to figure out what to replace auto with.
Hey, thanks for taking the time to explain this to me, I really appreciate it!
So we use the const iterators both as a protective measure and as a way to signal that we are not going to change the thing that iterator points to, got it.
I really like the idea of introducing typedefs to shorten the type specifiers.
What do you think of using the range-based for loop?
As you might have gathered by now, I am not a programmer by training, so I am definitely deferring to your insights here. Again, thank you for your time.