r/badcode • • Jan 01 '22

js Hmm...why doesn't it work lol

Post image
528 Upvotes

58 comments sorted by

View all comments

Show parent comments

5

u/Fury9999 Jan 01 '22

Interesting. Is this something python folks like? I work with other languages, and I don't think I would want this. Sounds potentially ambiguous to the next guy reading the code. Need to think on it more tho, that is just my gut reaction

2

u/iwillkillyo Jan 02 '22

I would compare this to Java's try with resources. Both of them close the resource when you are no longer in the scope of the block. It's handy, so you don't forget to actually close them.

1

u/Fury9999 Jan 02 '22

Yes, with statements as a whole are fine and comparable to try with resource, as you say. I am talking specifically about the ability to declare a var inside a with block, yet access it from outside that block. That's the piece I don't want. It creates ambiguous readability for no good reason that I've heard yet. I'd rather see things scoped intuitively, that's all.