6 ms·
Would you mind expanding a little bit on why this is bad ? I'm fairly new to TS and find myself doing it a lot.
by phowat 6y ago
Would you mind expanding a little bit on why this is bad ? I'm fairly new to TS and find myself doing it a lot.
- angio 6y agoThe advantage of the Option type is that you don't need to check for nullability, you simply pattern match on Some(_) or None. A type of `some{T} | undefined` means that the expression can have values `Some(_)` or `None` or `undefined`, which defeats the point of the Option type!
- masklinn 6y agoExcept Erlang doesn't have a none. Nor an undefined for that matter. So `some {T} | undefined` means exactly that, there is no underlying null pointer which could sneak up on you. `undefined` here is not built-in type or value of the language, it's a standard atom like any other. So are null, nil, value or false (although false does have a special status in that it's the customary output of boolean operations alongside true).
- mbo 6y ago> A type of `some{T} | undefined` means that the expression can have values `Some(_)` or `None` or `undefined` Can you please explain this further? Why is `None` an inhabitant of this union?
- btbuildem 6y agoIt can lead to cascading checks for undefined; best case scenario is a lot of boilerplate type code.
- masklinn 6y ago> It can lead to cascading checks for undefined Do you know anything about Erlang? Because unlike typescript, `undefined` in erlang is not a special value, it's just an atom like any other. > best case scenario is a lot of boilerplate type code. Do you know anything about Erlang(2)? Because unlike typescript erlang has pattern matching, both faillible and not. I'm not talking "it can kinda unpack objects", erlang has actual pattern matching (though not unification despite the prolog-inspired syntax), and a simple-looking assignment is a pattern match (and a potential assertion).
- airstrike 6y agoCouple things: personal attacks are not cool, and "please respond to the strongest plausible interpretation of what someone says, not a weaker one that's easier to criticize. Assume good faith." https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html
- masklinn 6y ago> Couple things: personal attacks are not cool, and "please respond to the strongest plausible interpretation of what someone says, not a weaker one that's easier to criticize. Assume good faith." Couple things: asking somebody if they know anything about a subject is not a personal attack, and that GP doesn't know anything about Erlang and completely miunderstands the snippet is the strongest plausible interpretation of their comments which assumes good faith. The alternative interpretations which do not are that they're actively lying, or that they can't be trusted with any device more complicated than a rock or a small stick.
- dang 6y agoIt sounds like you didn't intend it as a personal attack, but inserting rhetorical questions like "Do you know anything about $foo" in an argument about $foo definitely comes across that way on the internet, and isn't allowed here. The fact that you repeated it twice makes it much worse—this is an attempt to expose the other commenter as "someone who doesn't know anything", which is needlessly personal. If you know more than someone else, that's great, but please just share some of what you know so the rest of us can learn. Putting others down (even implicitly) doesn't serve learning, it's just distracting and builds up toxins in the ecosystem. Consider how much better your comment would read without those bits. The best way to react to bad information is respectfully with better information.