In Go, it is recommended to avoid using something == nil && len(something) == 0 in an if condition and instead use just len(something) == 0.
Here are a few reasons why:
Simplicity and readability: The expression len(something) == 0 clearly conveys the intent of checking if a variable or collection is empty. It is more concise and easier to understand for other developers reading the code. Including something == nil in the condition adds unnecessary complexity and may confuse readers.
Consistent behavior: In Go, the len() function is specifically designed to handle different types, including slices, arrays, maps, and strings. Using len() directly allows consistency in checking the length of any data structure without the need to handle specific cases for nil.
Avoiding nil checks: Checking something == nil adds an extra condition to handle the case when something is nil, which may or may not be desired or necessary. By focusing only on the length check with len(something) == 0, you eliminate the need for a separate nil check, simplifying the code.
Therefore, it is recommended to use len(something) == 0 to check if something is empty, rather than something == nil && len(something) == 0. This approach enhances code readability, maintains consistency, and avoids unnecessary nil checks in Go.