I understand the principles behind opaque data types, encapsulation, information hiding, etc. in theory: preventing alteration to parts of a program can prevent people from accidentally messing it up, and hiding the information is basically just to make it more readable. The thing that I just can't seem to wrap my brain around is how this wouldn't cause massive problems.
Having a programmer use a black box while completely ignorant to how it works seems really dangerous to me. Yes, I don't need to know what a bowl is made of or how a microwave works to use either of them, but if I do stick a bowl in the microwave and it's made of the wrong material, the bowl could shatter.
Say for example, I have a function, int black_box(int x, int y)
, that takes two numbers as inputs and performs some sort of calculation on them. It's known what the calculation does and how to use it, but the actual implementation is considered irrelevant. Now, I try black_box(5,3);
but part of the calculation, which I don't know about, involves var = y / (x-5);
. If the people who wrote up the documentation missed this and didn't write, "don't use 5 for x," I'd be stuck with an error telling me I can't divide by 0, and I would have no idea where I went wrong.
This was just a simplistic example where the oversight would be obvious, but in more complex programs, I can see this becoming a serious problem. I feel like I'm missing something vital here because I can't seem to view keeping other programmers blind to what they are using as a good thing.
var = y / (x-5)
is clearly a BUG if not explicitly documented as a special case. But, more important thing, how does it come that you are testing third party library without source code in the first place?