What is type juggling?

9

What does the term type juggling refer to? Is it related to dynamic typing languages such as PHP and JavaScript?

    
asked by anonymous 17.12.2018 / 22:30

1 answer

10

I only know the term being used in PHP. Have in the documentation . The term probably could not be more accurate, but in the wrong sense. And the definition there is poorly done (it's PHP, so it's normal).

The documentation begins by defining something that is typical of dynamic language, and until then I do not know if the term fits. This beginning indicates that the variable has the value type at that time. According to theory of types this is neither true. The variable has no type, or has a unique type with a tag for a type of value. Who has the type is just the value.

Then the documentation starts talking about coercion and then the term seems more appropriate. The language does a juggling to try to interpret what the programmer wants to do and give some result, even if it is not what the programmer wants to do. It gives a possibly wrong result so as not to give error. It seems to be a case of inferring something without being sure, which can lead to a false positive and cause more harm than the good that was expected of this feature of language.

Is not it "beautiful" a language that adds a boolean with a string and the result is an integer?

See running on ideone . And no Coding Ground . Also I placed GitHub for future reference .

At least now give warning .

Limited coercion that produces a correct result is not always a problem. Juggling is doing what may not work.

This is typical of script language and makes sense in very simple codes. I'm sorry if this displeases some, but using a script language to make applications enterprise is simply to use the wrong language, and the fact that language starts putting < > enterprise without repairing these problems shows that it is lost or trying to save itself in an environment where the bulk of the code is enterprise and not scripts . p>

This is typical of weak typing languages and not dynamic typing, a term people quite confuse .

In fact JS does something similar, but I have not seen the term being used on it. There are other weak typing languages that do not use the term, because in many cases they are a bit more controlled, eg C.

    
17.12.2018 / 22:49