Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String.empty() documentation unclear #2432

Closed
youreperfect opened this issue May 4, 2019 · 3 comments · Fixed by godotengine/godot#39778
Closed

String.empty() documentation unclear #2432

youreperfect opened this issue May 4, 2019 · 3 comments · Fixed by godotengine/godot#39778
Assignees

Comments

@youreperfect
Copy link

Godot 3.1.1

The documentation for String.empty() currently says:

bool empty()
     Returns true if the string is empty.

but should specify if this is exactl;y the same thing as if str=="" of it it is equivalent to C#'s string.isNullOrWhitespace(str) or some other behavior - and why you would use it instead of if str==""

@clayjohn
Copy link
Member

clayjohn commented May 4, 2019

Here is the definition:
https://github.com/godotengine/godot/blob/01f7166d09662889ae8e3a827ef95c2004ec3e53/core/ustring.h#L311

It returns true when the length of the string equals 0.

Oftentimes with these types of questions the best thing to do is test it out yourself in Godot, its really quick and it saves someone else having to do it for you! No one can answer this off the top of their head anyway so it is very helpful for you to check yourself.

Here is the output by testing:

var s = String()
print(s == "")
print(s.empty())

Prints:

True
True

@youreperfect
Copy link
Author

youreperfect commented May 4, 2019

Thanks - the issue here is about ensuring clear documentation so others, especially newcomers, understand when to use what functions especially when there are multiple ways of doing the same thing.

what I would like the documentation to say, considering its defition, is:
String.empty() is a synonym for String.length == 0
and then say if this is more efficient than str == "" or if its exactly the same efficency in practice. What other use cases would .empty() have over testing for "" etc...

@clayjohn
Copy link
Member

clayjohn commented May 4, 2019

My point was that no users can answer those questions. To get answers you should test it out, see if its faster, see if there are any edge cases and then submit a PR changing the documentation. I understand it is desirable to have such comprehensive information in the docs, I agree. But oftentimes, since you are the only person who currently wants to know, you'll have to figure out the answer yourself and then make a note either here or in a PR.

what I would like the documentation to say, considering its defition, is:
String.empty() is a synonym for String.length == 0
and then say if this is more efficient than str == "" or if its exactly the same efficency in practice. What other use cases would .empty() have over testing for "" etc

May a suggest a for loop testing this out a hundred thousand times with a printed time at the end?

@NathanLovato NathanLovato self-assigned this Jun 8, 2019
Meriipu added a commit to Meriipu/godot that referenced this issue Jun 23, 2020
akien-mga pushed a commit to akien-mga/godot that referenced this issue Jun 24, 2020
huhund pushed a commit to huhund/godot that referenced this issue Nov 10, 2020
edg1000 pushed a commit to edg1000/https-github.com-godotengine-godot that referenced this issue Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants