A Quick Meditation on Types
By anders pearson 06 Jul 2013
This is valid Java:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Foo { | |
public static void main(String[] args) { | |
Integer i = 3; | |
System.out.println("i is: " + i); | |
} | |
} |
But this is not valid Python:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i = 3 | |
print "i is: " + i | |
# you get: TypeError: cannot concatenate 'str' and 'int' objects |
It’s pretty easy to pick them apart and understand exactly why each is what it is, but I think it’s worth meditating on why it is somewhat surprising to most programmers.
Tags: programming java python types