3 ms·
to read or debug code with them in it one has to understand them Perhaps I'm missing some subtlety to the post, but when was that last time that you were
by fogus 15y ago
to read or debug code with them in it one
has to understand them
Perhaps I'm missing some subtlety to the post, but when was that last time that you were able to take a pass on understanding while debugging?
I think what the author is looking for is better compile-time checking and error reporting in the the with-* macros. I'm not sure how to respond to the "understanding" points. Is the need to understand your language constructs considered a sign of leakiness? I would say no.
- francoisdevlin 15y agoI can feel a bit of his pain, though. I think some of the trouble is that there are things that should be closable, but the (.close x) isn't enough. A Closable protocol could help with some of this. Granted, laziness still makes this issue very, very tricky.
- astine 15y agoAuthor here. It would seem "understanding" might be the wrong word. If I were to write something like: (+ 'foo 1) I wouldn't have to know how "+" is implemented to find the bug in my code. I would if I were to write: (with-open [foo some-object-that-isnt-a-stream] ...do stuff...) however, I would have to know the expansion. If I have to know the details of the expansion of a macro in order to use it correctly, then it is almost by definition leaky. In the case of "with-open," a simple type check at the beginning of the macro expansion would solve the problem.
- deleted 15y ago[deleted]
- readymade 15y agoYou don't need to know how it's implemented, you just need to know that you have to pass an object that can be closed. You can get that simply by reading the docs. The exception that's thrown in your first example above certainly makes it blatantly obvious what you did wrong, which is nice. but you still have to know that the addition operator doesn't let you concatenate numbers and symbols in order to use it effectively, or your program will crash once you run it. That's on you.
- cabalamat 15y ago> when was that last time that you were able to take a pass on understanding while debugging? When I run a program I've written in C or Python, the only program that's really running is written in x64 machine code, because that's the only language the processor understands. But I can debug my program without having to understand the x86 instruction set, because high level languages abstract it out. But if the abstraction was leaky, OTOH, I would still have to understand the details of what's being purportedly abstracted out, so the abstraction wouldn't be properly doing the job of an abstraction. That's why leaky abstractions are a bad thing.