4. Python’s Brave Decision "The language has two choices: either continue to bear the burden of what are now considered poor design decisions... or suck it up and let us try and fix some of these problems. It's like going to the dentist; it may hurt, but if that minor toothache goes untreated and develops into an abscess, you will wish you were dead." – blog entry by Collin Winter
10. Redundancy: Iteration in Java for (int i = 0; i < message.length(); ++i) { System.out.println(message.charAt(i)); } for (int i = 0; i < messageChars.length; ++i) { System.out.println(messageChars[i]); } 2 different ‘classic’ syntaxes for iterating over strings & arrays...
11. Redundancy: Iteration in Java for (int i = 0; i < vec.size(); ++i) { System.out.println(vec.elementAt(i)); } for (int i = 0; i < vec.size(); ++i) { System.out.println(vec.get(i)); } Enumeration<Integer> enumerator = vec.elements(); while (enumerator.hasMoreElements()) { System.out.println(enumerator.nextElement()); } Iterator<Integer> iterator = vec.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } ...+ 4 for vectors...
12. Redundancy: Iteration in Java for (int number : vec) { System.out.println(number); } for (char character : messageChars) { System.out.println(character); } ...+ 2 newer approaches for vectors & arrays...
13. Redundancy: Iteration in Java // Before JDK 1.5 BufferedReader inputFile = new BufferedReader( new FileReader("foo.txt")); String line = inputFile.readLine(); while (line != null) { System.out.println(line); line = inputFile.readLine(); } // Since JDK 1.5 Scanner inputFile = new Scanner(new File("foo.txt")); while (inputFile.hasNextLine()) { System.out.println(inputFile.nextLine()); } ...+ 2 for text files = 10 different iteration syntaxes!
14. Redundancy: Iteration in Python for character in string: print character for number in numbers: print number input_file = open('foo.txt') for line in input_file: print line, One syntax works for strings, lists and text files!
15. Redundancy: Integer Representation Java: four primitive integer types, four corresponding wrapper classes, BigInteger class Python 2: two integer types – int & long Python 3: one integer type – int
16. Redundancy: Object Model Two types of class in Python 2: class Foo: ... class Bar(object): ... Only ‘new-style’ classes exist in Python 3 (either syntax can be used) ‘old-style’ class ‘new-style’ class
17. Redundancy: Console Input Python 2 has two functions providing console input: raw_input , yielding input as a string input , yielding the result of calling eval on input Python 3 has one function, input , with the same behaviour as Python 2’s raw_input (New programmers also find this less surprising...)
21. Separation of Concerns: Text vs Binary Data Python 2: str for ASCII text strings & byte strings unicode for Unicode strings Two representations of text, overlapping with one for binary data! Python 3: str for Unicode text strings bytes for strings of bytes Clean separation of text and binary representations, with encode & decode methods for conversion