Qt’s QList class provides several methods for getting the number of items in the list – count, length, and size. As we all know, consistency is important, so which should be the canonical/preferred method to use of those 3?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I agree with everything @Cogwheel said, but in all honesty I would just pick one and stick with it. I think good style would dictate that if “size” sounds the best to you, then use “size” everywhere…don’t alternate between “count”, “length” and “size” haphazardly. That will lead to potential confusion or a lot of unnecessary trips to documentation pages.
You could try to come up with some other kind of rationale, but the language itself isn’t even consistent. All the STL containers (e.g.
list,vector) only provide “size”, thestringclass provides “size” and “length”, etc.Pick your favorite (or if you have multiple developers, you should all agree on a favorite) and just stick with it.