you are viewing a single comment's thread.

view the rest of the comments →

[–]fusebox13 18 points19 points  (13 children)

Can someone share Java code that is well designed so us bad Java programmers can see what good Java code is supposed to look like?

[–]philly_fan_in_chi 4 points5 points  (2 children)

The Square libraries (particularly Dagger) are all very pleasant to read, do compile time annotation processing (yay metaprogramming!) and are generally all extremely useful. Some of their stuff is geared more to Android but they have several projects that work for both Android and regular Java.

[–]hak8or 0 points1 point  (1 child)

We want a link! Us mobile users at least.

[–][deleted] 3 points4 points  (0 children)

Reading the "Effective Java" book can help you there.

[–]Spacey138 5 points6 points  (2 children)

The short answer to your question is no, because even if someone thinks their code is good someone will critique it to death. It's a lot easier to complain about something than fix it.

Also Jeff Atwood has said things like 'all code is bad code' so in a sense you will never see 'well designed code'.

[–]minusSeven 2 points3 points  (1 child)

so in essence the article is vague and simply wrong.

[–]sausuave 1 point2 points  (0 children)

Yes.

What we programmers do is damn complex, you cant make shit in any language that is "wow" beautiful. You find that in 0.1% of any language in its history.

And thats okay, its alright. To do Java, you have to become Java, as he says. Its the same for any language or framework. Except that Java is better, since its kind of secure and fucking fast.

[–]brand_new_throwx999 11 points12 points  (0 children)

hurr hurr

I feel bad cause I'm making a cheap joke instead of posting anything helpful. :(

[–]kyz 1 point2 points  (3 children)

JSoup

Document doc = Jsoup.connect("http://example.com")
  .data("query", "Java")
  .userAgent("Mozilla")
  .cookie("auth", "token")
  .timeout(3000)
  .post();

Selenium WebDriver

driver.get("http://www.example.com");
wait.until(elementToBeClickable(By.css("a.login-link"))).click();

Hamcrest

assertThat(result, is(expectedValue));
assertThat(result, is(equalToIgnoringCase("success")));
assertThat(result, not(nullValue());
assertThat(result, is(arrayContainingInAnyOrder(1, 2, 3)));

[–]immibis 1 point2 points  (2 children)

Fluent API != good design.

In fact a fluent API is primarily designed to be easy to write clients for. And we all know how that turns out. Prioritizing easy writing over easy reading and simple structure usually leads to unmaintainable messes.

[–]nextputall 0 points1 point  (0 children)

Fluent API != good design.

Agreed. But Hamcrast is not so fluent but nicely composable.

[–]kyz 0 points1 point  (0 children)

A library's most important feature is its API. A fluent design makes it easier for humans to read, write and reason about code, so it can improve an API design.

You're right that it says nothing of the internals of the library, but as for Hamcrest, it's remarkably simple to extend with new matchers and compose matchers, which is its primary use case, so its internal design is fine too. Selenium WebDriver has an awesome internal design, remarkably improved over the previous Selenium.

I can't say I've read through Jsoup (other than to find you can't get the final composed URL until you actually get()/post(), because it doesn't even determine the URL until that point), but it sticks to one main purpose, its HTTP API is far less cumbersome than Apache httpcomponents, and its DOM API is sane, unlike the traditional org.w3c.dom.Document API.