Live data from Hacker News

Go best practices, six years in

peter.bourgon.org

141–150 of 207 posts

Re: Go best practices, six years in

#141

Earlier quoted context omitted.

Java was: 1. Wow, this program runs on any platform! 2. Wow, no need to free memory! 3. Wow, threads and locks are so easy to do! Then many years later 4. Who really cares about cross-platform code if all I do is on Linux? 5. Why does this program require 4GB of ram? 6. Must I really download and install the JVM all the time, and what is it good for anyway? Go: 1. Wow, I can write stuff that previously could only be…

> 4. Who really cares about cross-platform code if all I do is on Linux? Most developers write their code on Windows and MacOS and then deploy on Linux. I'd say this "Write once run anywhere" thing was and still is a pretty big deal. > 5. Why does this program require 4GB of ram? Oh no! I need to buy a $5 piece of hardware to run this Java code? What kind of nonsense is that? > 6. Must I really download and install t…

> Oh no! I need to buy a $5 piece of hardware to run this Java code? What kind of nonsense is that?

Funny. That's Microsoft line of thought with Vista.

Re: Go best practices, six years in

#142

Earlier quoted context omitted.

Java was: 1. Wow, this program runs on any platform! 2. Wow, no need to free memory! 3. Wow, threads and locks are so easy to do! Then many years later 4. Who really cares about cross-platform code if all I do is on Linux? 5. Why does this program require 4GB of ram? 6. Must I really download and install the JVM all the time, and what is it good for anyway? Go: 1. Wow, I can write stuff that previously could only be…

> 4. Who really cares about cross-platform code if all I do is on Linux? Most developers write their code on Windows and MacOS and then deploy on Linux. I'd say this "Write once run anywhere" thing was and still is a pretty big deal. > 5. Why does this program require 4GB of ram? Oh no! I need to buy a $5 piece of hardware to run this Java code? What kind of nonsense is that? > 6. Must I really download and install t…

> Oh no! I need to buy a $5 piece of hardware to run this Java code? What kind of nonsense is that?

4 GB per program absolutely destroys VM consolidation. I love the look on managers' faces when they ask for a 1 GB VM and I ask them, "Is this for a Java program?" :)

Re: Go best practices, six years in

#143
post #6

Slightly tangential, but, could someone share their experience using Go specifically for building websites? How does Go (including Go frameworks specifically geared towards web development) compare in terms of performance, ease of development with RoR, Laravel? Is building websites using Go a good use case or is Go better suited for building high performance microservices?

As you probably know (and as you can probably tell from some of the responses here), sometimes choosing languages can be like choosing a religion :-)

As a backend for a web application, Go's performance is pretty great. The Go standard library comes with a fast parallel-enabled HTTP server that already makes use of all your cores in recent Go versions. No need for things like gunicorn to take advantage of cores. There's no interpreter overhead, and there's plenty of benchmark comparisons with other languages out there on Google. I've never heard of someone not using Go as a server-side language because it wasn't fast enough :-)

Go has very robust support for creating web applications. Of course, for the frontend you will still need HTML+CSS+JS (maybe + a JS framework like Angular depending on your needs). There is a crazy experiment called GopherJS to run Go in the browser/frontend, but currently, a crazy experiment is all it is IMO...

For serving dynamic content, the Go standard library comes with its own templating language and library: https://golang.org/pkg/html/template/

The standard library also comes with most of the tools you'll need for defining HTTP routes (see the server examples): https://golang.org/pkg/net/http/

Personally, I've found the following third-party packages to be quite helpful with putting together HTTP server-side apps in Go:

  - Gorilla mux for defining templated routes: https://github.com/gorilla/mux
  - Negroni for HTTP route Middlewares: https://github.com/codegangsta/negroni
For testing HTTP server-side Go applications, the httptest package is quite helpful: https://golang.org/pkg/net/http/httptest/

As you can see, most of what you need just comes with the standard library, which is quite professionally designed and coded (reading through their source is a pleasure). The two external dependencies I mentioned are helpful, but not a strict requirement to build a server-side app.

The main obstacle people have with using Go IMO has little to do with its ability to be used as a server-side language, and more to do with the nature of the language, and the consequences of its design choices. I think people who strongly prefer terse dynamic languages have trouble adopting/enjoying Go and its way of doing things. For instance, someone in this thread said that Go's structs and static typing makes it harder to work with JSON. You could also make the argument that this is a strength- all I have to do is declare a struct to specify what exactly I want to read from / write to JSON. Some people have complained about Go's verbosity. Sometimes they are right- certain things in Go take a little more text to express. I'm convinced that Go is a language that is more optimized for readability than for writability. You typically can't write "expressive" koans in a line of code... but your teammates probably have a higher chance (in my subjective opinion) of understanding the Go code you wrote a year after you've forgotten what you were thinking about.

I could go on and on, but now I'm just fighting the eternal language holy wars :-)

I hope I've given you a starting point for more research if you were considering Go for a server-side web application.

Re: Go best practices, six years in

#144

Earlier quoted context omitted.

I'm guessing his point is that "4 GB" is a big problem on a phone.

Yes it is, but his number was an exaggeration in the first place. There are hundreds of millions of phones running Java today, what does that tell you?

The point is that memory still matters, not that Java is inherently a problem. You're shifting the goalpost here - earlier your claim was that 4GB is not a big deal since we can just buy more memory, now it's that 4GB is a ridiculous number anyway.

It's not if you meet one of these typical "don't do any premature optimisations (even in the design phase of my data structures), because some important CS person said so"-designs. There's all too many programmers who think they should never have to care about hardware anymore.

Re: Go best practices, six years in

#145

Earlier quoted context omitted.

Java was: 1. Wow, this program runs on any platform! 2. Wow, no need to free memory! 3. Wow, threads and locks are so easy to do! Then many years later 4. Who really cares about cross-platform code if all I do is on Linux? 5. Why does this program require 4GB of ram? 6. Must I really download and install the JVM all the time, and what is it good for anyway? Go: 1. Wow, I can write stuff that previously could only be…

> 4. Who really cares about cross-platform code if all I do is on Linux? Most developers write their code on Windows and MacOS and then deploy on Linux. I'd say this "Write once run anywhere" thing was and still is a pretty big deal. > 5. Why does this program require 4GB of ram? Oh no! I need to buy a $5 piece of hardware to run this Java code? What kind of nonsense is that? > 6. Must I really download and install t…

> Once or twice a year, if you really want to.

I really hope you actually mean 7+ times a year. https://en.wikipedia.org/wiki/Java_version_history#Java_8_up... - most versions contained security updates.

Re: Go best practices, six years in

#146
post #64

Earlier quoted context omitted.

> For instance, there's a ton of Go repositories out there that are not go gettable because the author wanted to put source code under a src directory and hacked that together using make. Are there? If someone's that ignorant of the language, I don't think I'd want to run something written by him … > And good luck with organizing any repository that contains multiple languages where go is one of them...go's "code liv…

> Are there? If someone's that ignorant of the language, I don't think I'd want to run something written by him … Yes, there are. I don't know any off the top of my head, but I see them all the time. So, just for fun, how about a little test: Step 1: Google 'notable applications written in golang' >> first result: http://www.infoworld.com/article/2843821/application-develop... Step 2: Click through to github repos >>…

[deleted]

Re: Go best practices, six years in

#147
post #62

Earlier quoted context omitted.

I don't know, I want to like Rust, but every time I pick it up I feel like I'm relearning C++. It's learning curve is steep, the sorts of applications I write benefit more from solid development velocity and a good concurrency story. I might be wrong, but I get the feeling that Rust really only shines where performance and meticulous control are paramount. I want to like it, but it feels ill-suited to the application…

>I feel like I'm relearning C++ Because you are. You likely wrote widly unsafe things which are perfectly legal in C++. Rust is really just enforcing RAII which C++14 already has, and you've likely avoided.

C++has had RAII for decades already. Actual Rust innovations are the borrow checker and dynamically sized types.

Re: Go best practices, six years in

#148

Earlier quoted context omitted.

> 4. Who really cares about cross-platform code if all I do is on Linux? Most developers write their code on Windows and MacOS and then deploy on Linux. I'd say this "Write once run anywhere" thing was and still is a pretty big deal. > 5. Why does this program require 4GB of ram? Oh no! I need to buy a $5 piece of hardware to run this Java code? What kind of nonsense is that? > 6. Must I really download and install t…

> Oh no! I need to buy a $5 piece of hardware to run this Java code? What kind of nonsense is that? 4 GB per program absolutely destroys VM consolidation. I love the look on managers' faces when they ask for a 1 GB VM and I ask them, "Is this for a Java program?" :)

Just adding some ram is also not so easy in an embedded system.

Re: Go best practices, six years in

#150

Earlier quoted context omitted.

At some point mid #3 I finally hit the "I think it's time to just learn Elixir for every situation where I don't need a portable binary..." So far, looking like a solid decision.

I'm looking to transition from Rails to something more performant. Phoenix is at the top of my list, but these benchmarks worry me: https://www.techempower.com/benchmarks/#section=data-r12&hw=... https://www.techempower.com/benchmarks/#section=data-r12&hw=... In both Phoenix has very high error rates, and in the first it seems really slow. Here is their Phoenix test app: https://github.com/TechEmpower/FrameworkBenchm…

The benchmark for Phoenix was done at the last minute, and had a lot of problems which they didn't have opportunity to fix. The next round will be better.
Post reply on HN