开发者

Advantages of Weak Typing over Strong Typing

开发者 https://www.devze.com 2023-03-26 11:23 出处:网络
So, I\'ve read a bunch of similar questions on Stack Overflow regarding this issue, and I think I have a good grasp of what the differences between the two are.My question is whether there is any adva

So, I've read a bunch of similar questions on Stack Overflow regarding this issue, and I think I have a good grasp of what the differences between the two are. My question is whether there is any advantage of weak typing over strong typing beyond the fact that some operations 开发者_高级运维are simply easier for programmers. While I agree that some operations between types are unnecessarily complicated by strongly typed languages, it seems like everything that a weakly typed language can still be done in a strongly typed language with some extra baggage.

Personally, I would probably prefer the extra safety of strong typing and deal with minor annoyances for certain operations, but is there any advantage of weak typing beyond that? Is there something that strong typing could never do the same way?


Some languages offer concepts to alter an object's or class' behavior on runtime: An object that does not implement a method might decide to find a way to respond to the method call nevertheless.

In Objective-C delegation is a common way to let another object respond to a client's message. Objects can detect the missing implementation and pass the method call on to a delegate. It's also possible to dynamically add the implementation of a method when it gets called.

These concepts are based on dynamic method lookup, rather than weak vs. strong typing. But weak typing is tightly coupled with dynamic lookup, so I think this counts as an advantage.


Clearly there's no computability on the line... strongly-typed languages can be Turing equivalent and, assuming weakly-typed languages aren't counterexamples to the Church-Turing thesis (one imagines that this would be widely publicized, if this were known to be the case) then they are at least as powerful (computationally speaking) as weakly-typed languages.

We can then ask whether there is any time or space complexity on the line. My gut feeling here is that the answer is no; the difference between strong and weak typing is probably not significant (in terms of computational complexity) under the RAM model of computation. I could very easily be wrong here. However, strongly-typed languages can likely be compiled to tighter code, so real performance might favor strongly-typed languages anyway.

In my mind, the only benefit that is clear is programmability/writeability/readability/etc. That is, it makes programmers' lives easier, by allowing them to write less code with less effort to get the same effect as writing more code with more effort in a language with stricter typing rules. Then again, this is also up for debate, since strong typing can make it easier to provide correctness/robustness guarantees.


To me, there is almost NO advantage (only a bunch of pitfalls). It's error-prone, hard to debug, doing unit-test is ah.... (I don't know what to say), and it makes the programming beginners think programming is so easy, no design at the beginning of a project.

I need COMPILE-ERRORS, I don't like debugging the dynamic object why it's wrong, or ........


Weak typing is highly error prone, because you only find errors at runtime.

Compile errors are highly advantageous because they INSTANTLY show, whereas to find all runtime errors you need to run through every scenario of every use case. And unless you are developing Automated Tests that cover 100% (I have yet to see someone like that), you will have a more fragile piece of software than you would get with a strongly typed language.

Weak typing is less verbose, which means you type less, but this is also a myth, because with a strongly typed language you get code completion, which means less key strokes than weak typed languages.

0

精彩评论

暂无评论...
验证码 换一张
取 消