Ingo Steinke is a Berlin-based senior web developer focusing on front-end web development to create and improve websites and make the web more accessible, sustainable, and user-friendly.
Learn something new every day.
- I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
Location
Buenos Aires
Education
Computer Science Degree at Universidad de Buenos Aires
I love coding and what motivates me is problem-solving and preferably if it has an element of creativity.
I am a self-taught developer and work full-time as a front-end developer.
Location
Denmark 🇩🇰
Education
Bachelor in Nutrition and health (I know not super relevant to my current line of work!)
But we are not always writing the data or code with null ourselves.
One example: Auto-generated types made with GraphQL Code Generator.
We still need to be able to handle null.
Null does indeed make sense if you do not know if data will return empty.
Why is this a problem specifically before a side-effect?
Something like myFunc?.() will force people to pause. On the other hand short-circuits are a common pattern when setting default values or optionally rendering React components. People are used to reading them in other contexts, often with function calls on the right, so why do they become less readable in this one?
We're a place where coders share, stay up-to-date and grow their careers.
What about optional chaining? Which of course only works with functions designed to be chained, like
user?.isValid()?.logUserIn();I'd use that for finding a deep value but not performing an action:
Also, the implication in your example is that
isValid()returns a user object when that's not obvious - it looks like it should be a boolean.It has to be a boolean, boolean is how the data is first made.
The condition essentially evaluates to a boolean value, determining whether the nested property user.foo.bar exists and is truthy.
I am also engineer. Can we discuss more details?
Null is the worst code smell
And optional chaining, IMHO hids this antipattern.
I've written a smell on optional chaining. I will publish it in the following weeks
hackernoon.com/null-the-billion-do...
And optional chaining is another code smell
Code Smell 149 - Optional Chaining
Maxi Contieri ・ Jul 16 ・ 2 min read
But we are not always writing the data or code with null ourselves.
One example: Auto-generated types made with GraphQL Code Generator.
We still need to be able to handle null.
Null does indeed make sense if you do not know if data will return empty.
Why is this a problem specifically before a side-effect?
Something like myFunc?.() will force people to pause. On the other hand short-circuits are a common pattern when setting default values or optionally rendering React components. People are used to reading them in other contexts, often with function calls on the right, so why do they become less readable in this one?