CodeSOD: High Strung Note

CodeSOD: High Strung

Many programming languages offer convenience functions to check if a string is null or empty. C# also has such a function, but developers can still implement it incorrectly. Jason's StringValid function, while functional, is inefficient as it uses an unnecessary conditional statement. A better approach would be to directly return the boolean expression or use the built-in functionality. Derek's approach uses a one-liner "".Equals(Port) which is a reversed and less intuitive way to check for nullity. This pattern was found scattered throughout the codebase, suggesting the use of a code snippet. The inverted "".Equals syntax might have been influenced by languages like Python. Malfist's Java example involves a function named checkNull which is misleadingly named. This function is actually a coalesce function that returns a default string if the input is null. A significant flaw is that it trims the non-null input string but not the default string. Furthermore, it doesn't validate if the default string itself is null, potentially leading to further null reference exceptions. The author expresses frustration with the complexities of string handling, suggesting their abolition.