subtle bug magnet --> std::vector's clear() and empty()
-
Bring me the head of the person who decided on the names
clear()
andempty()
forstd::vector
! :mad: The two functions work as they are documented, but having such confusing names is a recipe for creating bugs - I'm sure I'm not the only person who has writtenempty()
when I should have writtenclear()
(i.e. when I'm trying to get rid of the contents of the vector - but instead just return abool
into thin air) According to the dictionary: empty[^] can be both an adjective "2. vacant; unoccupied: an empty house." and a verb "12. to make empty; deprive of contents; discharge the contents of: to empty a bucket" so if you were reading some unknown code and saw a function ABC.empty() you would be perfectly correct to interpret the meaning as either a test or an action, which is why this is a bad choice for a function name. What should the STL have done? usedMakeEmpty()
andIsEmpty()
or at leastEmpty()
andIsEmpty()
like the CString designers did. Rant over.:sigh:
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
-
Bring me the head of the person who decided on the names
clear()
andempty()
forstd::vector
! :mad: The two functions work as they are documented, but having such confusing names is a recipe for creating bugs - I'm sure I'm not the only person who has writtenempty()
when I should have writtenclear()
(i.e. when I'm trying to get rid of the contents of the vector - but instead just return abool
into thin air) According to the dictionary: empty[^] can be both an adjective "2. vacant; unoccupied: an empty house." and a verb "12. to make empty; deprive of contents; discharge the contents of: to empty a bucket" so if you were reading some unknown code and saw a function ABC.empty() you would be perfectly correct to interpret the meaning as either a test or an action, which is why this is a bad choice for a function name. What should the STL have done? usedMakeEmpty()
andIsEmpty()
or at leastEmpty()
andIsEmpty()
like the CString designers did. Rant over.:sigh:
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
I got confused first time but that was before reading the docs. I will not call it a subtle bug though
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
-
I got confused first time but that was before reading the docs. I will not call it a subtle bug though
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
Rama Krishna Vavilala wrote:
I will not call it a subtle bug though
It's not a bug in itself, but it's a fertile ground for writing your own (e.g. clearing out a vector that is usually, but not always, empty). It lets you write code that reads like it will work, and might not be noticed all of the time - which is my definition of a "subtle bug" (but I can understand if you disagree). Warren
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
-
Bring me the head of the person who decided on the names
clear()
andempty()
forstd::vector
! :mad: The two functions work as they are documented, but having such confusing names is a recipe for creating bugs - I'm sure I'm not the only person who has writtenempty()
when I should have writtenclear()
(i.e. when I'm trying to get rid of the contents of the vector - but instead just return abool
into thin air) According to the dictionary: empty[^] can be both an adjective "2. vacant; unoccupied: an empty house." and a verb "12. to make empty; deprive of contents; discharge the contents of: to empty a bucket" so if you were reading some unknown code and saw a function ABC.empty() you would be perfectly correct to interpret the meaning as either a test or an action, which is why this is a bad choice for a function name. What should the STL have done? usedMakeEmpty()
andIsEmpty()
or at leastEmpty()
andIsEmpty()
like the CString designers did. Rant over.:sigh:
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
Are you saying that Plain English ® has failed you? Heretic, I say. ;P
Chris Meech I am Canadian. [heard in a local bar] I agree with you that my argument is useless. [Red Stateler] Hey, I am part of a special bread, we are called smart people [Captain See Sharp] The zen of the soapbox is hard to attain...[Jörgen Sigvardsson] I wish I could remember what it was like to only have a short term memory.[David Kentley]
-
Are you saying that Plain English ® has failed you? Heretic, I say. ;P
Chris Meech I am Canadian. [heard in a local bar] I agree with you that my argument is useless. [Red Stateler] Hey, I am part of a special bread, we are called smart people [Captain See Sharp] The zen of the soapbox is hard to attain...[Jörgen Sigvardsson] I wish I could remember what it was like to only have a short term memory.[David Kentley]
Yeah, on second thought this C++ thing isn't working out for me. I guess I'll start porting everything to Plain English after lunch... :-D
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
-
Bring me the head of the person who decided on the names
clear()
andempty()
forstd::vector
! :mad: The two functions work as they are documented, but having such confusing names is a recipe for creating bugs - I'm sure I'm not the only person who has writtenempty()
when I should have writtenclear()
(i.e. when I'm trying to get rid of the contents of the vector - but instead just return abool
into thin air) According to the dictionary: empty[^] can be both an adjective "2. vacant; unoccupied: an empty house." and a verb "12. to make empty; deprive of contents; discharge the contents of: to empty a bucket" so if you were reading some unknown code and saw a function ABC.empty() you would be perfectly correct to interpret the meaning as either a test or an action, which is why this is a bad choice for a function name. What should the STL have done? usedMakeEmpty()
andIsEmpty()
or at leastEmpty()
andIsEmpty()
like the CString designers did. Rant over.:sigh:
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
Reminds me of a thread somewhere here not long ago, when someone was asking what properties was good for. This is one thing that properties is good for. If it was a .NET class (for example), Empty would have been a (read-only) property instead of a method (and also named IsEmpty instead). Being a property, one would not expect it to change the data in the class. But, as some people in the thread argued, as the properties are just another way of writing getters and setters, we could just as well have a getter for the value, named get_empty(). Hmm... would it be logical that a method by that name would return the status of the emptiness of the class, or would it be more logical that it would factor a new empty vector? ;)
--- b { font-weight: normal; }
-
Yeah, on second thought this C++ thing isn't working out for me. I guess I'll start porting everything to Plain English after lunch... :-D
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
Warren Stevens wrote:
I guess I'll start porting everything to Plain English after lunch...
Where you can say:
Clear the desk.
Empty the desk.
If the desk is empty...
If the desk is clear...and a variety of similar things that will all work in the obvious (and intended way).
-
Warren Stevens wrote:
I guess I'll start porting everything to Plain English after lunch...
Where you can say:
Clear the desk.
Empty the desk.
If the desk is empty...
If the desk is clear...and a variety of similar things that will all work in the obvious (and intended way).
Hey, if it really works as well as that, then you'll have a lot of converts in the end.
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
-
Reminds me of a thread somewhere here not long ago, when someone was asking what properties was good for. This is one thing that properties is good for. If it was a .NET class (for example), Empty would have been a (read-only) property instead of a method (and also named IsEmpty instead). Being a property, one would not expect it to change the data in the class. But, as some people in the thread argued, as the properties are just another way of writing getters and setters, we could just as well have a getter for the value, named get_empty(). Hmm... would it be logical that a method by that name would return the status of the emptiness of the class, or would it be more logical that it would factor a new empty vector? ;)
--- b { font-weight: normal; }
Guffa wrote:
someone was asking what properties was good for.
Properties rock! Since I usually write in c++, I'm really jealous of the properties in C#, and a bunch of other things too (like being able to write everything in one file, instead of having to maintain function names and parameters in two places (.h and .cpp)).
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
-
Guffa wrote:
someone was asking what properties was good for.
Properties rock! Since I usually write in c++, I'm really jealous of the properties in C#, and a bunch of other things too (like being able to write everything in one file, instead of having to maintain function names and parameters in two places (.h and .cpp)).
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
Warren Stevens wrote:
I'm really jealous of the properties in C#, and a bunch of other things too (like being able to write everything in one file, instead of having to maintain function names and parameters in two places (.h and .cpp)).
Yeah, that is a bit primitive for the 21st century. How does "no headers at all and the sequence in which you define things doesn't matter" sound to you?
-
Bring me the head of the person who decided on the names
clear()
andempty()
forstd::vector
! :mad: The two functions work as they are documented, but having such confusing names is a recipe for creating bugs - I'm sure I'm not the only person who has writtenempty()
when I should have writtenclear()
(i.e. when I'm trying to get rid of the contents of the vector - but instead just return abool
into thin air) According to the dictionary: empty[^] can be both an adjective "2. vacant; unoccupied: an empty house." and a verb "12. to make empty; deprive of contents; discharge the contents of: to empty a bucket" so if you were reading some unknown code and saw a function ABC.empty() you would be perfectly correct to interpret the meaning as either a test or an action, which is why this is a bad choice for a function name. What should the STL have done? usedMakeEmpty()
andIsEmpty()
or at leastEmpty()
andIsEmpty()
like the CString designers did. Rant over.:sigh:
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
That is a constant annoyance for me, the naming scheme is bad in subtle ways that can trip up newbies. My 2nd most-hated is
begin()
andend()
: methods whose names are verbs but which don't actually do any actions.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
Warren Stevens wrote:
I guess I'll start porting everything to Plain English after lunch...
Where you can say:
Clear the desk.
Empty the desk.
If the desk is empty...
If the desk is clear...and a variety of similar things that will all work in the obvious (and intended way).
perfect idiots never understand when we explain them to stop advertise their Plain english crap :( reported as Abusive ! :suss:
Don't know where to start ?
Refer the Forums Guidelines and ask a friend -
Bring me the head of the person who decided on the names
clear()
andempty()
forstd::vector
! :mad: The two functions work as they are documented, but having such confusing names is a recipe for creating bugs - I'm sure I'm not the only person who has writtenempty()
when I should have writtenclear()
(i.e. when I'm trying to get rid of the contents of the vector - but instead just return abool
into thin air) According to the dictionary: empty[^] can be both an adjective "2. vacant; unoccupied: an empty house." and a verb "12. to make empty; deprive of contents; discharge the contents of: to empty a bucket" so if you were reading some unknown code and saw a function ABC.empty() you would be perfectly correct to interpret the meaning as either a test or an action, which is why this is a bad choice for a function name. What should the STL have done? usedMakeEmpty()
andIsEmpty()
or at leastEmpty()
andIsEmpty()
like the CString designers did. Rant over.:sigh:
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
Ah, ambiguity in programming contexts. Yup, I still have to stop and think about these.
Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fruity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain) -
I got confused first time but that was before reading the docs. I will not call it a subtle bug though
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
Rama Krishna Vavilala wrote:
I will not call it a subtle bug though
No, but a subtle-bug-source.
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers!
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify!|Fold With Us! -
Bring me the head of the person who decided on the names
clear()
andempty()
forstd::vector
! :mad: The two functions work as they are documented, but having such confusing names is a recipe for creating bugs - I'm sure I'm not the only person who has writtenempty()
when I should have writtenclear()
(i.e. when I'm trying to get rid of the contents of the vector - but instead just return abool
into thin air) According to the dictionary: empty[^] can be both an adjective "2. vacant; unoccupied: an empty house." and a verb "12. to make empty; deprive of contents; discharge the contents of: to empty a bucket" so if you were reading some unknown code and saw a function ABC.empty() you would be perfectly correct to interpret the meaning as either a test or an action, which is why this is a bad choice for a function name. What should the STL have done? usedMakeEmpty()
andIsEmpty()
or at leastEmpty()
andIsEmpty()
like the CString designers did. Rant over.:sigh:
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
Warren Stevens wrote:
What should the STL have done? used MakeEmpty() and IsEmpty() or at least Empty() and IsEmpty() like the CString designers did.
is_empty()
if you ask me, but I agree - STL names are very strange.
-
Warren Stevens wrote:
I guess I'll start porting everything to Plain English after lunch...
Where you can say:
Clear the desk.
Empty the desk.
If the desk is empty...
If the desk is clear...and a variety of similar things that will all work in the obvious (and intended way).
The Grand Negus wrote:
a
So the first one is if nothing is on the desk, and the second one means that you can see through it? ;P
The pig go. Go is to the fountain. The pig put foot. Grunt. Foot in what? ketchup. The dove fly. Fly is in sky. The dove drop something. The something on the pig. The pig disgusting. The pig rattle. Rattle with dove. The dove angry. The pig leave. The dove produce. Produce is chicken wing. With wing bark. No Quack. - Thedailywtf.com
-
perfect idiots never understand when we explain them to stop advertise their Plain english crap :( reported as Abusive ! :suss:
Don't know where to start ?
Refer the Forums Guidelines and ask a friendtoxcct wrote:
perfect idiots never understand when we explain them to stop advertise their Plain english crap
:laugh:
Some people have a memory and an attention span, you should try them out one day. - Jeremy Falcon
-
Bring me the head of the person who decided on the names
clear()
andempty()
forstd::vector
! :mad: The two functions work as they are documented, but having such confusing names is a recipe for creating bugs - I'm sure I'm not the only person who has writtenempty()
when I should have writtenclear()
(i.e. when I'm trying to get rid of the contents of the vector - but instead just return abool
into thin air) According to the dictionary: empty[^] can be both an adjective "2. vacant; unoccupied: an empty house." and a verb "12. to make empty; deprive of contents; discharge the contents of: to empty a bucket" so if you were reading some unknown code and saw a function ABC.empty() you would be perfectly correct to interpret the meaning as either a test or an action, which is why this is a bad choice for a function name. What should the STL have done? usedMakeEmpty()
andIsEmpty()
or at leastEmpty()
andIsEmpty()
like the CString designers did. Rant over.:sigh:
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
-
Guffa wrote:
someone was asking what properties was good for.
Properties rock! Since I usually write in c++, I'm really jealous of the properties in C#, and a bunch of other things too (like being able to write everything in one file, instead of having to maintain function names and parameters in two places (.h and .cpp)).
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
Warren Stevens wrote:
like being able to write everything in one file, instead of having to maintain function names and parameters in two places (.h and .cpp)).
You don't HAVE to put things in 2 files ... it is done out of convience for the most part. You CAN put everything for a class in a .h file if you really wanted to.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
-
Warren Stevens wrote:
like being able to write everything in one file, instead of having to maintain function names and parameters in two places (.h and .cpp)).
You don't HAVE to put things in 2 files ... it is done out of convience for the most part. You CAN put everything for a class in a .h file if you really wanted to.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
Zac Howland wrote:
You don't HAVE to put things in 2 files ... it is done out of convience for the most part. You CAN put everything for a class in a .h file if you really wanted to.
Only in the most trivial cases. As soon as your project gets to a decent size, you do NOT want to touch a widely used .h file (or it takes forever to compile), which is why the split is needed. Also, if you have two classes that use functions of each other (which isn't that uncommon) the only way to do so is to use a forward declaration and two .h and .cpp files. :)
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)