News for hackers. Stuff that matters.
Re:How to Build Resilient JavaScript UIs by eatonphil on Wednesday August 04, 2021 @09:53AM (#28061007)
Not trolling: counting on compile time checks in Javascript is the opposite of what I think of as resilient.

Although I'm a huge fan of TypeScript and use it and a bundle in all my UIs, you cannot guarantee that everything was typed correctly or that things haven't escaped being typed.

Sometimes I wonder if the right thing is to actually guard every object from being undefined like this sample. It does seem crazy.

This is basically a problem for every language with metaprogramming/eval/LD_PRELOAD: you can't necessarily truly count on things being defined like you think they are. That also starts getting pretty paranoid but again the topic here is resilience so should you ignore that things can/actually do change under the hood when you don't expect?

Re:How to Build Resilient JavaScript UIs by chrismorgan on Wednesday August 04, 2021 @10:08AM (#28061167)
Error-handling code is the buggiest code out there. You should strongly avoid unnecessary error-checking stuff, because how you handle it will commonly be worse than having just done nothing. As a related example, validating email addresses badly (forbidding valid email addresses) is probably worse than doing nothing (accepting invalid email addresses).

This is an excellent example of necessary error-checking stuff; user-agent feature detection (which includes the browser’s baseline functionality which is basically a completely uncontrolled third-party library, the worst situation by far) is another good example. But it’s extremely easy to take it too far. Any library stuff that gets bundled into your code, you should prefer compile-time to runtime type-checking. But anything outside, yeah, then you have to decide.

Re:How to Build Resilient JavaScript UIs by city41 on Wednesday August 04, 2021 @10:47AM (#28061608)
The code that you locally control and own you can have strong confidence in and type checking can be very valuable. Anything brought in at run time (say a third party lib loaded via a script tag or data fetched from an endpoint) you have no guarantees at all about what it will actually be. You can still use TS to your advantage here and type the third party code/data in such a way that will cause the compiler to encourage you to be more defensive, such as using the unknown type.
Re:How to Build Resilient JavaScript UIs by eatonphil on Wednesday August 04, 2021 @11:08AM (#28061873)
Just because you wrote user input code or an HTTP client does not mean that the results of it are trustworthy. So no I would not agree that even your own code is trustworthy.

If it's your own code that does no IO then yeah it's more ok to trust TypeScript.

Re:How to Build Resilient JavaScript UIs by city41 on Wednesday August 04, 2021 @11:31AM (#28062182)
The HTTP client itself is trustworthy to the extent that static code can be. The data it acquires through requests is not.

Same with user input code. You can trust your implementation to the extent of static type checking and analysis. You can't trust anything a user entered into your system. Those are examples of the externals that I stated you can't trust.

Re:How to Build Resilient JavaScript UIs by schwartzworld on Wednesday August 04, 2021 @11:46AM (#28062375)
If you aren't personally in control of the backend, you have to assume that your backend is occasionally going to have bugs or breaking changes or unexpected information. If unexpected data is going to cause your app to crash or work wrong, IMO you absolutely need to have a plan for spotting those errors and failing gracefully.