re: What ever happened to putting the object type on the left? VIEW POST


As others have noted, I've seen it as an indicator of languages with type inference. So you can omit the type if you don't need it.

The syntax itself is taken from Pascal, so not "new" in the strict sense but "new" in the "not seen in popular languages until recently".

Here's how I read each one in my head and I find the right-hand more like natural English:

String hello = ...;
// "a string named hello with value..."

public String greet(int times) {...}
// "A public method that returns String, is named greet and takes an int parameter named times"
var hello : String
// "the variable hello is a String"

func greet(times: Integer) -> String {...}
// "a function named greet that takes times, an Integer, and returns a String"
// Though it can sometimes be slightly more difficult hard to find the return type in a complex function definition, especially in lambdas (functions that return functions ....)
code of conduct - report abuse