Why do the Visual Studio error logs show the things caused by some error, rather than the error itself? I often find the error messages to be useless and meaningless.
When I make a mistake, like for example a circular dependency, it throws a bunch of errors like
syntax error: missing ';'
instead of something like circular dependency detected
.
When I forget to include some header and use it in my code, for example the std::map
, it only says 'map' is not a member of 'std'
It never shows you what's actually wrong, it only shows the symptoms. I know that sometimes you can clearly see what's wrong based only on that, but I don't want to spend time figuring out what's wrong. I just want to fix it as soon as possible.
Why can't it be like Python with Pycharm IDE which actually shows you the actual error?
CodePudding user response:
Even though this question might be considered out of topic, I'll attempt to give an answer to make it clear why one might find the experssed opinion (useless and meaningless) as "unfair".
Firstly this is not a Visual studio thing. If you've used other C compilers (gcc/clang/intel compiler) you'll notice the errors are pretty similar. Even though they might seem "useless", a little experience goes a long way. Not only are the errors precise, exact and reproducible, but they follow a standard specification and adhere to the formal description of the language.
Secondly we have to draw a line when comparing C to Python. C is a compiled language meaning that prior to creating an executable the entirety of your code must be written according to the language rules. This means that a runtime branch is checked even if it's not executed. Python on the other hand is an interpreted language. This means that it verifies code on the fly (having richer information on the execution context) so the following code will probably run fine:
def main():
a = []
a.append(1)
print(a)
# return 9'999 out of 10'000 times
a.shoot_foot(2) # list object has no attribute 'shoot_foot'
if __name__ == '__main__':
main()
This comes with the price that an error (not even calling this a bug since it violates language rules) may remain hidden and manifest in production.
Thirdly C is a strongly typed language. This means that types are statically checked, at the price of requiring you to be correct about them. Unlike the dynamically typed Python the type of an object cannot be modified at runtime which means increased type safety at the price of "being careful" when programming. It's a JS vs TS kind of thing, and people get accustomed to different styles; for me the lack of type safety is the thing I miss the most when working with Python. This power comes at the price of some of the most intricate error messages when doing type checking.
Lastly C is actively evolving towards improving error messages, making them more informative and shorter. This is not an easy task but features like concepts allow programmers to be explicit on the restrictions they impose to the type sytem. Additionally defensive programming techniques like static assertions can introduce a "fail switch" that stops compilation early resulting in less errors and keeping only the information about the offensive code.