Go and Assembly
doxsey.net
doxsey.net
I have been holding back because I don't like the lack of exceptions. But it occurred to me that C doesn't have anything like exceptions either, and even though that lack causes some serious irritation, the C language as a total package overcomes it and is really powerful.
I don't know if any language can beat that list of tool chain benefits. Maybe I will give go a whirl.
Yes, there's some of this:
if f, err := io.Open("foo.txt"); err != nil {
return err
} else { // use f
}However, that's not really any more code than
try:
f = open("foo")
// use f
except IOError as e: return e // or throw, or whatever
Plus Go uses multiple returns everywhere, so you don't have to worry about errors being confused with actual data returned.It's pretty awesome.
This means you can't continue to execute the function, but you do get a chance of handling the exception / turning it into a regular return value.
tl;dr: Go has exceptions, they are just a little different (IMO for the better).
In the Go standard library source code, "panic" has pretty much the role 'assert(!"error message")' has in C.
The reality is that Go does not have exceptions the way Python does. If you're writing idiomatic Go, you're manually checking errors.
Exactly (and probably for a reason)
> In the Go standard library source code, "panic" has pretty much the role 'assert(!"error message")' has in C.
Well, there's no real way to recover after such an assert (the C stdlib is undefined when you catch the SIGABRT, the stack is not guaranteed to be big enough to do anything, most I/O is not guaranteed to work, etc. -- really, very few uses for catching a SIGABRT). There is a way in Go, even if it is far less capable than your average "except .." clause in C++.
> The reality is that Go does not have exceptions the way Python does.
True. Some of us (e.g. me) think that's a big advantage. (I'm not implying you disagree - I don't know what your opinion is)
I just find that so much more pleasant.
Even though I'm using GoSublime I haven't really dug into its plethora of feature, it might just have a repl in there...
Yep, rolled my own here: http://github.com/metaleap/go-buildrun -- I use it with GoSublime on Ctrl+B (which I strongly suspect must have some repl-like feature anyway by now, but not sure) -- but works in any editor that lets you hook a key binding to an executable and pass it the current .go file's path.
int *_memset32(int *p, int value, size_t count) {
asm {
mov EDI,p ;
mov EAX,value ;
mov ECX,count ;
mov EDX,EDI ;
rep ;
stosd ;
mov EAX,EDX ;
}
}
The compiler adds the function prolog/epilog for you, as well as any save/restore for used registers.Go doesn't have anything like that yet but I wouldn't be surprised if an experimental implementation is done by one of the alternate compilers being worked on.
http://golang.org/src/pkg/math/remainder_arm.s
That is, very short code that just looks like a function call to me, the complete asm noob. What is it, are all these maths functions implemented in hardware by amd64 and arm architectures? Or is this "asm code" just reverting to calling the Go implementation of the particular function (aka the not really that "optimized")?
http://golang.org/src/pkg/math/remainder_386.s
The other two call the go version:
- The fprem1 instruction is actually a long microcode sequence and is quite slow; 26-50 cycles on SNB according to Agner Fog. Several iterations of that loop are necessary for a complete reduction of some operands.
- There is no analogous instruction on arm (or really, any platform that isn't x86), anyway.
- If you're using the floating-point remainder operation in a performance-sensitive context, You're Doing It Wrong. Programmers have gotten so used to this that there is little value in optimizing remainder; it is rarely used in situations where the optimization would matter.
Very little of the Go standard library is written in anything but Go.
The name is a problem. And if the name is not a problem, then the community is a problem.
Every time a Go article comes up, the "name searchability" discussion comes up. Go's been around for some 4-5 years now, can we all come to terms with its name?
Somehow whenever brainfuck-lang threads show up, this issue is never raised, but surely might exist just the same? What about Perl (a common word), or Basic (even more basic), heck "C" (a freakin' letter). Is that so much better for searchability? Rust -- a common word. D -- a freakin' letter. Miranda -- a language but also the name of 100s of townships, an IM client etc etc.
Go is not the first language to have this "problem", and in fair daily practice it never ever is a problem. Because you never search for Go, you search for "Go channels" or "Go image processing" or "Go GTK binding" or "Go compiler error X" etc. etc. Like you would for all these other fine examples of oddly named languages. And somehow, Google is semantically smart enough to present a few decent matches among the first 10, even with all your personalization & tracking cookies etc. etc. disabled.
So... problem? Herin lies the problem with Go? Seriously... it's just not a big freaking deal getting in the way of getting stuff done. Promised.
I think it is too bad that in the days of Google and the web there is no easy way to keep track of all new references to an uncommon term like that.
OK scratch the Perl example. Still standing by my point: it's a "problem" shared by many languages and it's not a problem in the first place.
"Basic" is around #9,500.
"Rust" is ~#10,950
"Java" doesn't appear at all (List goes out to 40,000) (Admittedly, somewhat biased by the dated-ness of the material, but it's still not a common one.)
Go is #106, and modern lists based on contemporary sources place it in the top 50 most used English words.
(1MB) word count list: http://norvig.com/google-books-common-words.txt
Go: 187, Basic: 759, Java: 7136, Rust: 13110
With relative frequencies 320M:103M:8.9M:3.6M ~ 100:30:3:1
http://books.google.com/ngrams/graph?content=java%2Cperl%2Cm...
I'll assume you've never knitted.
All names which the programming language is one of the last things a search engine would normally associate, but by sheer number of hits you end up finding stuff. When they were invented these names weren't good either.
The discussion about Go's name is indeed useless.
If I hear about this cool new language called Ruby and search for "Ruby Sieve of Eratosthenes," it is highly unlikely there's an article about implementing the Sieve of Eratosthenes in another language that just happens to contain the word "ruby." Conversely, the word "go" is depressingly likely to appear in articles relevant to your other search terms but unrelated to Go.
This has become less of a problem as Go has gained popularity, but in my experience it was a bigger problem for Go than it is for most languages. I search for a lot of obscure language crap out of curiosity, and I have never found an obscure language that is as hard to Google for as Go was a year ago. I know the articles existed, because I eventually found them, but dang was it hard to coax the info out of search engines.
Exactly the same applied for Go. The first four were Go-specific, and the remainder were a mix of Go-specific and pages about the Sieve with "go" somewhere on the page.
Also, as others have said, one immediately comes across references to golang everywhere.
How many search engines do you use? And which of them ignore or error on 2-letter words?
I just tried this on the only four search engines I can even think of that seemed like they MIGHT matter: google, bing, ddg, and stackoverflow's site-specific. All four obviously respected the two-letter word "go" (although for my searches only Google and SO returned results I found useful).
Second of all, I can't understand the situation where this would come up. Obviously in normal circumstances it doesn't even come up.
* You wanna search all forums at once? Use Google (or DDG, or the shitty one).
* There's a Go-specific forum? So obviously you don't need to specify Go in the search.
* The forum isn't about Go? Then why are you searching there?
So for your complaint to make sense, you need to have a particular forum you want to limit your searches to, AND you don't want to use Google with site:stupidforum.com, AND the forum covers multiple programming languages, AND the forum doesn't have a tagging system to tag go-lang posts (like basically every programming forum does), AND it has this problem I've never heard of where it rejects 2-letter words?
I'm really trying to avoid just saying "bullshit", but I think you're bullshitting us. Name one such forum.
Again, as I asked in the grandparent comment, name one search engine where you, or anyone you know personally, has had this problem.
What exactly are you searching for? Perhaps I can help you... http://lmgtfy.com/?q=site%3Anews.ycombinator.com+go
Did you even try?
(For those that have experience using Google, the search results are: http://goo.gl/fqNiC )
Well, either "site:news.ycombinator.com go" or " "site:news.ycombinator.com golang" work very well for me, getting tons of results. What exactly was the problem again?
If you don't find as many articles on Go as you would like it's because there just aren't that many. It's a relatively new language, without much of a user base yet. Heck, it only has 3-4 books out on it.
Also, it is pretty easy to find this story by searching for 'go' in the HN search box. You can further reduce results by selecting 'Stories' and search by date.
So in practice it is not a big deal.
I do wish they had chosen a different name, but I realise it matters less and less.
Well, considering how hard I try not to be tracked by Google, probably it does for someone else.
I just came up the idea: why didn't they name the language "Goo", and leave "Gle" to the debugger? It would be more common for people to refer to the language itself than to its debugger.
[1] http://golang.org/doc/faq#What_is_the_origin_of_the_name
Then again... http://en.wikipedia.org/wiki/Goo_%28programming_language%29 , although the homepage http://people.csail.mit.edu/jrb/goo/ suggests that that sort of thinking is not really in Goo's pedigree... even for 2003 that's not a pretty page.
Also, if you're suggesting "gle" as a debugger name, you're missing the joke. "ogle" is a verb meaning, approximately, "to look at", so it's a good name for a debugger. "gle" is not.
(Except that "ogle" is not actually a good name for a corporate-sponsored debugger, because "ogle" has sexual connotations. Which is why you should assume that this is a joke.)
Silly.
1. C was already pretty much the programming language by the time the Web took off, so it had an inherent advantage in Googlability due to its popularity.
2. The letter C does not tend to be used by itself as often or as widely as the word "go," so even if C hadn't already had an unfair advantage, it would have less of a problem just on this basis. The odds that an arbitrary programming article unrelated to C will have "C" scattered about are not all that great. The odds that an arbitrary programming article unrelated to Go will use the word "go" are actually pretty decent. Put another way, "Go" is a more common word than "C," so it generates more noise.
I don't find this issue to be all that problematic anymore since the search engines seem to have learned that "go" in conjunction with programming terms indicates an interest in Go-centric material, but I did find it vexing when Go was younger and I was first trying to learn it.
Also, doesn't doing this limit your code to using gc toolchain (since the generic Go function has to get called from the arch-specific asm code which uses that Plan 9 dialect)? Does this mean that the Go standard library can't be compiled with gccgo for example?
Wikipedia says the last "stable" release of Plan 9 was in 2002, but there seem to be a number of recent forks.
I do wish Go supported an explicit inline modifier that worked like haxe's though (unlike the C/C++ one which is more of a suggestion).
MOVL BX,autotmp_0000+-4(SP) ; from the article -- terrible!
MOV EBX,[ESP+autotmp_0000-4] ; Intel -- comprehensible!
This assembler has an imaginary register called FP.WTF is up with the center dot?
A programming language should not require Unicode to write -- especially assembly language!
I don't know what's worse: That this assembler exists, or that a project chose to use it after better alternatives had been created!
MOV x,y translates to the assignment operator "x = y" in a high level language [1].
Your program only has access to one giant array called "memory" [2] [3]. So MOV EAX,EBX means "EAX = EBX" in high-level terms; MOV EAX,[EBX] means "EAX = memory[EBX]" in high-level terms ("memory[EBX]" has the same meaning here as in C-family languages like C, Java, Javascript and Python). This choice of operator notation is intuitive, because it's very similar with the use of brackets in other popular languages.
The insane syntax uses parentheses instead of brackets. Which is confusing, since it's not related to the standard meaning of parentheses, grouping for order of operations or function call. So you would say "MOV EAX,(EBX)" in weird-syntax land.
But the insanity doesn't end there.
In the sane Intel syntax, if you want to load the value at memory location 148 + -4 + ESP into EBX, you can probably figure out how you would say it:
MOV EBX,[148 + -4 + ESP]
The C/Java/JavaScript/Python translation is: EBX = memory[148 + -4 + ESP]
In weird-land, the syntax for this operation is: MOVL BX,148 + -4 (SP)
To me, it looks like this instruction says: Let t = 148
Let u = The contents of memory pointed to by SP
Let v = -4*u
Let BX = t+v
Clearly, there are only two possible explanations for this: The person who came up with this syntax was drunk at the time, or the person who came up with this syntax was high at the time.[1] In a HLL, "x = y" allows arbitrarily long expressions for x and y, but in assembly language only a few different forms of x and y are allowed. In a high-level language, in the expression "x = y", x needs to be an lvalue, while y can be a more general rvalue. "a = 5+6" is legal; "5+6 = a" is not. Both the left- and right-hand side can be arbitrarily long and complicated, for example the LHS could be "a.b.c.d.e.f.g.h" and the RHS could be "m+n+o+p+q+r+s+t", assuming the appropriate variables exist and have the appropriate types.
[2] Unless you use multiple segments. But you generally don't do that.
[3] Or paging. But you usually let the OS take care of that.
http://golang.org/ref/spec#Source_code_representation
Historical reason, TL;DR edition: Plan 9 based compilers, because Ken Thompson.
EDIT: see also mseepgood's response: http://news.ycombinator.com/item?id=5185334
1. It does have its own package manager but good luck actually finding packages. golang.org's list is out of date and so is every other resource.
This is a serious problem IMO.
2. The third party web libs are pretty poor. I'm a big fan of Express for Node and prefer just a little bit of goodies ontop of something minimal.
A lot of people like Sinatra/Flask so I'm not the only one who likes this. There's nothing like this in Go.
We have the bits and pieces to make it but no one has stepped up. Right now developing anything for the web with Go is just too annoying, you have to create so many things that literally every other language has had solved for years.
If both of these problems were solved I would insta switch to Go for everything and never look back. It's just so pleasant to program in for all the points you mentioned + more.
Because Go uses URLs for package names its easy to build tools like godoc.org that automatically aggregate packages from the web.
How can I know which one to pick at a glance? Asking me to evaluate and profile 30 different libs for just a single task is unreasonable.
Also this page isn't even on Google's first page for when you search for something. I didn't even know it existed until you mentioned it.
godoc.org is an interesting service because its package list is produced as a by-product of people using it to read package documentation.
When you publish an npm module it gets put on their site automatically, then there's a lot of javascript scraping sites that watch npm's site. Before you know it your module has a decent amount of coverage which in return makes it much easier to find as someone who is searching for modules.
I also never had a problem finding a good lib in Node because there's a few stand out Node devs who are insanely productive and produce extremely high quality libs on a regular basis.
With Go it feels like there's 3 or 4 lib searching sites but all of them are really flawed. Then on top of that Go code is hosted on a bunch of different sites.
Top Google results are also not very good. In that Redis search example I searched for "golang redis lib" and the highest rank result was for some lib with almost no traction and had a questionable API.
I like the idea of the reviews and ratings though. Normally I would put almost no value in a rating system but we need to somehow separate the good from the bad without having to dive in and look at and profile code from 20 diff libs on a daily basis.
Usually I just check the commit activity on github if I want to see which Go libraries are actively developed.
Chromium Version 22.0.1229.94 Debian 7.0 (161065) works fine.
Otherwise, Go & Haskell are very different languages. In the grand CLispScript landscape, Go is sort of close to Haskell because of the interface/typeclass similarity, but pushed apart by the fact that Go's strong type system has some serious weak points in it by Haskell standards, for instance, there's no equivalent to a TChan a -> TChan a function as there is no way to have a function that is ignorant of "a" but can pass it through as the same type. Go forces it to collapse to interface{}, which is roughly equivalent to Data.Dynamic in Haskell. (If you want to search for it, Go calls it's equivalent to Data.Dynamic.fromDyn a "type assertion". There's two ways to use it, one that is the rough equivalent of fromDyn in that it returns whether the conversion worked and maybe the converted value, and one mode in which it does the Data.Maybe.fromJust for you, complete with violent crashing behavior if you're wrong.)
There's the haddock auto-generated documentation from cabal (if you enable it). Not sure if that qualifies for "available from the command line".
No chance. Using the `go` tool to install packages is at least an order of magnitude less annoying than using `cabal`.
Cabal works much better now, and most of the problems were due to over-conservative version ranges combined with an over-eager reinstallation policy that overwrote packages in a breaking way. That was fixed about 6 months ago, IIRC.
And I'm not really referring to its weird behavior. To use cabal, you have to write a cabal file to specify dependencies, build instructions, etc. With the `go` tool, no such meta data is required. Everything that is needed to build a package is inferred from the source by the `go` tool. This is what makes it less annoying than most other distribution tools.
Of course, most other distribution tools support a larger number of options, so perhaps its not a fair comparison. But that is irrelevant to typical workflow annoyances.
> Of course, most other distribution tools support a larger number of options, so perhaps its not a fair comparison. But that is irrelevant to typical workflow annoyances.
If you need to stick to a particular version of a software package, the common workflow involves using existing tools. (i.e., fork.)
Compiler speed is not some minor difference, it is absolutely massive. Build times of 30 seconds vs 2 seconds, and that is without counting the 10 seconds of cabal resolving dependencies.
>Go comes with a complete set of documentation available from the command line
GHC does not come with command line docs.
>All Go code is statically compiled so deployment is trivial
GHC links in C libs dynamically, and as far as I can figure there is no way to get static linking working, so I have to have all the same C libs installed on my production servers as my build server. With go you can just upload your binary to a bare bones server and it works.
>but it also has a tool to clean up code: gofmt
GHC has nothing like this.
>And there's also go fix which can automatically convert Go code designed for earlier versions to newer versions
Or this.
Haskell is a great language, but it does not match go's toolchain.
I simply did not play with Go to know the compilation speeds. I believe you that it is a massive difference, and it is indeed a major Go advantage.
> GHC does not come with command line docs.
The haddocks are available from the command line. So I don't know what this means. Hoogle is available from the command line.
> GHC links in C libs dynamically
Ah, I see. Did you try -optl-static? I haven't, but it might work.
> GHC has nothing like this.
There are tools to format Haskell code by certain conventions on hackage.
Hoogle is roughly the equivalent. It doesn't come with ghc though, and the rather lengthy dependency list has caused problems getting it installed before. Is there a command line only version that doesn't need all the web stuff?
>Did you try -optl-static?
Yeah, no such luck. It turns out go can't do this either though, so that one shouldn't have been on the list in the first place.
>There are tools to format Haskell code by certain conventions on hackage.
The "being included with the compiler" aspect is pretty big here. People are much more likely to format their code if they already have the tool to do it. I'm not sure what you mean by tools available on hackage though. Stylish-haskell is about it, and all it does is align and sort imports/pragmas. Gofmt can basically rewrite go code however you want it to. Sort of like if hlint were built in to stylish haskell and did the replacements instead of suggesting them.