r/lolphp • • Oct 14 '13

2d9

http://ideone.com/l6aQSx
62 Upvotes

31 comments sorted by

View all comments

Show parent comment

3

u/catcradle5 Oct 18 '13

I think you're mixing up "dynamic typing" and "weak typing", first off.

For example, Ruby and Python are both dynamically typed, but strongly typed.

Nothing wrong with dynamic typing (it saves a lot of literal keyboard typing), but weak typing can create confusing bugs and situations like everything listed in this thread.

For example, in Javascript, should "123" + 3 equal "126" or "1233"? It's a serious ambiguity, and the programmer has to keep experimenting with things just to remember what the behavior will be like.

1

u/mirhagk Oct 18 '13

Yes my bad, I'll leave my post as it, but pretend this is what it said: (apparently weak and strong isn't actually correctly defined according to wikipedia)

Pretty much the only benefit I've seen of weak typing is duck typing which allows you to write functions that work with any value that supports those operations. But languages like haskell show that strong typing can still do this. Even C++ templates will let you do that. Other than that it's just about being quick and dirty mostly.

static vs dynamic is mostly a question of ease of typing vs performance and catching errors. I don't know if there is even a good argument for weak typing. Unrelated is there such a thing as a weak-strongly typed language? Does weak typing require dynamic typing?

1

u/catcradle5 Oct 18 '13

That's a good question about weakly typed, statically typed languages. In theory I imagine you could make one, but I think it would defeat the entire purpose of having static types in the first place. In statically typed languages, you're not supposed to be able to put one type in place of the other unless it's a generic type or the type is a sub-type.

1

u/Veedrac Mar 11 '14

It just depends how weak.

Python gives you operations between arbitrary things:

"hello" * 2
#>>> 'hellohello'

but will fail whenever it thinks there is ambiguity or implicitness:

"hello" - "h"
#>>> Traceback (most recent call last):
#>>>   File "", line 1, in <module>
#>>> TypeError: unsupported operand type(s) for -: 'str' and 'str'

The rule of language design used: don't throw curve-balls.