views:

98

answers:

4

I come from a statically/strongly typed language background (java), and I recently started to learn python and I think I see the value of dynamic/strongly typed language.

Now I'm wondering whether weak typing can be ever desirable.

Going through stackoverflow, I only found explanations that say it has performance benefits. Since the weight of such performance benefit are declining in today's programming world, is weak typing practically dead? For example, would any good language designer in the future consider making his/her language weak-typed?

If so, why?

A: 

Seems like you could get something working faster if you didn't have to worry about types. Some languages don't force you to worry about them.

It all lies in what you're trying to accomplish.

John at CashCommons
That seems to be an issue with static-versus-dynamic. It's orthogonal to the strong-weak debate.
erickson
@erickson: Right. Common Lisp is strongly typed, in that all values can be exactly typed at runtime. It's also dynamically typed, which I found very handy in experimental programming.
David Thornley
A: 

It trims down a lot of coding time, while not increasing debugging time all that much; Type errors are found in testing almost as quick as a compiler finds them, but you didn't have to type int fooBar = 2 It also helps not to have 4+ Number types, however...

Rixius
But in weak typing, you don't get (a lot of) Type errors right? Not having to type `int foobar` sounds like dynamic typing characteristics to me...
Enno Shioji
you have invisible 'type errors', like when adding a number to a string in Javascript, `1+'1'='11'` as opposed to an intended `1+1=2`
Rixius
I think you're arguing for dynamic types, not weak types. There's a very big difference.
David Thornley
Then I am unaware of what exactly Weak types are. I apologize.
Rixius
@Rixus: That's just a badly designed operator. In Perl, you can't confuse `+` with `.` or in Tcl you can't confuse `incr` with `append`
slebetman
+2  A: 

Weak typing is primarily useful in low-level programming. A function to read an integer or string off a disk, for example, will have to take a sequence of bytes and come up with an integer or string. That's much harder to do with strong typing.

David Thornley
I'm not sure I understand. Can you give an example? Even pseudocode would be fine.
Ken
I did give an example, the functions that take raw bytes and turn them into integers and floating-point numbers and the like. An array of bytes is a different type from an `int`, and therefore a function that will change one to the other involves treating the same data as two different types for two different purposes. Since strong typing means that there is a definite type for all data objects, the conversion involves weak typing.
David Thornley
+1  A: 

This is not a flame but just my experience in general. In more than 10 years writing and maintaining code I've only come across type related bugs less than half a dozen times. I have however come to strongly hate the idea of types when writing low level code which moves bytes around. I have long considered the idea of typing to be not necessary anymore when the culture of programming adopted the ideals of good readability.

Of course depending on the language and coding style typing can either help or impede code understanding so I don't mind typed languages too much.

So, as long as there are people out there who, like me, don't see any advantages in types there will always be languages designed to be typeless or weakly typed.

Considering the track record of bugs vs what language used (both in my experience and from what I see on open source code) strong or weak typing does not affect code quality much. Considering the code I've actually read in my experience I would also say it does not affect code readability much. To me it's just a matter of taste (though I know strong type people disagree, they just can't back up their disagreement with facts, it's just their gut telling them to disagree). OK, that last sentence was almost flaming. I'd better stop now.

slebetman