Which is more efficient for the compiler and the best practice for checking whether a string is blank?
In languages that use C-style (null-terminated) strings, comparing to ""
will be faster. That's an O(1) operation, while taking the length of a C-style string is O(n).
In languages that store length as part of the string object (C#, Java, ...) checking the length is also O(1). In this case, directly checking the length is faster, because it avoids the overhead of constructing the new empty string.