I’ve noticed a tendency to use the Elvis operator (?.) in Angular for almost every backend response, regardless of whether it’s expected to be null or not. Here are my concerns and questions:
-
Expected Values: I believe it’s fine to use the Elvis operator where
the value might reasonably be null or incorrect, but it seems
unnecessary where we don’t expect the backend to return an incorrect
result unless the server crashes. Is my understanding correct? -
Code Readability: Overusing the Elvis operator can make the code
look cluttered and harder to read. When every response is handled
with ?., it creates uncertainty about whether any value or object
might be null. Does anyone else find this approach impacts code
readability, and how do you balance its use? -
Performance Impact: Does the extensive use of the Elvis operator
have any notable impact on performance? I assume it’s minimal, but
I’d like to hear from others with more experience. -
Best Practices: What are the best practices for using the Elvis
operator in Angular? Are there guidelines or criteria that you
follow to decide when and where to use it?
I appreciate any insights or experiences you can share. Thanks!