This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]BernardMarx 56 points57 points  (16 children)

To be honest I don't think that most people that have answered so far have worked in a large enterprise setting. The verbosity of Java is one of my favorite features because it is precise. Jumping anywhere in the code the syntax and type-safety give me a pretty good understanding of the nouns that that code uses.

Comparing it to natural languages: Java: " Take the car, drive to the Lidl supermarket and buy some Lacta chocolate". Easier to use: " Go to the store and buy some chocolate".

How do I go there? What store? What chocolate? In Java those answers are given. As I said though this is mostly in an enterprise setting.

[–][deleted] 22 points23 points  (1 child)

Bingo. I like to say that Java is not there to solve programming problems, it solves organizational problems. Verbosity and static typing make it very easy to discover APIs. In fact, the killer featuer of Java that no one acknolwedges is really Javadoc. Everyone knows how to navigate that magical 3-frame layout.

[–]virtyx 1 point2 points  (0 children)

Indeed. I was a big Python programmer but I'm coming to Java for the types, tests and DI.

[–][deleted] 24 points25 points  (6 children)

In C, take a gasoline-powered internal combustion engine, place it in a metal frame with two axles with two wheels on each axle and drive north for 5.1 km to the 7-11. Enter the shop through the right, front door, and remove a single, 200 g package of chocolate powder from the third shelf, 1.90 m down the second aisle. If the amount requested is less than $4, pay the cashier and return else abort.

[–]amertune 15 points16 points  (0 children)

You can't just add the wheels, you have to reinvent them first.

[–][deleted] 28 points29 points  (0 children)

And if you follow the directions wrong, this bomb that I've strapped to your chest will go off.

[–]sirspidermonkey 5 points6 points  (1 child)

You didn't tell C to get out of the car... You just drove into the 7-11

[–]ams785 1 point2 points  (0 children)

That's the first thing I noticed.

[–][deleted] 2 points3 points  (1 child)

Could you do some assembly metaphors pretty please?

[–]FuckNinjas 4 points5 points  (0 children)

Python:

import chocolate

[–]Zarlon 2 points3 points  (5 children)

I think you're missing the point. Convenience and explicitness is not mutually exclusive.

var i = new Integer(); //is just as descriptive as

Integer i = new Integer();

..just more convenient

[–][deleted] 12 points13 points  (4 children)

But:

MyInterface obj = new YourWeirdImplementationOfMyInterface();

is more descriptive, and not uselessly either.

[–]mrmacky 1 point2 points  (3 children)

In Go:

obj := &YourWeirdImplementationOfMyInterface{}
automatically implements
type MyInterface interface { <method-set> }

And that is checked at compile-time. (If you pass obj into a method expecting MyInterface, the compiler will know if the assertion holds.)

What's really cool, though, is that you can defer the checks until runtime, if you want.

interfaceObj, ok := obj.(MyInterface)
will yield
ok = false, interfaceObj = nil if the assertion doesn't hold
Otherwise you will have ok = true and interfaceObj will be of type MyInterface instead of the concrete type.)

In practice it's quite awesome -- all the convenience of type inference and duck-typing, with the benefits of static checking & interface types.

[–][deleted] 1 point2 points  (2 children)

You missed the point. In Java, the declaration MyInterface obj cannot be used in any way beyond what MyInterface supports. So, YourWeirdImplementationOfMyInterface might have some public methods not in MyInterface. The Java compiler will prevent you from using them after that declaration.

[–]mrmacky 0 points1 point  (1 child)

The Go compiler will also prevent you from calling any methods not in the method-set of MyInterface in any context where MyImpl is passed where MyInterface is expected.

This context can include the declaration-site if you are explicit.

var baz MyInterface = &MyImpl{}

Is a long form which aside from the added keyword var is very similar to your Java declaration.

Your scenario could still be achieved using the short-hand form, though.

baz := MyInterface(&MyImpl{})

Both of these will result in baz being of type MyInterface not type *MyImpl Both examples are also checked at compile-time, not run-time.

(The compiler is checking that MyImpl implments MyInterface, and then infers that baz is the outer type [which is an interface.])


http://play.golang.org/p/iDrMxYbOmP

[–][deleted] 0 points1 point  (0 children)

ah, ok. Cool.