When working in a language which is considered strongly typed, does static code analysis offer anything that dynamic code analysis cannot?
1 Answers
To answer your question, yes, a strongly typed language which does static checking offers benefits.
Why?
As an example, consider a programming language that does static type checking (a functional language like OCaml), versus a language like Python that does dynamic type checking.
Static type checking allows for type-safety before the code is executed at runtime. Whereas dynamic type checking only checks for type-safety during runtime.
What this means is that if you did not use the right types in a language that does static type checking, it is caught at compile time, and will not execute at all. It will catch all those type errors before the code is ran. If it does not encounter any problems, only then would it execute.
On the other hand, in a dynamically typed language, it will compile and execute even if there are unresolved type errors, and during the execution, if it does encounter a type error it cannot resolve, it will throw an exception and just quit.
On small programs these don't look like a big difference, but if you think about it on a large scale, if your program takes a long time to compute something, and on a dynamically typed language, only catches the error nearing the end of the execution, you just wasted a lot of time and resources right? (At least this was an example that helped me understand what benefits it offers that dynamic code analysis does not)
In case you're wondering, Java is a strongly typed language. SO Q&A on whether C is strongly typed or not
There are subtle differences between a strong/weak typed language and a static/dynamic language. Being strong/weak typed refers to how strict a language is with its types. Whereas being static/dynamic is when it is required. (Compile time or runtime) Source
Hopefully that answers your question!
Some references: (yes wikipedia is not a reference but it gives the best examples for this case IMO)

- 1
- 1

- 6,627
- 2
- 35
- 58