Godot-docs: String.empty() documentation unclear

Created on 4 May 2019  路  3Comments  路  Source: godotengine/godot-docs

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==""

junior job

All 3 comments

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

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...

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?

Was this page helpful?
0 / 5 - 0 ratings