Hacker News new | past | comments | ask | show | jobs | submit login

> I hate having to say everything twice. Types force me to do that

Thats just because most OO languages OP uses don't have powerful type inference. Sure, type inference is tricky in languages with subtyping but it certainly doesn't need to be verbose and redundant like it is in Java.




Can you elaborate, what redundancy are you talking about?


I believe he means that very often, type annotations are not necessary to know unambiguously the type of a variable or the return type of a function.

For example, in the following Java code:

  public String myMethod() { return "hello, world"; }
  String myVal = myMethod();
Given that the compiler knows that myMethod cannot return anything but a string, there really should be no need to state it explicitly - it's redundant information. Likewise, myVal can only be of the same type as myMethod's return type.

Languages with type inference get rid of (most of) that redundancy. Take Scala, for example:

  def myMethod() = "hello, world"
  val myVal = myMethod()


One example is repeating the class name in the type declaration and in the constructor call:

    Foo foo = new Foo();




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: