Live data from Hacker News

"Should I still learn Java?" Answered: Yes.

beginwithjava.blogspot.com

81–90 of 108 posts

Re: "Should I still learn Java?" Answered: Yes.

#81
post #79

Earlier quoted context omitted.

Ruby 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 wha…

There, problem solved. The problem isn't solved. You now know what the type is for that particular moment . What you don't know are the invariants of the don_t_know_the_return_type() function. What types/subtypes is can return, whether it can return None, what exceptions it can throw, and whether those will change in the future. That information can only come from a type system and/or documentation. Simply reading th…

First, even in Java you don't know the return type / invariants ...

     int n = func_that_returns_positive_even_number()
What you need is to document the thing:

    def func_that_returns_positive_even_number():
          """Returns positive even number."""
This comment will be available when typing "help(func_that_returns_positive_even_number)" in the Python console btw.

Or if you're paranoid and that function can totally break your code:

         n = func_that_returns_positive_even_number()
         assert isinstance(n, int) and n % 2 == 0 and n >= 0
Or to make extra sure this will hold in the future (i.e. protecting from code-changes done by other people) ...

     import unittest

     class TestMyFunc(unittest.TestCase):
           def test_is_positive_and_even(self):
                n = func_that_returns_positive_even_number()
                self.assertTrue( n % 2 == 0 and n >= 0 )

Re: "Should I still learn Java?" Answered: Yes.

#82
post #80

Earlier quoted context omitted.

From 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…

How do you define (and enforce) those rules? My general position when writing library code is that none of my classes should be subclassed. The very few classes that may be subclassed are documented as such, and the methods that may be overridden are explicitly documented, as well as what behavior is required from the subclass when overriding those methods. The invariants of complex inheritance hierarchies are very h…

Why do you need to enforce rules, other than documenting the classes/methods defined?

     What happens if the superclass method isn't called
Shit doesn't work or it breaks, then the person who sub-classed needs to fix it. Sometimes it also means your class is leaking encapsulation.

This also happens with plain aggregation/composition btw. It also happens with data-immutability (which has nothing to do with inheritance, as your object can be immutable and extend a dozen classes).

Re: "Should I still learn Java?" Answered: Yes.

#83
post #79

Earlier quoted context omitted.

There, problem solved. The problem isn't solved. You now know what the type is for that particular moment . What you don't know are the invariants of the don_t_know_the_return_type() function. What types/subtypes is can return, whether it can return None, what exceptions it can throw, and whether those will change in the future. That information can only come from a type system and/or documentation. Simply reading th…

First, even in Java you don't know the return type / invariants ... int n = func_that_returns_positive_even_number() What you need is to document the thing: def func_that_returns_positive_even_number(): """Returns positive even number.""" This comment will be available when typing "help(func_that_returns_positive_even_number)" in the Python console btw. Or if you're paranoid and that function can totally break your c…

First, even in Java you don't know the return type / invariants ...

This is a classic type system straw man. The language doesn't support encoding integer ranges in the type system, ergo, the type system is not ever a significant advantage and all invariants must be documented. You fool!

What you need is to document the thing:

Some invariants require further documentation. The more you can express concisely in code via the type system, the more time you and your API clients save in both development and maintenance.

More succinctly: By expressing them in code you let the compiler automate the work of enforcing them.

Or if you're paranoid and that function can totally break your code:

An assert doesn't "protect" your code from future changes (better phrasing would be: make your code adaptable to change, loosely coupled with its dependencies as to allow iteration of your code and its dependencies independently).

An assert simply causes your code to fail in an obvious way. It's still up to you to track them down (at runtime) and figure out where you went wrong.

Re: "Should I still learn Java?" Answered: Yes.

#84
post #64
post #15

Earlier quoted context omitted.

public static void main(String[] a) { System.out.println("Hello world");} Yeah you're right. That's an insane amount of typing which would take any kid hours. I had to muster up all of my patience just to type all that code out. You're right! Java is so verbose! Your "argument" if you can call it that, is like people saying lisp is crap because it uses too many brackets.

> which would take any kid hours > Your "argument" if you can call it that From Hacker News guidelines ( http://ycombinator.com/newsguidelines.html ): "Be civil. Don't say things you wouldn't say in a face to face conversation. When disagreeing, please reply to the argument instead of calling names."

I would certainly say a lot worse face to face :)

Re: "Should I still learn Java?" Answered: Yes.

#85
post #26
post #20

Earlier quoted context omitted.

As someone who programs Java a fair bit, what bad habits do you believe it teaches?

Most of my work these days is Java too, fwiw. But only because I need Lucene and Hadoop ;-) The main bad habit is a gross overuse of patterns to compensate for language stupidity (see: http://norvig.com/design-patterns/ ). A few particular examples include: - Too much global state. You call it a Singleton. I call it a global variable with a fancy name and a lot more code. - You lose the ability to think functionally…

I disagree with all of that, but I doubt my opinion matters here.

Hardly ever use globals, never use patterns, I think in code , dynamically...

The whole point is to make passing in functions hard. Passing functions everywhere leads to spaghetti code.

Re: "Should I still learn Java?" Answered: Yes.

#86
post #20

Earlier quoted context omitted.

As someone who programs Java a fair bit, what bad habits do you believe it teaches?

Inheritance instead of composition. Too much worry about security theater public/protected/default/private instead of actually reusing code. The inability to fake stuff for tests without designing ability to fake things into every class. Basically, you write the code, and that's what you have. If anything changes, it's basically a rewrite, even with Eclipse's "refactoring" features. Type erasure. When all you have is…

I know I'm not an average Java programmer (I hate IDE's, hate patterns for example), but I've never seen anything as an AbstractHammerFactoryInterface.

Seems like you're confusing Java the language, with how some people choose to use Java.

Re: "Should I still learn Java?" Answered: Yes.

#87
post #68
post #20

Earlier quoted context omitted.

As someone who programs Java a fair bit, what bad habits do you believe it teaches?

Would you mind discussing your development setup? What editor(s) do you use? Other software that makes writing Java easier? There are many opinions about this on the internet, but most of them are geared towards enterprise developers in large shops; not towards startups.

  jdk
  textmate / jedit / nano
  ant
What else do you need? :/

Re: "Should I still learn Java?" Answered: Yes.

#88
post #37
post #18

Earlier quoted context omitted.

I'd skip C and learn assembly personally.

For which architechture?

Best way to learn is to do, so depends what hardware they have to play on.

I personally went Z80->x86->arm with a few others thrown in.

I'd probably suggest most people learn x86 and then arm.

Re: "Should I still learn Java?" Answered: Yes.

#89
post #87
post #68

Earlier quoted context omitted.

Would you mind discussing your development setup? What editor(s) do you use? Other software that makes writing Java easier? There are many opinions about this on the internet, but most of them are geared towards enterprise developers in large shops; not towards startups.

jdk textmate / jedit / nano ant What else do you need? :/

Is it common for java developers to use a "dumb" editor like textmate / jedit / nano? I've heard that a good IDE is a requirement for writing significant amounts of Java. To be fair, I've mostly been interested in Scala; but it seems like you have to know Java to get the most out of Scala.

Re: "Should I still learn Java?" Answered: Yes.

#90
post #80

Earlier quoted context omitted.

How do you define (and enforce) those rules? My general position when writing library code is that none of my classes should be subclassed. The very few classes that may be subclassed are documented as such, and the methods that may be overridden are explicitly documented, as well as what behavior is required from the subclass when overriding those methods. The invariants of complex inheritance hierarchies are very h…

Why do you need to enforce rules, other than documenting the classes/methods defined? What happens if the superclass method isn't called Shit doesn't work or it breaks, then the person who sub-classed needs to fix it. Sometimes it also means your class is leaking encapsulation. This also happens with plain aggregation/composition btw. It also happens with data-immutability (which has nothing to do with inheritance, a…

Why do you need to enforce rules, other than documenting the classes/methods defined?

The less repetitive work we delegate to human fallibility and instead delegate to a machine, the more time we have for human ingenuity.

Shit doesn't work or it breaks, then the person who sub-classed needs to fix it.

It's not that simple. The more difficult it is to understand the rules of behavior before changing the code, the more difficult it is to change the behavior. It's not just a question of expressing valuable -- but simple -- kindergarden requirements (this value may not be NULL), but higher-level requirements (this method must be called in the context of a READ-COMMITTED transaction).

The more you can express concisely, the easier it is to mutate the system over time. It's not a question of breaking code -- or noticing when it breaks -- but having the language assist in simply not breaking it at all.

This also happens with plain aggregation/composition btw.

Composition makes invariants easier to understand. If you then design your classes so poorly as to fail to enforce correct behavior through their API insofar as it is possible to do so, that is the programmer's failure.

It also happens with data-immutability (which has nothing to do with inheritance, as your object can be immutable and extend a dozen classes).

Data immutability is related to the avoidance of inheritance insofar as they both very significantly facilitate the full and easy comprehension of an implementation invariants.

Post reply on HN