News for hackers. Stuff that matters.
Re:Go best practices, six years in by dineshp2 on Sunday May 01, 2016 @01:29PM (#11607005)
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?

Re:Go best practices, six years in by dalyons on Sunday May 01, 2016 @01:56PM (#11607120)
I've done a lot of ruby and go. Honestly, I would think twice before building a major website/product API on go. Development time is markedly slower in go, some causes off the top of my head:

- testing is way harder (ruby has some amazing mocking/stubbing/testing tooling).

- debugging is way harder. Hope you like printf.

- Json; the strict typing & struct searialization rules make dealing with Json a pain in the arse, and heavy on boilerplate

- interfacing with Sql (if you have to do a lot of it) is a pain in the arse, for similar reasons to json.

- having no stack for errors is insanely frustrating.

- templating in go is primitive

Go is amazing for services. The parallelisation primitives are fantastic, and allow you to do things that would be hard/impossible in ruby/Python. Go is undeniably much faster, execution wise. (Although our super high volume ruby product api is at 50ms median so, it matters less than you think)

Decide what you care about most; if your prime goal is to get a product in front of customers as soon as possible, I'd pick a higher level language. If you want to make a rock solid service that sips on resources & scales to the moon, use go.

Re:Go best practices, six years in by jsmthrowaway on Sunday May 01, 2016 @02:00PM (#11607144)
Median latency is a completely useless number. There is literally no use for it, ever. Satan invented median latency to confuse people, because it lies to you and whispers sweet nothings in your ear. Averaging latencies in your monitoring leaves the outliers out in the cold because you will never see them, and tail latency is way more important for user experience.

Quantile your latency. I suspect you'll find 99th tells an interesting story between Ruby vs. Go. The best latency graph has five or six lines at different percentiles (yes, including 50) stacked in a latency sandwich. I'm willing to bet your app has a rough 99th. Maybe even a rough 95th. Nothing against Rails (honest, this applies to most interpreters), but most scripted stuff has a pretty rough latency tail, and you ignore that with median. (Go is not off the hook either; GC pauses can blow out high percentiles if you're memory-heavy.)

I'm pretty passionate about this, sorry. I'm on a mission from God to purge our mortal plane of average/median latency, because it's one of those misapplications of statistics that everybody does without a second thought. Don't even collect it. Average latency is unimportant and misleads people, and misleads people more as you get more popular. It's that 1% of clients sitting there for 2sec that impacts perception of your UX.

Re:Go best practices, six years in by dalyons on Sunday May 01, 2016 @02:13PM (#11607202)
Sure, and I thought twice before putting that in :) We of course monitor our 95th & 99th primarily, for reasons that you said. But I didn't quote those because they're usually blown out by slow db queries, n+1 selects,n+1 cache gets, etc, issues that happen regardless of language. often they're on rarely used end points, where the cost-benefit of optimising isn't worth it. I feel median gives a resonable proxy for the language/framework execution capabilities.
Re:Go best practices, six years in by jsmthrowaway on Sunday May 01, 2016 @04:13PM (#11607668)
That response actually illustrates my point, oddly enough; median has comforted you to organizationally disregard the super interesting data you're getting from the percentile aggregations. Those blowouts are far more interesting than you're saying, I wager.

p99 blowout is generally an operational smell, even on low-RPS endpoints.

Re:Go best practices, six years in by dalyons on Sunday May 01, 2016 @09:05PM (#11608632)
I think we might be talking past each other a little :)

The median has absolutely not "comforted" us, nor do we disregard the percentile data. In fact, we have a whole perf team basically dedicated to looking at 95/9th & other slow transaction trace data, and fixing these.

In big projects, serving 10's of millions of users, with a handful of devs, you've gotta pick your battles, you cant fix everything always. We do our best, just like anyone else. So obviously we agree with the importance of percentiles. Dont make assumptions :)

And all of this is rather irrelevant to the main point now, which is overall _language_ speed.

Re:Go best practices, six years in by jsmthrowaway on Sunday May 01, 2016 @10:08PM (#11608825)
It's not, actually, and I'm not sure why you think I'm talking past you. Your claim was that Ruby is comparable performance-wise to Go in your application, and you cited median latency to make that case. I pointed out that interpreted languages often have a long tail and that the long tail is more interesting and undermines the comparison. You replied that I am correct and, indeed, you do have a long tail but you wrote it off as "stuff that happens" regardless of language. I am replying that the "stuff that happens" is the interesting stuff that undermines the flawed comparison you attempted to make, and I disagree that all of it can be written off to language-independent concerns; if you investigate it further, you might find some of it comes from the choice of language itself.

I have not wandered off topic into irrelevancy nor talked past you. This is still addressing the point you attempted to make by citing median latency in defense of the performance characteristics of your chosen language, in order to assuage general hesitance to adopt Ruby over performance concerns. I think you'll find that your metrics do not support your data if you dig into that p99.

(I share that experience from handling tens of millions of users myself, which is all I can admit to publicly, so that request re: assumptions goes both ways.)

To recap: claim submitted with flawed supporting data, thread addressing why the supporting data is flawed. No talking past taking place.

Re:Go best practices, six years in by dalyons on Sunday May 01, 2016 @10:40PM (#11608925)
Never claimed ruby was as fast as go. Our go services run at about 5-15ms(excluding 95/99 etc), so they're def faster(they do a lot less too!). I'm just saying ruby (or other dynamic langs, i dont mind, I dont have a "chosen language") can make a decently fast product API, and thats all.

And of course we've investigated further... (this is anecdotal i know), but of all the degenerate 99th cases we've investigated/solved, I can only think of 2 or 3 that were lang related, rather than logic, db, n+1s, etc. If you're curious, those were: - degenerate GC behaviour in a specific circumstance - JSON serialization (specifically crossing the C/ruby boundary shiteloads of times to serialize an object) Sure these issues sucked, but we mitigate/sidestepped those issues for the most part.

It's all a trade off when you're trying to decide what to use for your project; right tool for the job etc. Im not evalganizing for or against anything.

Curious what would you propose instead to roughly compare speeds of a product API? (Keeping in mind my anec-data about nearly all of 99ths being a logic/db issue). Comparing 99ths (from my experience) would be more like comparing which codebase has more bugs, because thats how we treat degenerate cases.

Re:Go best practices, six years in by jsmthrowaway on Sunday May 01, 2016 @11:11PM (#11609025)
> Never claimed ruby was as fast as go.

Fine, you claimed the performance difference "matters less than [one thinks]," which is pretty much the same thing if you really step back and think about it. It's also wrong for a whole cornucopia of reasons in general, but I'm choosing to focus on the supporting data you used to make that claim.

> Our go services run at about 5-15ms(excluding 95/99 etc),

See, nobody can resist middle-ground aggregations to describe things, even in a thread about middle-ground aggregations! They are such a cognitive trap. You should say "our Go services run at about 5-15ms half the time," because that'd be more correct if my assumption about where that aggregation is coming from is correct (and I'm guessing it's a gutstimate of median). And, again, 95th and 99th are super interesting, particularly when describing the performance characteristics of a latency-sensitive service, and it's a disservice to omit them.

I will absolutely say "about ___ms" and refer to my 99th and let people think I'm telling them average. To me, 99th is my average. (Normally I'd ignore this as pedantry, by the way, but it's the subject of the thread...)

> - JSON serialization (specifically crossing the C/ruby boundary shiteloads of times to serialize an object)

All of the terrible code in the world that handles JSON is one of my favorite "make this app go faster" targets. Its ease and ambiguity is its downfall, because people write genuinely awful code to interact with it. Most of that code is in language standard libraries. I will stand by that remark no matter how much you challenge me on it.

I'm of the fun school of thought now where I treat JSON as an external hot potato and throw it in a sane bag at the edge like protobuf or Thrift internally. If your internal services are communicating in JSON you are wasting a lot of cycles and bandwidth for pretty much no reason. You can switch to MsgPack and get an immediate win if IDLs aren't your thing, or CapnProto and get an even bigger win if they are. If you like being on the fun train, protobuf3+grpc is a pretty fun environment. This complaint even applies to Go even though Go shipped JSON in the standard library with clever reflection, so now everybody wants to lazily expect JSON configuration files which map cleanly to their internal config struct (please, stop doing this and write configuration formats that don't completely suck; looking at you, CoreOS).

Does serialization really matter, you ask? Profile your application and watch how much time it spends dealing with JSON. I've seen switching away from JSON remove the need for entire machines at scale. Whole machines. Because that many cores were freed up by not making every single instance spend 5-6% of its time marshaling and unmarshaling data.

> Comparing 99ths (from my experience) would be more like comparing which codebase has more bugs, because thats how we treat degenerate cases.

In other words, I was correct about organizational comfort with how you interpret 99th percentile latencies.

99th are not your degenerate cases. The poor souls in the 1% are your degenerate cases, and they are users too. A bad 99th percentile latency is bad, no matter how you justify it. Most folks write off 99.9th latency; 99th is a bit strong, especially if we're talking about your 10MM+ (M?)AU app. 1% of requests is a shitload of requests if your volume is as high as your audience description implies. I'm weird in that I consider a strange 99th+ as interesting data worthy of investigation, but I think that should be the norm, too.

As for comparing the performance characteristics of two separate apps, the metrics I'd start with are going to be RPS, TTFB, and TTLB. For the times I mentioned, σ (my personal favorite) as well as 50th, 75th, 90th, 95th, 99th, and 99.9th percentiles. Those are the externally-interesting ones. I also want to know how many cores are running it, how much RAM it consumes, and a whole bunch of other stuff on the inside. But it's a poor comparison at all, really; no two codebases are directly comparable, which I think you already know.

Re:Go best practices, six years in by bumbledraven on Sunday May 01, 2016 @04:20PM (#11607695)
Grandparent's point is that 99th percentile latency is, for their application, unrelated to the ruby-vs-Go comparison.
Re:Go best practices, six years in by IanCal on Sunday May 01, 2016 @07:53PM (#11608410)
> Average latency is unimportant

That feels like an overly-bold claim. Improving your 99th percentile latency from 2 seconds to 1 second may not be worth it if you bring your average latency up from 0.05 seconds to 0.99 seconds.

> It's that 1% of clients sitting there for 2sec that impacts perception of your UX.

Well, surely that depends on what endpoints those are and what people are expecting from them. A 2s wait for a whole rendered dashboard page of your entire organisation may not really be a concern. A 2s wait for 'find out more about our fast CDN' might really harm sales.

Now, if your point was "you shouldn't only look at average latencies" then you're entirely right, but I cannot see how they're irrelevant. The overall distribution is important and I'd actually recommend that people look at this shape. Just picking one percentile is always going to be misleading because you're throwing away a vast amount of data.

Re:Go best practices, six years in by jsmthrowaway on Sunday May 01, 2016 @08:08PM (#11608478)
That actually was my point, and at no point did I say only look at one percentile. I in fact said look at five or six, stacked, including median/p50. I implied that median latency is only useless by itself, or so I thought, so I apologize if that was unclear. It is perfectly fine in concert with other aggregations. This is the type of graph I mean:

       |                 ====   p99
       |=================       
    ms |+++++++++++++++++++++   p95
       |.....................   p75
       |`````````````````````   p50
       |---------------------
        t ->
That outlier jump might be a production emergency, such as a database server dying or something. Yes, really. Had you only graphed median here, you would have missed it until some other alarm went off.

You gain a lot from this. Visually, you can see how tight your distribution is as the rainbow squeezes together. Narrower the better. Every time. In fact, very often the Y axis is irrelevant, and here's why:

Reining in your p99 that far at the expense of a higher average is, oddly, a win. That might surprise you but it is borne out in practice, because at scale only the long tail of latency matters. A wide latency distribution is problematic, both for scaling and for perception. A very narrow latency distribution is actually better. If you can trade off a bit higher latency for less variance/deviation, it will be a win every time. Weird, I know. User perception is weird and, as you point out, the rules change per-endpoint. Perception tends to evolve, too. As a rule of thumb, though, tighter distribution of latency is always better and how far you can push median to get there is your business decision and user study environment.

To borrow one of Coda Hale's terms[0], the scenario you presented demonstrates the cognitive hazard of average and is actually my root point. The average came up, yes. That is not necessarily bad (at all!), but "average" intuitively tells you that it maybe should be. In this case, it is misleading you, because the exact scenario you presented might be a strong win depending on other factors. A 99th of 1000ms with a 990ms average is a really tight latency distribution so it is fairly close to ideal for capacity planning purposes. It blew my mind when I discovered that Google actually teaches this to SREs because, like you, how unintuitive it is threw me off.

It's hard to swallow that a 990ms average might be better than 50ms. Might be. Average doesn't tell you. That's why it sucks. Not just for computing, either; average is pretty much the worst of the aggregations for cognitive reasons and is really only useful for describing the estimated average number of times you fart in a day to friends, because it is quite overloaded mentally for many people without experience in statistics.

[0]: https://www.youtube.com/watch?v=czes-oa0yik

Re:Go best practices, six years in by stock_toaster on Sunday May 01, 2016 @02:09PM (#11607185)
Your cause is just. Keep fighting the good fight!
Re:Go best practices, six years in by yxhuvud on Sunday May 01, 2016 @02:30PM (#11607288)
> Median latency is a completely useless number. There is literally no use for it, ever. Satan invented median latency to confuse people, because it lies to you and whispers sweet nothings in your ear. Averaging latencies in your monitoring leaves the outliers out in the cold because you will never see them, and tail latency is way more important for user experience.

Umm, you do not get the median latency by averaging anything. Median latency is just the 50th percentile. It is definitely not one of the interesting ones to reason about or care about improving, but not valueless to measure. It is interesting to have if you are graphing your latency curves, to make an example.

Re:Go best practices, six years in by jsmthrowaway on Sunday May 01, 2016 @04:09PM (#11607658)
I think if you reread my comment you'll find that what you're saying does not actually disagree and is a restating of what I said.
Re:Go best practices, six years in by yxhuvud on Sunday May 01, 2016 @04:36PM (#11607754)
It is not. Your comment confuses the median with the mean latency. The comment you replied to did not mention using averages - it mentioned only using the median. You introduced scathing critique of using averages when those are only used for means and therefore totally irrelevant here (even if I totally agree that people that use them should be educated. But that wasn't the case here).
Re:Go best practices, six years in by jsmthrowaway on Sunday May 01, 2016 @04:38PM (#11607766)
I actually don't, and you're reacting to the use of "averaging" as a verb. That's why I encouraged you to reread. When you're discarding 50% of the samples in a 50th percentile median, I think "averaging" is an acceptable verb to proxy the situation in English since "medianing" isn't a word. I could have said "computing the median," but that's just tedious.

Notice later in the comment I say average/median, implying that they are separate but related concepts. I think it's safe to assume that someone who can conversationally use the word "quantile" is not confusing median with mean. You're assuming that my (intentional) selection of a lower-fidelity term to describe a concept, which I carefully illustrated with ancillary points to give specificity to said concept, demonstrates a misunderstanding of the very field I'm explaining. That is pretty obviously wrong and a bit condescending.

We agree, which is what's frustrating. You're just latching on to a pedantic correction of my point, and rather than belabor that correction I encouraged you to reread to see that we do actually agree. Now, I do see average latency far more often than I'd care to admit, which is why I got lazy and just said "average" at the end there once I started referring to generality instead of specificity, but I think it's pretty clear that I understand the distinction regardless.

Re:Go best practices, six years in by skj on Sunday May 01, 2016 @09:16PM (#11608665)
In statistician-land, the median is simply one way of averaging, as is the mean. Introducing (or at least using) the extra term takes care of some ambiguity.
Re:Go best practices, six years in by pstuart on Sunday May 01, 2016 @04:55PM (#11607829)
> debugging is way harder. Hope you like printf.

You have other options: https://github.com/derekparker/delve

Re:Go best practices, six years in by jud_white on Sunday May 01, 2016 @08:16PM (#11608499)
> having no stack for errors is insanely frustrating.

Check out https://github.com/pkg/errors

If you want more rich control of the output of the stack trace there's https://github.com/go-stack/stack

Re:Go best practices, six years in by dalyons on Sunday May 01, 2016 @08:55PM (#11608603)
Yeah, we've started using that. Kind of amazing that you need an addon lib & Wrap() everywhere to make errors useful. Just more boilerplate! :)
Re:Go best practices, six years in by gkya on Sunday May 01, 2016 @04:43PM (#11607785)
> - debugging is way harder. Hope you like printf.

Can't you use gdb with Go? https://golang.org/doc/gdb

Re:Go best practices, six years in by spriggan3 on Sunday May 01, 2016 @04:48PM (#11607805)
The second you launch a Go routine, gdb becomes useless.
Re:Go best practices, six years in by gkya on Sunday May 01, 2016 @05:21PM (#11607905)
How do you debug then? (I'm not a Go coder, tho I'm familiar a bit with it)
Re:Go best practices, six years in by sacado2 on Sunday May 01, 2016 @06:01PM (#11608056)
Oh, that's simple. We gophers don't make any mistake. Ever. It makes our lives easier.
Re:Go best practices, six years in by jsmthrowaway on Sunday May 01, 2016 @11:02PM (#11608990)
This is wrong. The answer is obviously "Go is debugged in production with extensive logging," so I question whether you're actually a gopher.
Re:Go best practices, six years in by shurcooL on Sunday May 01, 2016 @05:51PM (#11608024)
See another answer in this thread, https://news.ycombinator.com/item?id=11607829.
Re:Go best practices, six years in by shurcooL on Sunday May 01, 2016 @02:32PM (#11607294)
I really enjoy using Go for building websites. But I use Go for everything, including games, frontend (instead of JavaScript), etc. There's nothing else I'd rather use. Heck, I even rewrote my resume in Go that renders HTML on frontend [0], hehe.

[0] view-source:https://dmitri.shuralyov.com/resume

Re:Go best practices, six years in by matthewmacleod on Sunday May 01, 2016 @02:22PM (#11607248)
My experience says "don't use Go for building web applications".

Compared to something like Ruby on Rails, the development story with Go is much less batteries-included. You'll find yourself gluing together lots of components, and they're not really that friendly. Plus, for any front-end code, you'll end up using Node or whatever anyway to build assets. It's big and messy and not a good match.

Go does excel at two kind of web applications however:

- Simple single-page applications that use Websockets or simple AJAX to perform a basic task. In this case, the limitations around templating and such are less obvious, and Go is a brilliant match for Websocket clients. Think of things like status dashboards.

- JSON APIs with no front-end. Build your front-end using whatever other technology, and just fire requests at a Go app. It's pretty good at handling this, though JSON marshalling/unmarshalling is a bit stupid in Go.

Re:Go best practices, six years in by ver4no on Sunday May 01, 2016 @02:49PM (#11607367)
what would you use go for then?
Re:Go best practices, six years in by spriggan3 on Sunday May 01, 2016 @04:42PM (#11607778)
People use Go to write "infrastructure services", such as Rest APIs, caches, proxies,queues ... and command line tools. That's what Go does best since it requires minimal investment upfront( the language is tiny, the standard library has a lot of network oriented code...).

Whether one can effectively write a classic website with complicated HTML templates and web forms like Rails,JSF and co allow is however questionable since Go type system lacks of expressiveness. Go fans answer is "use client side javascript" which is ironic since javascript is the antithesis of Go in terms of design.

Re:Go best practices, six years in by matthewmacleod on Sunday May 01, 2016 @08:57PM (#11608613)
Go is great for what is describe as "plumbing" - things like proxies, infrastructure tools or simple microservices. The simplicity is a great benefit in these cases.

I've also found it unexpectedly useful for some embedded applications. Deployin code to the raspberry pi is super simple and that makes it quite attractive - there are projects that provide for thing like i2c, GPIO and SPI, and combined with the built-in HTTP support its a pretty compelling platform.

Re:Go best practices, six years in by BuckRogers on Sunday May 01, 2016 @09:58PM (#11608790)
> Go is great for what is describe as "plumbing" - things like proxies, infrastructure tools or simple microservices. The simplicity is a great benefit in these cases.

Those reasons aren't really convincing to add another platform into the stack for me. I'd just continue using the many good-enough technologies to build those things on.

I was getting into Go some years ago and came to the same conclusion as you stated. It's good of course if its someone's favorite language to use, then it doesn't matter what it is and isn't great at. But in the end for me it didn't do enough, or do enough better than existing broad PLs that I already knew.

I think Go is still in need of a "killer usecase" to justify its usage for people like me. Rails was that for Ruby. Linux entrenchment and Django was that for Python (now numerics and scientific computing). Node for JS. That said, I'm a Go fan in theory as a "simple is better" type.

Re:Go best practices, six years in by iamd3vil on Sunday May 01, 2016 @01:42PM (#11607057)
I worked with both Go and Elixir but found Elixir and Phoenix better than Go for building backends for web services. I was more productive and all the awesomeness of Erlang VM made me choose Elixir. I would say give Elixir a try.
Re:Go best practices, six years in by 55tine on Sunday May 01, 2016 @04:40PM (#11607772)
The other answers provided plenty of info on Go, so if you're looking for a new language and framework for web dev I suggest checking out elixir and Phoenix. They're inspired by ruby/rails (without some of the problems) and have many of the benefits of erlang.
Re:Go best practices, six years in by tyingq on Sunday May 01, 2016 @02:03PM (#11607156)
>>How does Go ... compare in terms of performance, ease of development with RoR, Laravel?

The available web frameworks for Go are more comparable to microframeworks like flask. If comparing directly to RoR or Laraval, you may find some gaps. Not that they can't be solved, but there's less available out of the box. Things like:

- multiple file upload

- session handling without cookies

- built in support for a variety of authentication types and backends

The communities are also significantly smaller, so there's less experience to draw on.

Not to say you can't build websites just fine with golang, but it's doesn't seem to be a strong suit at the moment.

Re:Go best practices, six years in by andreynering on Sunday May 01, 2016 @04:19PM (#11607690)
RoR is an awesome framework that has (almost) everything you need to build monolithic web apps.

Go is a different story. You need to join the pieces together to make something functional. You will probably need:

- A router like [Gin](https://github.com/gin-gonic/gin)

- A [XSRF token generator and validator](https://github.com/golang/net/blob/master/xsrftoken/xsrf.go)

- An ORM like [Gorm](https://github.com/jinzhu/gorm) or [XORM](https://github.com/go-xorm/xorm)

- A template lib like the one that comes with the stdlib

- Node for front-end (ugh, this is the harder part)

- The testing library in stdlib plus maybe [testify](https://github.com/stretchr/testify)

- etc...

Many nice things are missing. Some were [shamelessy copied by other people](https://github.com/go-testfixtures/testfixtures). Some you may need to implement yourself.

The big advantages is that Go has much better performance, and run on Windows, etc.

Re:Go best practices, six years in by jimjimjim on Sunday May 01, 2016 @07:24PM (#11608301)
err... RoR is a full-size framework. Ruby is the language. Go is a language. Go has frameworks.

You are comparing apples to oranges. With go you can then select what functionality, libraries, toolkits or frameworks you want to use with your system.

ps. why would you mention node? would you use node with a php site?

Re:Go best practices, six years in by andreynering on Sunday May 01, 2016 @07:59PM (#11608446)
> Go has frameworks

I don't know nothing monolithic like Rails for Go, do you? What I was trying to say is that you have to use libs, instead of a big monolithic framework like Rails, that do not exists for Go (AFAIK).

I don't like Node and NPM, but it would be the alternative to Asset Pipeline (e.g. for concatenating and minifying JS and CSS, etc).

Re:Go best practices, six years in by cjslep on Sunday May 01, 2016 @08:08PM (#11608479)
> I don't know nothing monolithic like Rails for Go, do you?

Revel is pretty monolithic: https://revel.github.io/

I've used it to build a web application, and here are some of the problems it addresses (this is just the table of contents from their manual):

    - Controllers
    - URL Routing
    - Request Parameters
    - Validation
    - Session & Flash
    - Results & Response
    - Templates
    - Interceptors
    - Filters
    - Websockets
    - Internationalization
    - Cache
    - Database
    - Debugging
Re:Go best practices, six years in by lastofus on Sunday May 01, 2016 @06:58PM (#11608224)
Can you explain more about using Node for the front end? Do you mean you use `npm` for front-end package management, or are you running a Node server process along side your Go process on the backend?
Re:Go best practices, six years in by andreynering on Sunday May 01, 2016 @08:02PM (#11608462)
Yes, I am talking about asset management. Rails has Asset Pipeline. In Go, if you want a build step for JS and CSS you have to play with node.
Re:Go best practices, six years in by bkeroack on Sunday May 01, 2016 @08:38PM (#11608556)
You don't actually need most of that.
Re:Go best practices, six years in by pella on Sunday May 01, 2016 @01:53PM (#11607101)
Re:Go best practices, six years in by Thaxll on Sunday May 01, 2016 @01:32PM (#11607025)
Go is pretty good for anything backend related.
Re:Go best practices, six years in by asimuvPR on Sunday May 01, 2016 @05:50PM (#11608019)
My experience over the years is that Go serves a specific niche ver well. The niche being boring long running services that do simple tasks in unison with other services. It's better to see it as a language wi th which you can build little self contained machines that work well together. I have a system made up of such little machines and it quietly works away at some low end server.
Re:Go best practices, six years in by eternalban on Sunday May 01, 2016 @03:03PM (#11607421)
No, that is definitely not correct, unless your "anything" is merely that which is fully defined & composed at compile time.

(And yes, you can go the IPC route to introduce dynamism that you get out of the box from a VM based language. But here is the classic case of the Go [tail] wagging the architecture [dog]..)

[edit: correct tail endian]

Re:Go best practices, six years in by ereyes01 on Monday May 02, 2016 @01:15AM (#11609310)
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 by mmargerum on Tuesday May 03, 2016 @05:06AM (#11619004)
The cost and pain of developing software is approximately zero compared to the operational cost of maintaining it over time

not my quote