3 ms·
I'd like to know as well. IMO, one of the few things Java is actually good for is to learn object oriented programming. - It has a pretty simple syntax, as it
by wladimir 16y ago
I'd like to know as well. IMO, one of the few things Java is actually good for is to learn object oriented programming.
- It has a pretty simple syntax, as it doesn't have too many strange or unintuitive language constructs.
- Its verboseness forces the learner to understand what is going on and be thankful for the magic that more dynamic languages provide.
- It's statically typed so it forces the learner to think about types.
- It's hard to shoot yourself in the foot with beginner mistakes like with C++/C. Still, it's a good preparation for learning C/C++ later.
- Clear compile-time and run-time error reporting.
And so on...
- smanek 16y ago- It is just barely object oriented (and Alan Kay agrees with me on this). Checkout CLOS and the MOP or Smalltalk sometime for a good object system. - No. Java has a complex syntax. Take a look at the grammar sometime. It's 10s of times longer than Scheme's (see: http://java.sun.com/docs/books/jls/second_edition/html/syntax.doc.html http://java.sun.com/docs/books/jls/second_edition/html/synta...). You just like it because it's almost, kind of, a little, like C and C++. - It is, in large part pointless verbosity. Explain to me how: Map<String, Pair<Integer, Set<String>>> data = new HashMap<String, Pair<Integer, Set<String>>>(); is useful. Explain how 20 lines for a strategy pattern or a visitor pattern is better than just having built in first order functions and multiple dispatch. - The type system is abysmal (and not sound). Runtime Erasure of generic types? Casts? Nulls? - I do agree it is better than C++ for most purposes though ;-)
- xyzzyz 16y agoComparing the languages that use S-expressions to the languages that actually have syntax is a bit unfair, I think.
- wladimir 16y ago- True; I was just considering the mainstream languages. Yes, if you include Smalltalk, LISP, I'm sure there are better alternatives to learn specific concepts. But Java is used a lot in practice, and looks a lot like other languages used in practice (C++, ObjC, C#, and friends), which in my experience makes students more enthusiastic. - I agree the "generics" are complex and overly verbose. They almost look like the C++ templated types, which I would go around with a 10 foot pole if I wanted to learn someone programming... IMO, pre-1.5 Java was best for learning. - Yes, a lot of the verbosity is pointless, I think it helps for learning to specifically mention everything and be a bit repetitive. Other languages luckily allow leaving the obvious stuff out.
- bad_user 16y agoRuby and Python are also mainstream, and both provide saner OOP. C++ templates at least have a purpose and provide extra benefits (e.g. performance, compile-time computations for pre-caching). In Java generics are practically implicit type-casts and nothing else. About verbosity ... clear conventions are a lot more effective for readability and learning. In a dynamic language like Ruby / Python, if you don't know what an object's type is or what it does, the fix is as easy as ... obj = don_t_know_the_return_type() # doing lots of stuff import pdb pdb.set_trace() That opens up a Python debugging console at the current point of execution, and you can inspect "obj" for its type / members and also modify its state. Also, if you're using "ipdb" instead of pdb then you've also got auto-completion on <TAB> (e.g. Intellisense). You can do something similar in Ruby, and in Smalltalk the whole application is active while you're typing in the IDE. There, problem solved.
- uriel 16y ago> Ruby and Python are also mainstream, and both provide saner OOP. For various other reasons I prefer Python to Java (or Ruby), but there is one thing that Java got right and Python totally messed up: avoiding the disaster that is multiple inheritance. Of course a much better option is to completely do away with inheritance like Go has done (plus Go combines some of the advantages of Python's 'duck typing' with the static type checking of Java's interfaces).
- bad_user 16y agoFrom where did you get the idea that multiple-inheritance (in general) is a disaster? Multiple-inheritance is only a disaster when the rules aren't clear on ... (a) what you're inheriting (b) what you're overriding (c) what happens when you try calling super:: Otherwise, inheritance is really useful, and Python scores pretty good on all the above points. Also, GO doesn't have "duck typing". That's called "structural typing" and it is a lot more limited than dynamic typing. GO is not really object-oriented either.
- 16y ago
- srgseg 16y agoExplain to me how: Map<String, Pair<Integer, Set<String>>> data = new HashMap<String, Pair<Integer, Set<String>>>(); is useful. Firstly, in Java 7 or in Java 6 in a modern IDE, you only have to type: Map<String, Pair<Integer, Set<String>>> data = new HashMap<>(); So let's break this down: if I was using another language, I could just do: var data = {}; But consider what you've now lost: 1. If your code was just a simple associative array, not much. But if you have a complex nested data structure, you need to now put a comment somewhere so you don't forget what you're storing there. You can get into serious problems when multiple programmers are working on the same project if you don't clearly describe your data structures, and so you're not really saving on typing by writing Map<String, Pair<Integer, Set<String>>> because you'd have to document that in a comment instead. Since people are lazy when it comes to commenting code, Java therefore forces a degree of self documentation into data structures. 2. I notice that you're storing a Set of Strings (Set<String>). As I'm sure you know, this means you can throw a bunch of strings into the set without worrying about duplicates. In Javascript, this would be messy. Since there is no 'Set' data type in Javascript you'd have to have an associative array where you store the string as the key and 'undefined' as the value. 3. HashMap isn't the only kind of map. In Java, you could use a TreeMap so that content is sorted in key order. This saves you code later by not having to take the associative array, converting it into a list, and then sorting the list. 4. In addition to TreeMap, another extremely useful kind of map is the ConcurrentHashMap, which allows you to manipulate the Map simultaneously from multiple threads (e.g. multiple simultaneous web request threads) without getting concurrent access problems or having to write your own synchronization code. 5. Tons of other really cool data Java datastructures available to you in the Java libs. E.g. WeakHashMap which won't prevent referenced objects from being garbage collected if they are dereferenced elsewhere, and LinkedHashMap which is useful for guaranteeing the order of stored objects even if they are removed and reinserted. So although I agree that var data = {} can be more convenient in simple cases, that's not to say Java's approach has no upside.
- smanek 16y agoYes, Java 7 finally will fix this bug (which is 7 years old!). The fact that good IDEs can work around this bug, doesn't mean Java sucks any less for it though. I have similar issues with syntax for anonymous classes (which you need a lot of, to even poorly simulate fp), but we'll save that for another day. I don't want var data = {} in a statically typed language. I want something like Map<Int, [Int, Set<String>]> data = new HashMap(); to use the exact same example that I used above. This way gets all the benefits of what java currently does, with literally half the characters and more readability.
- stcredzero 16y agoIMO, one of the few things Java is actually good for is to learn object oriented programming. You'd do better in an environment where everything is an Object. (No "primitives" to get in the way.) It has a pretty simple syntax, as it doesn't have too many strange or unintuitive language constructs. Confusing language syntax and semantics? Java's syntax is pretty large and complex by any number of objective measures. Is this an instance of the "start a language war" game?