News for hackers. Stuff that matters.
Re:Half a decade with Go by wwweston on Monday November 10, 2014 @05:58PM (#8587191)
OK, I'll admit it. I've spent six months with Go. I keep waiting for the moment when I understand it, maybe even develop some enthusiasm for it, and reach Pike-enlightenment.

And I pretty much hate the language. I feel like I'm writing in something that combines the worst weaknesses of Pascal and Java. In fact, Mark Dominus' comments about Java (http://blog.plover.com/prog/Java.html ) approximate my experience Go far better than I would have guessed when I started the project I'm on.

People who seem to be smart nevertheless keep talking it up... some not even as just a good tool but as their favorite language.

So I'll ask: What is it I need to read/work through in order to at least "get" Go and really understand its strengths (whether or not I end up liking it)?

Re:Half a decade with Go by MetaCosm on Monday November 10, 2014 @11:34PM (#8588314)
Composition. That is the single biggest thing that has impressed me as my codebase has grown. Concurrency and messaging is nice, but I come from Erlang... I am not easily impressed by concurrency and messaging. Composition, the power of interfaces in complex systems is the key for me. It is what makes me stay with Go, and why I will probably stick around for a long time. It is so obnoxiously useful, without ever getting in my way. Let's talk for a second about the tiny little function

io.Copy(dst io.Writer, src io.Reader)

It reads data from reader and writes to writer... simple. Now what makes this little function so darn useful is it takes anything fulfilling its interfaces (io.Writer and io.Reader). The first way you will probably use it will be to copy between some stream and a file without having to eat up all the memory to store the buffer (not using ioutil.ReadAll for example)... but then you realize you can use a gzip compressor on the writer side, or a network socket, or your own code... and io.Copy works with anything that fulfills its interface.

As you build out a complex application, you start by creating your own functions that take advantage of existing interfaces foo.OCR(dst io.Writer, src img.Image). After that you start building out your own interfaces... like a MultiImage interface that has ImageCount and ReadImage methods that returns the count of images and binary data... but then you realize the images could be big, so you make the ReadImage method return an io.Reader... and now you have gone full circle and are using io.Copy to copy imageX from a stack of images to return to your OCR function that will output the data to an io.Writer which you made actually a gzip writer because text compresses well.

Beyond composition -- obviously, the concurrency and messaging is nice and when you need it vital. The other thing that will help make Go "click" is being very "data oriented" in your design... be vicious and minimal: http://youtu.be/rX0ItVEVjHc (great talk on data oriented design) and be absolutely pragmatic, focus on getting shit done, always...

Re:Half a decade with Go by coldtea on Tuesday November 11, 2014 @04:09AM (#8588981)
>It reads data from reader and writes to writer... simple. Now what makes this little function so darn useful is it takes anything fulfilling its interfaces (io.Writer and io.Reader). The first way you will probably use it will be to copy between some stream and a file without having to eat up all the memory to store the buffer (not using ioutil.ReadAll for example)... but then you realize you can use a gzip compressor on the writer side, or a network socket, or your own code... and io.Copy works with anything that fulfills its interface

And how is that any different than any language with interfaces? (Besides the implicit thing?).

Re:Half a decade with Go by arnehormann on Tuesday November 11, 2014 @04:37AM (#8589060)
Because of the implicit thing! The api designer doesn't have to write the interface, you can do it yourself. As long as naming conventions are kept to and the signature matches, you can apply this anywhere.

Imagine a close() interface in Java. There isn't one - but having a try {...} finally { x.close(); } can be very useful sometimes. But having interface graphs made of granular interfaces makes everything slow and causes a lot of complexity when you try to think about your type hierarchy. That's why interfaces always just grow and you can't use them any longer because other classes only implement part of the api. Something usable for all of awt, swing, file handling, random foreign libraries? Unthinkable. Also, adding something in a later release (like CharSequence in 1.4) can have a wide ranging impact and requires you to change a lot of code.

In Go, you just add an interface from the union set of multiple structs api - and you can use it. No matter who wrote those structs. The value is enormous. Think of it as something like dependency injection at compile time.

Re:Half a decade with Go by mschulze on Tuesday November 11, 2014 @06:45AM (#8589365)
>Imagine a close() interface in Java. There isn't one

https://docs.oracle.com/javase/7/docs/api/java/lang/AutoClos...

You can even leave out the finally when you use an autocloseable resource.

    //r will be closed no matter what
    try(Resource r = getResource()) {

    } catch(SomeException e) {

    }
Re:Half a decade with Go by arnehormann on Tuesday November 11, 2014 @07:13AM (#8589440)
My Java is getting rusty... I read about this sometime somewhere but forgot it, thanks! I should have picked something like "String getText()", then.
Re:Half a decade with Go by pjmlp on Tuesday November 11, 2014 @05:53AM (#8589249)
> Because of the implicit thing!

Known as structural typing and available in most modern languages.

Re:Half a decade with Go by icebraining on Tuesday November 11, 2014 @06:27AM (#8589319)
available in most modern languages

Well, "modern" is an ill-defined concept. As far as I'm aware, structural typing is not really that common, is it? Besides OCaml and Scala, is there any relevant (used outside of academia) language that supports it?

Re:Half a decade with Go by pjmlp on Tuesday November 11, 2014 @06:50AM (#8589378)
D and C++ templates for example.

F# also supports it, given its ML linage.

C# tricks with dynamic, although in this case it is dynamic typing, so not really the same thing.

Re:Half a decade with Go by seabee on Tuesday November 11, 2014 @07:14AM (#8589441)
The disadvantage of C++ templates is the structural type is implicit - you only know if the input object satisfies the type if you read the documentation, code, or can decipher the error message that occurs if it didn't.

Concepts would have fixed this, but we don't have concepts and maybe never will!

Re:Half a decade with Go by pjmlp on Tuesday November 11, 2014 @08:20AM (#8589626)
> Concepts would have fixed this, but we don't have concepts and maybe never will!

enable_if and type traits are a workaround for the time being.

Concepts lite will definitely be in the next revision.

Re:Half a decade with Go by losvedir on Tuesday November 11, 2014 @08:08AM (#8589588)
Would rust's "traits" count as structural typing? (I know Rust may not count as "relevant (used outside of academia)" yet, but maybe in the future.)
Re:Half a decade with Go by tel on Tuesday November 11, 2014 @08:51AM (#8589734)
Haskell's typeclass provide it.
Re:Half a decade with Go by dragonwriter on Tuesday November 11, 2014 @10:28AM (#8590242)
Typeclasses aren't structural typing, they are nominative typing, as typing is controlled by explicit declaration of relations between types and typeclasses, not inferred from structural properties.
Re:Half a decade with Go by tel on Tuesday November 11, 2014 @11:12AM (#8590533)
Sure they are: (forall a. X a => a) is a supertype of (forall a. (X a, Y a) => a).
Re:Half a decade with Go by dragonwriter on Tuesday November 11, 2014 @09:28PM (#8593676)
I stand corrected.
Re:Half a decade with Go by raverbashing on Tuesday November 11, 2014 @04:53AM (#8589102)
Like duck typing?
Re:Half a decade with Go by LBarret on Tuesday November 11, 2014 @05:40AM (#8589222)
I suspect this is like duck typing with some verification before compilation : the compiler checks that the object sent as parameter implements the correct interface.
Re:Half a decade with Go by diroussel on Tuesday November 11, 2014 @06:03AM (#8589273)
It's called structural typing.
Re:Half a decade with Go by kaoD on Tuesday November 11, 2014 @07:51AM (#8589537)
So, compile-time duck typing.
Re:Half a decade with Go by dllthomas on Tuesday November 11, 2014 @10:07AM (#8590117)
So, wikipedia says (http://en.wikipedia.org/wiki/Duck_typing#Structural_type_sys...):

"Duck typing is similar to but distinct from structural typing. Structural typing is a static typing system that determines type compatibility and equivalence by a type's structure, whereas duck typing is dynamic and determines type compatibility by only that part of a type's structure that is accessed during run time."

So it sounds like "duck typing" is defined in terms of run-time semantics. I guess you might be able to have genuine "compile-time duck typing" in a dependently typed language, which could be a good reason to preserve the distinction.

Otherwise, yes, they are certainly similar.

Re:Half a decade with Go by tel on Tuesday November 11, 2014 @08:52AM (#8589740)
In the same Formula 1 is performance go-karting.
Re:Half a decade with Go by coldtea on Tuesday November 11, 2014 @08:55AM (#8589749)
No, structural typing. It has a name already.
Re:Half a decade with Go by _pmf_ on Tuesday November 11, 2014 @03:01AM (#8588806)
> Now what makes this little function so darn useful is it takes anything fulfilling its interfaces (io.Writer and io.Reader).

I've implemented InputStreams from byzantine transport layers in Java that work with the standard library. I don't quite understand what is special about this concept in Go (maybe it's nice for people coming from typeless, messy dynamic languages or nice languages with horribly inflexible and ad-hoc standard libraries like Python and Ruby).

Re:Half a decade with Go by MetaCosm on Tuesday November 11, 2014 @03:55AM (#8588940)
Go has nothing unique (and maybe that makes it special). I mean that sincerely, everything it has, has been done dozens of times. Interfaces in Go are implicit (which is important, IMHO) and really, tremendously simple. These two features make them exceptional easy to use, and ACTUALLY used.

I have used interfaces (or equivalent concepts) in dozens of languages and they always felt like far more of a chore, explicitly using X interface or Y interface, ugly complex declarative specs, etc. Go just makes it painless.

Re:Half a decade with Go by LBarret on Tuesday November 11, 2014 @05:29AM (#8589190)
replace Go with Python in the text, and you won't see a difference: there are iterable, keyable, file-like interfaces, etc. And creating your own is trivial.
Re:Half a decade with Go by icebraining on Tuesday November 11, 2014 @06:29AM (#8589323)
Yes, but Python doesn't compile to a single binary, and usually runs much slower.

What people like about Go is its mix of features, not some specific one by itself.

Re:Half a decade with Go by pjmlp on Tuesday November 11, 2014 @06:57AM (#8589395)
Depends on the implementation.
Re:Half a decade with Go by cma on Tuesday November 11, 2014 @08:25AM (#8589649)
Python doesn't verify the interface is met until run time.
Re:Half a decade with Go by coldtea on Tuesday November 11, 2014 @08:56AM (#8589755)
With all the cases were Go pushes you to use interface{} that's the case in Go a lot of the time too.

If it had Generics that would be another thing.

Re:Half a decade with Go by ansible on Tuesday November 11, 2014 @10:18AM (#8590189)
With all the cases were Go pushes you to use interface{} that's the case in Go a lot of the time too.

However, you can wrap an interface{} using container (for example), with type-specific input and output functions, getting back compile-time type-checking. Yes, it is not optimal, and yes, you're still paying the price for type assertions.

If it had Generics that would be another thing.

I would like to see a good solution for this that integrates well with the rest of the language.

Re:Half a decade with Go by coldtea on Wednesday November 12, 2014 @03:20AM (#8594500)
I would like to see a ho-hum solution for this that's on par with what's offered on other languages.

I say that because the Go designers, despite having designed a quite mediocre language, suddenly when it comes to generics the want the perfect no-compromises solution or nothing.

Re:Half a decade with Go by jesstaa on Tuesday November 11, 2014 @04:03AM (#8588965)
You can make an io.Reader interface in any language. Interfaces don't really shine until you start composing them.

Say you have a type that implements the io.Reader, io.Writer, io.Closer and io.Seeker interfaces, eg. an os.File. This type would also automatically implement io.ReadCloser, io.WriteCloser, io.ReadWriter and io.ReadWriteCloser, io.ReadSeeker, io.ReadWriteSeeker, io.ReadWriteSeekerCloser, io.WriteSeeker, io.SeekCloser etc.

Re:Half a decade with Go by MetaCosm on Tuesday November 11, 2014 @02:27PM (#8591656)
Yeah, I simply think that this is hard to explain in a comment how useful and easy it is. But, I gave it my best Go...
Re:Half a decade with Go by stinos on Tuesday November 11, 2014 @02:44AM (#8588762)
Composition

I read your comment, but this seems more like A sane standard library with proper interfaces and not a language feature per se (also composition to me sounds like the pattern where you create objects which are composed of other objects but that's not what you mean, right)? What you display here can be done in pretty much any language suporting inheritance (or I'm missing something), so your point is those languages don't have io.Copy out of the box?

Re:Half a decade with Go by Svip on Tuesday November 11, 2014 @03:00AM (#8588800)
I think the point here is implicit inheritance. There are many interfaces in Go, but you don't need to specify which interface you are implementing. So you can easily implement io.Reader and io.Writer among many others, without extending your type declaration for lines on end.

This means that many standard types in Go implements either io.Reader and/or io.Writer. That's neat. The implicit interface implementation is definitely a language feature, and the libraries are making good use of it.

(That is not to say, you could not do the same in other languages, but you would have to specify the interface they implement rather than just adding a method with a specific layout.[0])

[0] I am not remembering the right term right now.

Re:Half a decade with Go by mike_hearn on Tuesday November 11, 2014 @06:50AM (#8589375)
I suspect you will come to hate this feature. Just because an class happens to have a method called close() does not mean it works the same way as another class that also has a close method. An interface is much deeper than the prototypes of its methods, and pretending you can pattern match an API to whatever names a code author happened to pick is likely to lead to pain eventually ...
Re:Half a decade with Go by latch on Tuesday November 11, 2014 @07:30AM (#8589487)
The very point of an interface is to decouple the caller from all the implementation specifically because it will work differently between implementation. If you expect two classes to implement it the same way, you an abstract base, not an interface.

Close is a particularly good example. One need only look at C#'s IDisposable to see that it does, in fact, work well. A mock might noop it, another class might close an FD, and yet another might make an RPC call.

I agree that interfaces tend to have fairly narrow family tree. And, by this narrowness, there's little ambiguity about what T GetById(id int) means. As the tree expands, which happens with implicit interfaces, ambiguity is more likely. Nevertheless, there's a fairly large common vocabulary that we'd all largely agree on. Closer, Reader, Writer, Logger, etc. Even in more complex ones, I see little risk of confusion, say, http.ResponseWriter. And, something that I've noticed from Go (which I never did in C# or Java), is the tendency to favor very small interfaces, which ends up being pretty awesome.

That aside, consider that implicit interfaces allow the consumer to define the interface. For example, you create a library that has a concrete struct called MyStruct with a method called DoStuff(). You define no interface because you don't need one.

I, a consumer of your library, need an interface because in some cases I'm using your MyStruct to DoStuff and in other cases, I'm using my own implementation. So I create an interface, define DoStuff(), and BAM!, your structure now implements my interface. I don't have to change your code.

Sure, the workaround is to wrap your structure in my own which implements the interface. But how, in this case, is the implicit interface not a huge win?

Maybe, as you say, it'll screw over people who use it poorly. For everyone else, I see no drawbacks.

Re:Half a decade with Go by dllthomas on Tuesday November 11, 2014 @10:11AM (#8590137)
It's not just "people who use it poorly". The point of an interface is to abstract over some details while guaranteeing others. If I am unaware of an interface, I don't know to avoid the names used in that interface, and I don't know to abide by the invariants assumed in that interface. That seems like it will bite people who've done nothing wrong. If I am providing a library, I can't possibly be aware of every interface anyone might define in code that uses it. I've no clue how frequently this will occur, in practice.

Haskell's typeclasses work around this by letting you define "how a type implements an interface" at either the definition of the interface or the definition of the type. (Or, strictly, anywhere else both are in scope - but that gets messy for a few reasons, so it's discouraged and GHC warns about "orphan instances" unless you tell it not to.)

Re:Half a decade with Go by ansible on Tuesday November 11, 2014 @12:20PM (#8590951)
If I am unaware of an interface, I don't know to avoid the names used in that interface, and I don't know to abide by the invariants assumed in that interface. That seems like it will bite people who've done nothing wrong. If I am providing a library, I can't possibly be aware of every interface anyone might define in code that uses it. I've no clue how frequently this will occur, in practice.

That's not a problem with Go's module system. If someone is using your library, and wants to use your interface in a particular package, that's fine. If they want to use another library, with another interface of the same name in another package, that's also fine.

If they want to use both libraries in the same client package, they'll have to locally rename one or both of the imports.

Re:Half a decade with Go by dllthomas on Tuesday November 11, 2014 @12:35PM (#8591046)
It's entirely possible that I just don't know enough about go's interfaces. Wasn't it explicitly stated up-thread that you don't need to name the interfaces you support? If that's the case, I don't see how you get around the possibility of a type seeming to support (because of what's defined for it) an interface that it doesn't (because those functions actually do other things - obviously or subtly).
Re:Half a decade with Go by AnimalMuppet on Tuesday November 11, 2014 @01:17PM (#8591261)
Here's a (very contrived) example of what I think you mean.

Here's a container interface. It has a sort() method, which sorts the elements of the container.

Here's a different container interface. It's got a method that tells you what kind of concrete container you have, so you can understand how expensive actions like insert and sort are going to be. But the author was from England, and so called that method "sort".

You can see how that's going to (fail to) work out when you define a "sortable" interface...

Re:Half a decade with Go by dllthomas on Tuesday November 11, 2014 @01:25PM (#8591312)
Right, thank you!

Traditional (but even more contrived) examples include "draw" and "fire" doing unexpected things when applied to a gun as opposed to an image or an employee.

Re:Half a decade with Go by latch on Tuesday November 11, 2014 @06:58PM (#8593118)
ok, ok. I think I'm understanding. Let me propose a middle ground.

First, you really have to split this up into two distinct cases.

The most powerful/useful is when you create an interface in your package for a structure in a different package. It's been years since I've done .NET or Java, but I remember frequently cursing a library developer (often someone at Microsoft or Sun) for exposing a concrete type instead of an interface. In this case, I don't see any downside. Creating a:

type Render interface { Draw() }

And then using my (or someone else's) Gun structure, is no different than using the Gun structure directly and expecting it to render itself to the screen rather than come out of its holster. The interface buys you the level of indirection, but whether you use the interface or the concrete type, it's up to you to know WTF Draw() does.

This first approach is well explained at [1]

In the second case, where a library expects an interface, I agree there's a risk:

// 3rd party package package fastRender

type Drawable interface { Draw() }

func Render(d Drawable) { ... }

// my code: fastRender.Render(new(Gun))

I've lost some degree or type checking. Since my Gun's Draw doesn't explicitly implement fastRender.Drawable, maybe I'm trying to fit a square peg into a round hole. There's nothing the compiler can do to help either.

It sounds a bit like an academic concern to me. Is this something that's actually bitten people in the ass? How is it different than any method that takes primitives? I can pass a []byte of a bitmap to a Music player's Play(data []byte) method...

[1] https://medium.com/@rakyll/interface-pollution-in-go-7d58bcc...

Re:Half a decade with Go by dllthomas on Tuesday November 11, 2014 @07:56PM (#8593368)
Note that I'm not arguing for Java. Haskell typeclasses covers both of these use cases (you can make a new type an instance of an existing typeclass, or existing types instances of a new typeclass, without touching any exsisting code) but requires someone to look at it and say "This actually implements the contract that interface assumes." They can be wrong about that, of course, but I think making it explicit helps.

There's also a subtle third case - I import two libraries. One of them defines Drawable, the other has something that looks like it implements Drawable. But it's just happened upon the same signature, and makes different assumptions. Maybe it even says it implements Drawable - but a different Drawable defined in a third library.

As I've said all along, I don't know how often these things are hit in practice. I think so far go development has been comparatively centralized, and so it might be seen less often than it would if it were used everywhere, but that might still be rare enough to not be a problem.

Re:Half a decade with Go by latch on Tuesday November 11, 2014 @11:02PM (#8593946)
thanks
Re:Half a decade with Go by ansible on Tuesday November 11, 2014 @01:33PM (#8591360)
OK, now I understand. It may be possible to muck things up if you've got two different types (from different packages) that have the exact same signatures for all the functions defined in the interfaces.

It doesn't seem like a high probability that this would happen on accident, though it might be possible to contrive an example.

I'll have to think about that.

Re:Half a decade with Go by dllthomas on Tuesday November 11, 2014 @03:05PM (#8591844)
Certainly the larger an interface is, the less likely that someone supports all of it by accident. Of course, that's both good and bad - if the accidental support would have been correct then we're missing out, but I think most of the time we shouldn't count on that.

One could possibly force the issue by including an unused function with a deliberately unique name (supports_interface_foo, or maybe a UUID or both) as part of the interface. Can functions added later fill parts of interfaces? If so, this approach would make the situation roughly that of Haskell typeclasses. If not, then this approach makes the situation roughly that of Java interfaces. In either case, it might be appropriate to some pickier interfaces.

Re:Half a decade with Go by AnimalMuppet on Tuesday November 11, 2014 @05:53PM (#8592810)
Thinking about it in the abstract, it seems to me that the probability goes up as interfaces get smaller/narrower (which apparently is a style that go encourages) and the codebase gets larger (which is go's target environment).
Re:Half a decade with Go by dllthomas on Tuesday November 11, 2014 @06:16PM (#8592956)
It goes down as method names contain more entropy, too.
Re:Half a decade with Go by AnimalMuppet on Tuesday November 11, 2014 @06:51PM (#8593093)
True. And yet... for a good method name in an interface, you want it to be as general as the interface could be. You want sort(), not sortVector(), because sorting is much more general than sorting a vector - you could sort a tree, if it can be ordered.

You could include the name of the interface as part of the method name, though. But the downside of that approach is, if another interface wants to re-use the same method, things get awkward...

Re:Half a decade with Go by Solarsail on Tuesday November 11, 2014 @04:10AM (#8588985)
Structural types, as opposed to nominal types?
Re:Half a decade with Go by Svip on Tuesday November 11, 2014 @05:14AM (#8589153)
Basically. But Go obviously also have nominal types.
Re:Half a decade with Go by MetaCosm on Tuesday November 11, 2014 @04:17AM (#8589007)
No, io.Copy was just the example that everyone would recognize in Go, and likely the first interface you will touch.

My point was implicit, exceptional simple interfaces are sorta magic. They are effortless, and because they are implicit, there is no harm in creating a 1 function interface (or 10 of them). Because your caller is never going to have to do an ... Implements ThingA, ThingB, ThingC, ThingD, ThingE, Thi... it implicitly supports an interface if it fulfills the signature.

So your interfaces end up being tiny (just what you need) and pervasive. This means the way your system ends up working tends to be far more aligned along interfaces than anything else.

When I speak of composition (in this case the composition of functions) I am speaking of the ability to use functions together rather freely and with little effort. This is a bit hard to explain, but it feels a bit like a modern shell, you can wire together lots of commands (functions), from lots of places that have no awareness of each other with the pipe | operator. In Go, simple, minimalistic interfaces act as the glue and let you compose lots of diverse functions together exceptionally quickly.

Re:Half a decade with Go by killertypo on Tuesday November 11, 2014 @01:15AM (#8588569)
I NEED to work Go into one of my projects, but dammit I love Python so much. it is a warm and safe and comfortable cocoon. :)
Re:Half a decade with Go by MetaCosm on Tuesday November 11, 2014 @04:27AM (#8589033)
Then you need to scale and your library isn't actually built in C... or only runs on 2.x (or 3.x) and the cocoon seals up and you can't escape... you scream but no one can hear you... you look for help, desperately clawing at cython, numpy, jython, pypy and C extensions -- they all require you to leave your cocoon far behind... you struggle and break free... suddenly you are exposed to the big wide world outside of your cocoon... you look back and realize the cocoon was just a cleverly disguised prison. /hackernewsstorytime
Re:Half a decade with Go by killertypo on Tuesday November 11, 2014 @11:47AM (#8590752)
hahah well I am very comfortable with C and other languages, but I love python for it's versatility and ease of use! It has some very expressive one liners that are surprisingly coherent for being one liners.
Re:Half a decade with Go by raverbashing on Tuesday November 11, 2014 @07:38AM (#8589500)
Just keep in mind Go IS NOT like python, but instead it's a better C

I'd say it's a better C, not a better C++ (or Java/C#)

Re:Half a decade with Go by lucozade on Tuesday November 11, 2014 @08:57AM (#8589758)
As a language maybe but for usage, not so much.

For me, most modern uses of C fall into 3 camps:

+ extreme portability

+ complete, low level resource control

+ foundational libraries

And Go doesn't really qualify for any of these. For the latter 2 largely because of the GC.

I think in practice, that its engineering bent i.e. no frills language and high quality tooling, will more likely see it being used in the server-side application/middleware space. I guess not surprisingly.

So it really is up against Java, Python, Ruby and C++ and is, therefore, interesting in that it isn't trying to compete on lingustic goodies.

Re:Half a decade with Go by raverbashing on Tuesday November 11, 2014 @01:53PM (#8591479)
"As a language maybe but for usage, not so much"

Yeah, I agree with your points. Which is a shame really.

Re:Half a decade with Go by lmm on Tuesday November 11, 2014 @02:52AM (#8588779)
I loved python and wouldn't've given any of it up. Then I switched to Scala and discovered how much I could get the computer to do for me, without giving up the conciseness, readability and expressiveness of Python.
Re:Half a decade with Go by cgag on Monday November 10, 2014 @06:17PM (#8587281)
I don't think you're going to come around on it. It's not suddenly going to stop being terrible at abstraction. That essay seems very accurate and applies to Golang.

The strengths of Go to me seem to be its extensive standard libary and the fact that you don't need to worry about writing elegant code because it's not really an option. That reduced decision making is actually really appealing to me on some level, but it's not enough for me to consider it over what I consider better tools (Haskell, Rust).

I'm currently porting a tiny program a friend wrote in Go to Haskell so we can compare notes, and I think the Haskell is both safer and more elegant, but I'm jealous of the fact that all the libraries he used are from the standard library while I have to evaluate libs of varying quality. However, I would rather put my time in to improving the Haskell ecosystem than using something convenient that makes a lot of decisions I disagree with.

edit: I also think there's value in being a conventional imperative language as someone mentioned below. I with there were something between Go and Haskell. Perhaps that'd essentially be Rust with immutable data structures and garbage collection.

Re:Half a decade with Go by nickik on Monday November 10, 2014 @06:33PM (#8587346)
I dont know much about go, but I always thought that the problem with 'the standard library does everything' is that it starts to feel heavy and better alternatives pop up. Then you have these dark places in the library that most people avoid, and you cant really throw away.

Clojure used to have something called, clojure contrib and it was kind of awsome, it did pretty much everything in just one jar. It was also a huge problem to mentain and everybody wanted to be in contrib, so you had the one json lib in contrib and fasters outside.

With clojure 1.3 it got split up into many diffrent parts and it still servs as somewhat of a community standard or recommended library. Overall its much better and much more usful, but sometimes I miss the days when everything was in one jar on on dependency.

Re:Half a decade with Go by cpeterso on Tuesday November 11, 2014 @12:45AM (#8588512)
Rust is avoiding the contrib problem by shipping a robust package manager from the beginning and pushing much of the Rust stdlib (and language features) into libraries.

http://crates.io/

Re:Half a decade with Go by cgag on Monday November 10, 2014 @06:58PM (#8587454)
I started using Clojure just after 1.3 came out so I could be wrong, but my impression was that while contrib was all in one place, it was still maintained by a bunch of random people who got their code into contrib, rather than being treated as a core part of the language the way (I believe) Golang's is.
Re:Half a decade with Go by nickik on Wednesday November 12, 2014 @09:19PM (#8599590)
Yes it was, like I said it is better now. However it was also kind of nice because everything was just there. Even with good mantainers, some of the same problems could keep existing.
Re:Half a decade with Go by coolsunglasses on Monday November 10, 2014 @07:18PM (#8587523)
That's right. contrib was always the red-headed stepchild to core.
Re:Half a decade with Go by ansible on Monday November 10, 2014 @06:09PM (#8587236)
So I'll ask: What is it I need to read/work through in order to at least "get" Go and really understand its strengths (whether or not I end up liking it)?

As discussed elsewhere on this page, Go is not the most feature-rich language out there.

But it does have features that seem to help my solve my problems with a minimum amount of fuss. Like using interfaces liberally, instead of having to define classes. Having lexical closures is also nice.

If you're not working on an application that can benefit from concurrency, you may not see all the benefits of Go either.

What kind of problems were you trying to solve, and how did Go see heavyweight compared to how you'd solve the problem in some other language?

Re:Half a decade with Go by wwweston on Monday November 10, 2014 @06:47PM (#8587408)
I like functions as first-class values and closures. If they weren't present, I might well have bailed months ago. :) And from various experiences doing OO with other languages, I can kindof buy that Go interfaces are often 80% of what you want.

Most of what I've been working on is a Rest API. Here's an example of a problem that felt like it should be something for which I'd be able to write an abstraction to deal with, but turned out to be challenging, at least as a n00b:

https://groups.google.com/forum/#!topic/golang-nuts/JhsiiGHQ...

(Incidentally, though I moved past my then really poor understanding of Go interfaces, I wasn't able to apply the respondent's answer or my new general knowledge to achieve the abstraction I was looking for, and settled for just grinding out the same code for the dozen entities/endpoints it applied to.)

Concurrency: I suspect there's a bit that's hidden in some libraries we're using, and we may yet need to write our own code for some API requests that get processed offline, but I haven't had to explicitly write code for it yet.

If you can think of a specific exercise that might serve to illustrate Go's outstanding concurrency strengths, I'd be interested to try it and compare efforts to another language or two.

Re:Half a decade with Go by ansible on Tuesday November 11, 2014 @03:50AM (#8588924)
(Incidentally, though I moved past my then really poor understanding of Go interfaces, I wasn't able to apply the respondent's answer or my new general knowledge to achieve the abstraction I was looking for, and settled for just grinding out the same code for the dozen entities/endpoints it applied to.)

I definitely can't deny that using interfaces instead of regular OO classes takes some getting used to.

Though I don't understand why you had to grind out duplicate code for all the entities / endpoints though. I hacked up things a bit to get it to run on the playground, but as Jesse McNelis wrote, just passing the pointer to foo worked for the code you wrote.

http://play.golang.org/p/jNpK5CRBfv

Re:Half a decade with Go by aangeles on Tuesday November 11, 2014 @04:02AM (#8588962)
Regarding the sample code is "bson_*" is a bson code convention? I notice Mixed Caps [1]is the idiomatic code for go? TIA

[1]http://golang.org/doc/effective_go.html#mixed-caps

Re:Half a decade with Go by ansible on Tuesday November 11, 2014 @04:15AM (#8589000)
That stuff is from the bson Mongo package. I didn't want to pull it into this example, so that it could run on the playground. I replaced dots with underscores in that case.
Re:Half a decade with Go by stanleydrew on Monday November 10, 2014 @08:42PM (#8587780)
It's a painful exercise (entirely due to Apple, not Go), but we implemented an Apple Push Notification Service provider in Go that relies on several of its concurrency primitives.

I think implementing a simple HTTP proxy might also be a really good exercise, though I haven't done it.

Re:Half a decade with Go by spotman on Monday November 10, 2014 @09:55PM (#8588046)
If you have spent six months, is that just occasionally tinkering and reading things online, or actually using it fairly regularly?

If you have developed software in go, and after a couple months you aren't finding its saving you time, or at least pleasant to work with, maybe its not for you.

I feel like it is similar to C, but more opinionated, with much less rope to hang yourself, and often things I would have used C or Java, I find doing them in golang saves me plethoras of time.

It is opinionated, but for me the aha moment was after I learned enough of the standard libraries to feel comfortable in the language, I find myself getting things done at lightning speed, and it has performance that is as solid as the jvm in your average use case.

I find the code is also pleasant to read, and the language lends itself to writing verbose, simple code, which I find easier to debug than overly abstracted systems.

Re:Half a decade with Go by curun1r on Monday November 10, 2014 @11:18PM (#8588271)
> I find the code is also pleasant to read

This, to me, is what he's missing. On the continuum between readable and expressive, Go falls decidedly on the readable side. If you're working on a project by yourself for 6 months, you might not like Go. But if you work on a team or return to code you wrote 6 months ago and haven't touched since, that's when you'll appreciate Go.

Evaluating languages based on simple solo projects will always favor the more expressive languages, but it's a short-sighted evaluation.

Re:Half a decade with Go by Elrac on Tuesday November 11, 2014 @03:20AM (#8588852)
Maybe unlike other respondents, I'm a Go amateur. I've written three projects in Go, one of a few thousand lines and two of a few hundred. Also unlike many others, I consider Go un-elegant to the point of being ugly. In other words, I'm no expert and no fanboy.

What makes Go my go-to language for certain kinds of projects (I'll doubtless be using it again) is that it gets shit done. It has the brutal simplicity and hardware proximity (and raw speed) of C combined with the small handful of things that most significantly contribute to make Java better than C: A simple type system, garbage collection, usable string handling and dynamic data structures (arrays and hash maps). Go also has a fairly large, useful library.

Multiple return values often including errors make error/exception handling very explicit and in-your-face. When something can go wrong, you the programmer are forced to recognize that and deal with it as soon as the function returns. That's a Good Thing IMO. Java-style exception handling, by comparison, looks to me like an elaborate language hack for passing the buck.

There's a ruthless kind of efficiency in Go's surrounding philosophy. There's one way to format Go code, you let the utility take care of it and never worry about formating again. The compiler won't tolerate various kinds of sloppiness, such as unused imports.

As somebody else mentioned, in Go, writing elegant code is not a consideration because it's nearly impossible. Well, I'm sure there are "better" and "worse" ways to write Go code, but not so obviously that I'd be tempted to give it a lot of thought. So I tend to just sit there and write code by the bucketful until I'm done.

Finally, the tooling gets the job done, and quickly. I can compile for and across various hardware environments and ship executables that don't rely on a JVM or other external dependencies.

Re:Half a decade with Go by meowface on Monday November 10, 2014 @07:52PM (#8587630)
Going by Paul Graham's "Blub" essay (http://www.paulgraham.com/avg.html), I'd say the problem is that languages like Go and Java are simply not high in the rankings when it comes to power.
Re:Half a decade with Go by enneff on Monday November 10, 2014 @09:36PM (#8587980)
The underlying assumption is that the problem that modern programming languages should solve is lack of power. But I don't see that problem in modern codebases. In my experience, the problem is complexity.
Re:Half a decade with Go by reverius42 on Monday November 10, 2014 @09:56PM (#8588048)
I think in this case more power might be a good proxy for less complexity: power should correlate positively with expressiveness, and expressiveness should correlate negatively with complexity. More expressiveness lets you build more powerful abstractions with less code.
Re:Half a decade with Go by enneff on Tuesday November 11, 2014 @12:08AM (#8588410)
> expressiveness should correlate negatively with complexity

I don't see why that would be true. In my experience, the most expressive languages often produce the most impenetrable spaghetti code. Can you explain your reasoning?

Re:Half a decade with Go by lmm on Tuesday November 11, 2014 @03:00AM (#8588801)
Consider e.g. traverse, which is a function you simply can't write in a language without higher-kinded types. Several times I've written half a page of code only to realize "that's just traverse" or "that's just foldMap" or so on. In a less expressive language I would've had to leave that half-page as is. Surely that means the expressiveness results in more readable, less complex code?
Re:Half a decade with Go by enneff on Tuesday November 11, 2014 @08:57AM (#8589759)
Sounds more like boilerplate or redundancy to me than complexity. Things I would call "complex" in a software system are god objects, APIs with too many options, invisible interactions between parts that appear unrelated, and so on.
Re:Half a decade with Go by lmm on Tuesday November 11, 2014 @06:18PM (#8592964)
Fair enough. In that case I'd say expressive languages help, but only indirectly, because they make it possible to keep track of effects and interactions without having to write reams of code.

In a language with lenses, you can delimit where your models are mutated. In a language that lets you treat composable effects in a generic way, you can e.g. split up your variables explicitly with ReaderWriterState, making it clearer which serves which purpose.

The kind of things you might be tempted to use "magic" or global variables for in a lesser language - the "cross-cutting concerns" - you can instead handle in normal code as a generic kind of context. E.g. an audit trail can just be Writer. Or actions that need access to a database session can just be another kind of context. I'm working on such a thing right now (see tpolecat's doobie for a public example of the same kind of thing) - whether a function accesses the database or not is visible right in its type, but it's easy to compose functions that do. The types ripple up, and in the end I'm probably going to do session-creation-in-view - but in a principled way, using the ordinary type system, visible in the code - with Spray, my web route definitions are just another ordinary bit of Scala code (whereas in most languages I would define routes in an external config file, or at best a config object a la Django - adding complexity).

Heck, error handling is a perfectly good example of this. In a less expressive language, the only way around the boilerplate of handling errors where they occur is unchecked exceptions (or effectively-unchecked exceptions, as in "throws Exception"). In a language with good generic context support, the possibility of failure is just another kind of context that we compose with the same generic tools as any other, and the control flow becomes something sensible again.

Re:Half a decade with Go by f2f on Monday November 10, 2014 @11:21PM (#8588274)
your "should" and "should" should be replaced with "doesn't" and "doesn't" or at best "may" and "may".

more code has been written in Go than Haskell, Rust and Ocaml combined.

Re:Half a decade with Go by sheepmullet on Monday November 10, 2014 @11:51PM (#8588357)
More code will be written in COBOL this year alone than has ever been written in Go.
[dead]
Re:Half a decade with Go by coldtea on Tuesday November 11, 2014 @04:14AM (#8588998)
No, he's pretty right. Do you know what COBOL codebases are out there and what they power?
Re:Half a decade with Go by sheepmullet on Tuesday November 11, 2014 @03:03AM (#8588811)
How many lines of Go do you think will be written this year?

50 million? 100 million?

Re:Half a decade with Go by meowface on Monday November 10, 2014 @11:27PM (#8588294)
So what? More code has been written in C and Java than Go and Rust and Ocaml and whatever-else combined. A language's popularity says little about its complexity or how good of a language it is.

Powerful languages let you grapple with problems, weak languages first make you grapple with the language before tackling problems. Some people feel like Go gets in the way. I have not written any Go, but I understand both the praise and the criticism.

Powerful languages can cause other issues, but they do enable certain things that weaker languages simply never can.

Re:Half a decade with Go by melling on Tuesday November 11, 2014 @12:25AM (#8588463)
You're being a little vague. Can you give a couple examples where software projects were done in "powerful languages?" I can certainly appreciate that higher level languages are better. However, it seems like in practice they are not used as often as you would hope.
Re:Half a decade with Go by f2f on Tuesday November 11, 2014 @12:02AM (#8588395)
C and Java are not the subject here.
Re:Half a decade with Go by codygman on Monday November 10, 2014 @11:46PM (#8588345)
Do you have a source? I don't find your claim implausible, however I would like to know how you came to that conclusion.
Re:Half a decade with Go by f2f on Tuesday November 11, 2014 @12:02AM (#8588397)
the internet is my source.
Re:Half a decade with Go by melling on Tuesday November 11, 2014 @12:19AM (#8588445)
The Internet, in general, can be very unreliable.
Re:Half a decade with Go by jamon51 on Tuesday November 11, 2014 @02:21AM (#8588713)
How do I know this statement is reliable?
Re:Half a decade with Go by dons on Tuesday November 11, 2014 @08:57AM (#8589760)
> more code has been written in Go than Haskell, Rust and Ocaml combined.

[Citation needed]

Re:Half a decade with Go by pjmlp on Tuesday November 11, 2014 @03:46AM (#8588915)
> In my experience, the problem is complexity.

Simple languages led to complex code bases.

Many of the Enterprise Java sins were caused by the language limitations and developers trying to work around them.

Re:Half a decade with Go by enneff on Tuesday November 11, 2014 @08:56AM (#8589751)
I think the enterprise Java sins were caused by cargo cult programming. Java can actually be pretty nice when wielded by someone who isn't afraid to invent new things.
Re:Half a decade with Go by pjmlp on Tuesday November 11, 2014 @03:15PM (#8591888)
What leads you to believe the same won't happen to Go?

I have seen this happen in C codebases before Java took the enterprise.

Its own little macro based DSL and pointers that were actually handles for the real data.

Re:Half a decade with Go by enneff on Tuesday November 11, 2014 @03:37PM (#8592002)
Java's sin is a fetish for over abstraction. Go has a strong cultural emphasis on avoiding unnecessary abstraction.
Re:Half a decade with Go by pjmlp on Tuesday November 11, 2014 @06:02PM (#8592867)
Enterprise architecture is traversal to the languages being used.
Re:Half a decade with Go by oblio on Tuesday November 11, 2014 @07:22AM (#8589458)
True, but in a lot of enterprise situations the complexity is intractable - it is caused by business requirements.
Re:Half a decade with Go by pjmlp on Tuesday November 11, 2014 @08:24AM (#8589648)
Exactly because of that I rather use languages that provide the tools to work with complexity, instead of shunning it into the shoulders of developers.

Anyway Go has its use cases, and it is already an improvement if less C code gets written.

Re:Half a decade with Go by AnimalMuppet on Tuesday November 11, 2014 @02:42PM (#8591731)
The problem with the Blub essay is precisely the assumption that all languages can be ranked on a one-dimensional axis called "power". That assumption is false. (I know this is heresy to say on HN, but in this essay, PG is simply wrong.)

I'm repeating myself here, but: A Haskell user and a Lisp user are both sure that they're at the top of the power curve, and they're both sure that they're looking down when they're looking at the other language, and they can both tell you precisely why they're sure they're looking down ("It doesn't even have a decent type system" and "It doesn't even have macros", respectively). But they can't both be looking down. What's wrong here?

What's wrong is the assumption that all languages can be ranked by a one-dimensional attribute called "power".

Or look at it another way: Power? Power for what? Well, for writing programs. But what kind of programs? General programs? I've never written a general program in my life; I've only written specific ones. Then "power" is whatever's going to make it easier to write the program I need to write. Whatever language does that is the "most powerful" language for the problem I'm facing.

What power is Go shooting for? It's the power to write a ten-million-line application and have it be maintainable for two or three decades. (That's not my guess; it's what Rob Pike said the language goals are.) If you face that kind of problem, Go may in fact be a very powerful language.

Re:Half a decade with Go by melvinmt on Monday November 10, 2014 @07:06PM (#8587479)
> So I'll ask: What is it I need to read/work through in order to at least "get" Go and really understand its strengths (whether or not I end up liking it)?

I highly recommend to read this article where Rob lays out the motivation behind many aspects of Go: http://talks.golang.org/2012/splash.article

Re:Half a decade with Go by claystu on Monday November 10, 2014 @06:01PM (#8587202)
What weaknesses of Pascal are being repeated in Go?
Re:Half a decade with Go by lmm on Tuesday November 11, 2014 @02:54AM (#8588786)
There is no escape. The language thinks it knows better than you. The standard library is allowed to do things that your code isn't.
Re:Half a decade with Go by _ak on Tuesday November 11, 2014 @06:06AM (#8589276)
Like what? The standard library is no more special, other than where it resides in the filesystem. You can write C and assembly code as well and link it to your Go code. And I'm not talking about cgo, I mean [568][ac], the Plan 9 C compiler and assembler that come with Go.
Re:Half a decade with Go by pjmlp on Tuesday November 11, 2014 @07:02AM (#8589404)
> Like what?

Maps, slices, the pre-defined functions.

More powerful languages make no big distinction between user defined types and the language provided ones.

Re:Half a decade with Go by lmm on Tuesday November 11, 2014 @07:00AM (#8589401)
I was thinking most obviously of generics. The go standard library is full of generic collections, but you're not allowed to use generics in your own code.
Re:Half a decade with Go by claystu on Wednesday November 12, 2014 @12:01AM (#8594099)
It looks like free pascal has generics: http://www.freepascal.org/docs-html/ref/refch8.html#refse46....

But to your larger point, doesn't any non-programmable programming language exhibit the same weakness to some extent?

Re:Half a decade with Go by lmm on Wednesday November 12, 2014 @05:55AM (#8594838)
Any language will have some "magic" things that are special-cased in the compiler - things like the basic integer datatypes, or the threading primitives - and probably a few more things that are implemented as C code (though if you're lucky this can be done in a "standard" way, through the language's FFI). But most of the standard library should be implemented in the language itself (look at e.g. the Java standard library, or the Python standard library. In a more coherent language like TCL, even language constructs may be written this way - e.g. "for" or "if" can be just ordinary methods. At the other extreme, PHP has the infamous T_PAAMAYIM_NEKUDOTAYIM, because a simple-seeming piece of syntax had to be special-cased in the parser). If the standard library authors kept feeling the need to step outside the language itself, that's a bad sign - it suggests the language is poorly suited to writing libraries in. But you're right that it's a question of degree rather than a binary thing.
Re:Half a decade with Go by _ak on Tuesday November 11, 2014 @07:52AM (#8589541)
That's not the standard library, though.
Re:Half a decade with Go by howeman on Tuesday November 11, 2014 @12:54PM (#8591155)
Actually, the c compiler just got deleted.

https://groups.google.com/forum/#!topic/golang-codereviews/A...

Re:Half a decade with Go by jfb on Monday November 10, 2014 @10:53PM (#8588209)
It may just not fit for you. I feel the same way about C++ -- I understand the strengths of a pay-for-what-you-use language with a ridiculously powerful template library, but it just never came naturally to hand for me.
Re:Half a decade with Go by cft on Monday November 10, 2014 @06:13PM (#8587251)
Go is the only language that allows one to write very scalable TCP servers fast (i mean development effot). The servers are almost as fast as C (i.e. 15x Python), but the development time is like Python.
Re:Half a decade with Go by threeseed on Monday November 10, 2014 @07:54PM (#8587637)
There are numerous options for writing very scalable TCP servers on the JVM e.g. Vertx.

Then you have the option of using Java, Clojure, Scala, Ruby, Python, Javascript or Groovy languages.

Re:Half a decade with Go by est on Monday November 10, 2014 @07:38PM (#8587597)
For the record, Go does not allow you to operate on fd, so some fine tuning TCP parameters does not happen unless you do reflection magic and use SysCall. Which is PITA compared to Python.
Re:Half a decade with Go by tlmr on Monday November 10, 2014 @06:31PM (#8587337)
What about Julia?
Re:Half a decade with Go by FraaJad on Monday November 10, 2014 @07:03PM (#8587470)
Yeah, what about Julia?

which makes as much as sense as asking

- What about R? - What about GNU DAP? - What about FORTRAN?

for writing a TCP server.

Re:Half a decade with Go by pasxizeis on Thursday November 13, 2014 @11:01AM (#8602202)
Tooling, simplicity (eg. lack of features), composition, channels.
Re:Half a decade with Go by coldtea on Tuesday November 11, 2014 @04:08AM (#8588978)
>People who seem to be smart nevertheless keep talking it up... some not even as just a good tool but as their favorite language.

Being good enough, not knowing any better PL-wise, and the Stockhold Syndrome explains that.