by em-bee · 7y ago · 0 comments
in python this is an error:
>>> i = 10
>>> s = "20"
>>> s+=i;
TypeError: cannot concatenate 'str' and 'int' objects
>>> i+=s;
TypeError: unsupported operand type(s) for +=: 'int' and 'str'my preferred language is pike, which is a strong and declarative typed language (declarative typing is the term i prefer since not everyone defines static typing the same way, and some statically typed languages are weak, like this example here)
pike does catch type errors at compile time, but behaves like a strong dynamic typed language at runtime.
i understand that python and rubys optional types now allow for something similar.
It should never happen in production - there should be a test that proves this.
In Common Lisp, the SBCL compiler would be such an example:
* (defun foo () (let ((i 10) (s "20")) (concatenate 'string s i)))
; in: DEFUN FOO
; (CONCATENATE 'STRING S I)
;
; caught WARNING:
; Derived type of I is
; (VALUES (INTEGER 10 10) &OPTIONAL),
; conflicting with its asserted type
; SEQUENCE.
; See also:
; The SBCL Manual, Node "Handling of Types"
;
; compilation unit finished
; caught 1 WARNING condition
FOO
*