Reputation:
Can a good IDE (e.g. Visual Studio) find basic logic errors?
or is there no such thing as a "basic" logic error and all of these errors are undetectable by the IDE?
Upvotes: 0
Views: 1732
Reputation: 415
Not really.
Sometimes it can pick up that a code path may never execute I think.
int x = 9;
if (x != 9)
{
foo();
}
and it maybe able to tell you that you've declared something without using it. It's stuff you can catch yourself. However, the real power is in the debugger where you can use "watch" or locals/autos and follow the code with step-in/out/over at any scope, see when they change, and change the values yourself to see what needs to happen. It's a good way to test logic. In assembly, you can move your code back a few lines and repeat it... it's not guaranteed to work, but you can override anything.
Edit: see https://en.wikipedia.org/wiki/Halting_problem
Upvotes: 1
Reputation: 700680
Yes, some IDEs (like Visual Studio) have continous syntax checks, that can find some logical errors. However, a logical error can only be spotted if there is something odd in the code, there is no AI trying to figure out what the code is actually intended to do.
If you for example write this in a C# method in Visual Studio:
int a = 1;
int b = 2;
Console.WriteLine(a + a);
then the IDE will notice that you never used the variable b
, and put a warning in the form of a squiggly line under the variable. Pointing on it will reveal the message The variable 'b' is assigned, but its value is never used
.
The IDE can't know if you intended to output a + b
rather than a + a
, and simply the use of a + a
is not odd enough to render a warning, but it can see that you created a variable b
and that you probably intended to use that for something.
Upvotes: 1