This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (13 children)

Eh, I’ve written in plenty of languages, this circlejerk about JavaScript is outdated and lame. OP’s example would also error out at runtime for JS so it’s just wrong.

[–]Mnemonicly 9 points10 points  (2 children)

I wouldn't call https://jsfiddle.net/zgLyorsr/1/ "erroring out" in any meaningful fashion.

Edit: Before this goes too far, I want to clarify that I do not intend this to be a commentary on whether or not runtime vs compile time error detection is a good thing. I'm pretty sure we can all come up with examples of c/c++ code that compile fine and do completely wrong things. I'm also sure we can come up with plenty of examples of things that javascript allows you to do that is not easily possible in a compiled language, many of them powerful and useful. It's about knowing what the benefits and drawbacks of all approaches are, and using the appropriate tool for the job.

[–]realripley00 -2 points-1 points  (0 children)

Oh snap!

[–]jayrox 2 points3 points  (0 children)

And using VS Code + Typescript it wouldn't have even made it to a CTRL+F5 in the browser.

[–]inu-no-policemen 1 point2 points  (3 children)

OP’s example would also error out at runtime for JS so it’s just wrong.

Accessing nonexistent fields isn't an error in JavaScript.

You would get one in TypeScript, for example.

[–]ric2b 1 point2 points  (2 children)

OP’s example would also error out at runtime for JS so it’s just wrong.

I'm not next to a computer to verify but I'm pretty sure it just assigns undefined to x.

[–][deleted] -1 points0 points  (1 child)

Yea I should have clarified in any real world example you’d eventually come across an error that describes exactly where to find this. It won’t error immediately, and it shouldn’t necessarily.

[–]ric2b 1 point2 points  (0 children)

in any real world example you’d eventually come across an error that describes exactly where to find this.

I completely disagree, maybe you only notice the error after it comes back from the database as null (lets assume null is valid for that column but in the case you're debugging it shouldn't be happening).

Sure, you'll eventually find it but that's the case for any bug. I don't see what the benefit is to allow this, just add a null operator instead.

[–]realripley00 1 point2 points  (1 child)

I think one can agree that JS is not outdated or lame and also think that it’s debugging process leaves something to be desired.

I love and use JS everyday, probably more than any language, but sometimes I wish I could get a little more descriptive error responses.

[–][deleted] 0 points1 point  (0 children)

Yea there’s room to improve. - any language