5 ms·
I don't know about .NET, but Java definitely suffers from the enterprise verbosity problem (no it still hasn't gone away). I mean, tell me the equivalent Java
by IshKebab 11y ago
I don't know about .NET, but Java definitely suffers from the enterprise verbosity problem (no it still hasn't gone away).
I mean, tell me the equivalent Java code to this:
resp, err := http.Post("http://example.com/upload", "image/jpeg", &buf)
I think that would be about 20 lines in Java. You've got to make a `HttpUrlConnection`, then call `setDoInput(true)` (or is that `setDoOutput(true)`), wrap it in a `try`, etc. etc. etc.
Go's standard library is amazing.
- pjmlp 11y ago> I think that would be about 20 lines in Java. You've got to make a `HttpUrlConnection`, then call `setDoInput(true)` (or is that `setDoOutput(true)`), wrap it in a `try`, etc. etc. etc. Nothing prevents you to wrap those 20 lines in a generic method. Also there are other options in Clojure, Scala, Kotlin, Groovy besides pure JDK API calls. Here Scala style, easy to mimic in Java 8 val result = http.postData("http://example.comupload").header("Content-Type", "image/jpeg").responseCode > Go's standard library is amazing. So amazing that is doesn't have proper database drivers for the SQL databases that matter.
- tinco 11y agoI recently rewrote one of our services in Go and there was a SQL interface in the standard library with backends for all SQL databases that matter. I don't remember if the backend we used (for PG) was from the community or the standard library, but that's rather inconsequential.
- pjmlp 11y agoFor our customers that means Oracle, SQL Server, Informix, DB2,... from the database vendors themselves. Not community projects that kind of work.
- merb 11y agowith play-ws it's even ws.url("http://example.comupload").withHeaders("Content-Type" -> "image/jpeg").post() Also this is non blocking, while the go code will bock, by default. there is even akka-http now which could be wrapped really great which is streamed by default, even better.
- IshKebab 11y agoNothing prevents you from writing an entirely new Java library. The point is Go's library already has all the nice convenience methods. With Java I would be endlessly writing them myself, and even then they wouldn't be as good as Go's because they wouldn't be standard (no help on StackOverflow for example).
- pjmlp 11y agoActually it is easier to write generic code in Java than in Go. Also many Java bashers in the Go community seem to be unaware of what is delivered in the JDK. When I used to daily read gonuts, many weren't even aware that since Java 6, there is a similar infrastructure for HTTP(S), no need for third party servers.
- vorg 11y agoFor the last 3 months, Groovy has been officially known as "Apache Groovy".
- flaie 11y agoEither you make a method of it and then you can call it in 1 line, or you can use some libraries like OkHttp from square which will let you do that with only 5 indented lines, not 20+. Request request = new Request.Builder() .url("http://example.com/upload") .post(RequestBody.create(IMAGE_JPEG, file) .build(); Response response = new OkHttpClient().newCall(request).execute(); But yes Go's standard library is cool, but Java's ecosystem is too, and larger.