Live data from Hacker News

Lists of JavaScript methods which you can use natively

github.com

161–162 of 162 posts

Re: Lists of JavaScript methods which you can use natively

#161

Earlier quoted context omitted.

The answer is: that's an expected failure, so you make the error handling explicit by catching the error and taking care of it appropriately (including proceeding to the rest of the page load, naturally). Implicitly handling errors behind JavaScript's loose typing rules is a recipe for disaster.

Explicitly handling errors is almost always a bad idea, no matter what programming language it is. There are very few errors you can reasonably handle, and they must be designed for. It's specific application domains that need different handling strategies: e.g. embedded, device drivers, software that's trying to maintain some very strict invariants. A web page isn't usually one of them. Usually errors should be sent…

Take a look at Common Lisp and Dylan and their respective condition/restart systems. This is how error handling should look like: they let you handle your errors where it makes sense and naturally recover from them if it's possible.

Re: Lists of JavaScript methods which you can use natively

#162
post #160
post #149

Earlier quoted context omitted.

What? 1. Where did anyone say we were hitting undefined behavior? We're hitting a well-defined JavaScript value whose name is "undefined". 2. Why is crashing correct? Don't answer in terms of language specs, answer in terms of desired behavior for whatever you're trying to do with the program. Software engineering is a tool for accomplishing other things. Sometimes, yes, software crashing is the right thing in servic…

Undefined behavior of a program is when a programmer didn't define how to handle a particular situation. If an array becomes "undefined" and the programmer didn't expect such result (e.g. there's no if (typeof array === "undefined") { ... }), then the behavior is undefined regardless of what kind of types there are in JavaScript. Crashing in such case is used to avoid incorrect functioning of the program, such as ove…

Lodash methods handle things like String#match which returns array/null.

More for avoiding guard scaffolding than for undefined behavior.

Post reply on HN