
Introduction to Golang - tehmaco
http://www.altdevblogaday.com/2013/08/18/introducing-go/
======
programminggeek
I've just recently started playing with go and I think the most impressive
part is how close you can get to a dynamic language development feel without
sacrificing the benefits of static compilation, speed, binary distribution,
etc.

There is a lot to love about go and it is very quickly starting to look a lot
more interesting than other languages like ruby for future projects.

------
coolsunglasses
And for people who want to "level up" their programming skills and get an
excellent language for writing servers in with a great faculty for safely
concurrent semantics:

[http://clojure-
doc.org/articles/content.html#clojure_tutoria...](http://clojure-
doc.org/articles/content.html#clojure_tutorials)

~~~
defen
How is deployment with clojure? I haven't used either, but deploying golang
programs looks incredibly simple, whereas JVM wrangling (which I last did
years ago) was never fun for me. Does either one support erlang-style hot code
swapping?

~~~
coolsunglasses
You might be over-rating the usefulness of code hot-swaps in production with
Erlang. Erlang devs I've talked to have looked a little green in the gills
when I asked about it.

Coming from Python and Ruby, being able to just deploy a jar is a dream.

~~~
drdaeman
Python has packages ("eggs", although the term has multiple meanings, I'm
unaware of good unambiguous name to things you host on PyPI or alikes). You
put your code under a certain conventional directory structure, write simple
setup.py file and, well, that's about it.

(Although, as I happen to use mostly Debian-based systems, I prefer not using
Python packages directly but build .deb out of them with stdeb and use system
package manager to deploy. Just dput the built package to company's private
apt repo, and Puppets pull the update.)

~~~
coolsunglasses
Eggs are incomplete, broken, don't really solve the entire problem, and don't
even solve the problem they were designed to solve.

It's a mess, there are multiple factions and implementations, and until people
started consolidating there were 4-5 concurrent popular approaches to
packaging Python libraries.

I've lost tangible shards of my sanity to Python packaging and some of my poor
coworkers are fighting the terribly useless fight regularly still to this day.

Worse, most Python projects that have any non-trivial dependencies usually
entail NumPy, SciPy, or Cython.

Have you ever packaged something that's using multiple C and Fortran
dependencies for automated deployment? It's horrific.

Meanwhile, back when I'm at home and I use jBlas or any other Clojure, Java,
or Scala library here's what I have to do:

Add dependency to project.clj:

    
    
        [bulwark "0.0.3"]
    

Ship the jar.

    
    
        lein deploy $maven_repo
    

Writing Clojure code at home is incomparably more pleasant not just in pure
code, but in all the accouterments and tooling as well.

------
drdaeman
Tried the language recently. Wanted a in-memory data structure that could
represent a filesystem-like graph. Ran away when I understood (please correct
me if I got that wrong, but I wasted a whole weekend and found nothing) that
it's either totally type-unsafe void*^H^W interface{} all the way or I have to
write my own separate implementation for every and each type of graph I'll
use, without any significant way to reuse code.

~~~
cdoxsey
Without generics you'll need to use an alternative approach. As you said you
can use interface{} everywhere. Another option is to create an interface that
does what you need. Checkout "sort" for an example:
[http://golang.org/pkg/sort/#Interface](http://golang.org/pkg/sort/#Interface).

~~~
drdaeman
Sure, I can `type Tree struct { Child []*Tree; Node NodeType }`, where
`NodeType` is either `interface{}` (makes `Tree` reusable by sacrificing type
safety) or some concrete type (sacrifices `Tree`'s reuse) but that's about how
far I can progress. Also, I have to manually ensure that only one of Child or
Node is set, but not both.

I just can't do anything like `data Tree a = Leaf a | Node [Tree a]` there.

(Edit: okay, my mind swayed a bit, that was trees, not graphs. I had different
ideas on data structure to use, and my memories are a bit messy. Sorry about
this. The problem should still hold, it applies to both trees and graphs, and
I think many other data structures too.)

~~~
cdoxsey
The 'one of Child or Node' isn't really an issue since you probably shouldn't
expose the members of the struct (the tree should be accessed via methods).
But I agree with your point about containers.

------
JulienSchmidt
[http://i.lvme.me/4gl8uip.jpg](http://i.lvme.me/4gl8uip.jpg)

The up-to-date Go Users page is at [http://code.google.com/p/go-
wiki/wiki/GoUsers](http://code.google.com/p/go-wiki/wiki/GoUsers)

------
catnaroek
Taken from the article:

> "Strongly typed (with dyamic casting)" > "while Go is statically typed, it
> has a strong system for dynamic casting and reflection".

This is not even wrong. The _whole_ point to using types is to make strong
_guarantees_ about the meaning of programs without even having to run them.
Dynamic casting and reflection _destroy_ the usefulness of these guarantees,
by virtue of their semantics depending on information only avaluable at
runtime. Strong typing with dynamic casting and reflection is like a safe
knife whose handle is a blade!

> "Really good at concurrent stuff, pretty fast"

Give me a break. Concurrency support is all about compartmentalizing the use
of resources as much as possible, reducing sharing between the concurrent
units of computation (processes, tasks, goroutines, whatever you want to call
them) to the bare minimum required for the program as a whole to serve its
goal. How does Go's shared memory model help in this regard? This fundamental
inadequacy has negative consequences both for correctness (synchronization is
a convention, it is not actually enforced) and for performance (Go needs a
stop-the-world garbage collector).

===

Go might have been barely interesting ten or fifteen years ago, but in 2013,
this kind of design has to be rejected as mediocre.

~~~
azth
I don't know why you're being down voted. Your points are completely valid.
Without Google's name behind it, Go would not have had all this hype around
it.

~~~
catnaroek
Fanbois hate it when someone points at the flaws in their favorite language. I
still cannot comprehend why. As much as I like Haskell and Standard ML, if
someone pointed out their flaws (Haskell: lame module system, needing arcane
hacks to selectively introduce strictness; SML: no open sum types, no
applicative functors even when generative ones do not make sense), I would not
take issue with that. Realizing our tools are not perfect is the first step to
improving them.

I have nothing against Google, but their programming languages (at least, the
ones that I know of), Dart and Go, are really mediocre and uninspiring. For
all their bad reputation, Microsoft at least has F# and is indirectly involved
in the development of Haskell. Even Microsoft's take at an objected-oriented
language for the uneducated masses, C#, is much better than the Google- and
Apple-endorsed alternatives (Java and Objective-C).

------
nolok
For people who use go in production; what do you use for database abstraction
and mapping ? I found several "ORM" but either they throw static typing out
the window, or they seem to be way overblown in what they try to do (ending up
dictating how some of the data has to look in the database), I look only for a
database abstraction (which db/sql doesn't provide), does a good one exists ?

------
pixie_
Random question - but what happens when you divide by zero in go?

~~~
motter
[http://play.golang.org/p/TjzkjvDfYa](http://play.golang.org/p/TjzkjvDfYa)

~~~
mostafah
For people not familiar with Go Playground, that’s a compiler error.

~~~
Dewie
Does it only throw a compiler error if you use 0 as a constant? Let's say you
have a function that returns an int; does it force you to check if that int is
non-zero before using it in division?

~~~
chimeracoder
It can only throw a compiler error if you use a 0 literal (or constant),
because it cannot determine the runtime value of a variable denominator at
compile-time (obviously).

It does not force you to check, but if you wanted to "catch" the "exception"
(really, "recover from the panic"), here's how you would do that. Note that
this is admittedly a somewhat unidiomatic use of recover():
[http://play.golang.org/p/dAQ01dus9Y](http://play.golang.org/p/dAQ01dus9Y)

------
RamiK
"This isn’t a language for use in UIs or game clients, but it is an extremely
competent language for making servers, infrastructure or parallel/distributed
processing systems."

Golang has a GUI tool kit: the "net/http" and "html/template" packages. While
I personally hate EcmaScript with a passion, I have to admit every single GUI
tool kit or windowing system I've worked with had serious fundamental design
flaws not unlike JavaScript and the DOM. The entire scenario is not unlike the
Tcl\Tk days. People will bitch and whine but will do so while using it until
something better comes up.

~~~
pkaler
> Golang has a GUI tool kit: the "net/http" and "html/template" packages.

The article is written from the point of view of a game developer. He means
UIKit or WPF. Most games used to write their own UI controls.

------
mrschwabe
There sure has been a ton of Golang hype lately. At the risk of being
downvoted, just wanted to add my 2 cents: seems obvious to me that Google's PR
team has been in full motion on Go lately. At the very least, there are quite
a few Google fans active on HN routinely pushing Go. Which is no problem of
course.

I just find this somewhat frustrating given that we also have the massive NSA
surveillance scandal unfolding. Because I'd like to think that intelligent,
free-thinking hackers would opt for using products & technologies from
companies & organizations not so directly, deeply, and intricately involved in
said scandal.

Anyway, kudos to Dan for his detailed article - I'm sure he could care less
about the political alignment of the corporation he is getting his tools from
- and really it should be about technology first; so if Golang fits his needs
most optimally then by all means that's what he should be using. Just saying,
don't forget about the alternatives ;)

~~~
thezilch
FUD. What proof are you referring to that Google is "directly, deeply, and
intricately involved in said scandal?" Should the industry drop C++
(Microsoft) and Java (Oracle) support or similar (Scala, Python, etc)? AMD and
Intel processing? All American companies; completely ludicrous.

~~~
mrschwabe
[http://en.wikipedia.org/wiki/File:PRISM_Collection_Details.j...](http://en.wikipedia.org/wiki/File:PRISM_Collection_Details.jpg)

And there is plenty of other reading material to review regarding Google's
history with the NSA (see my other links posted in the nested comment below).

Perhaps I should not have said "directly, deeply, and intricately involved in
said scandal" in the tone of 'matter of fact' \- because it is indeed an
opinion, but I'm just drawing what I feel are logical conclusions. IMO Google
is the NSA's primary Trojan Horse into the free market. I am in no means
declaring this as fact, like I said originally - just wanted to drop my '2
cents' if that's OK.

~~~
thezilch
It goes deeper than that. You are suggesting that intellectual, free thinking
and Google can't coexist, or to work AT or WITH Google is to be not
intellectual nor free thinking. It's ludicrous to label Google employees and
users. You would suggest that Robert Griesemer, Rob Pike, Ken Thompson, and
those Google employees that publicly deny your FUD [0] can't be intelligent,
free-thinking hackers. Crazy.

[0]
[https://plus.google.com/app/basic/stream/z13qvvpjivahzpnbo04...](https://plus.google.com/app/basic/stream/z13qvvpjivahzpnbo04cghl5dpa2ytui4wg0k)
(Yonatan Zunger [Chief Architect, Google+] denies PRISM wholesale)

~~~
mrschwabe
I believe you're taking my comment out of context. I shared 'my 2 cents'; an
opinion - and did not label Google users or employees. I apologize if you
found my comment rude, but I clearly intended it to be taken with a grain of
salt.

