14 ms·
Go and Assembly
- freehunter 14y agoAnd herein lies the problem with Go. Seriously, try searching for articles about Go on HN. People always say "well the name isn't a problem, because you just search for it with "golang" instead!" but no one writes golang unless they're pointing out how to search for it. If I was trying to get back to this article a month from now and I searched for "go", would I find it? Probably not, unless I remembered the article title contained the word "assembly", but then I'm matching a search to assembly and not Go. The name is a problem. And if the name is not a problem, then the community is a problem.
- bthomas 14y agoI'd imagine Google recognizes you're a programmer and modifies your results for "go" accordingly
- muyuu 14y agoIt doesn't. Well, considering how hard I try not to be tracked by Google, probably it does for someone else.
- nextparadigms 14y agoWould you say the HN search is a "good one"? And who would search for Go just by typing go in a search bar? Would you really do that on Google? I don't even do that for less common words, let alone one like "go". I usually use 3-4 words for my queries, maybe more. Because I have a pretty good idea of what I'm looking for and I don't want to waste time looking into pages of search results to find the relevant article, because I only searched for one word.
- Jabbles 14y agoWell, I'm glad to hear you don't have any substantial complaints about the language. What exactly are you searching for? Perhaps I can help you... http://lmgtfy.com/?q=site%3Anews.ycombinator.com+go 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 http://goo.gl/fqNiC )
- caligo 14y agoC has a bit of a problem with search as well. There is C, C++ Obj-C and C# which all tend to come up in searches. And that is excluding things that can be avoided with additional key words in searches, such as C the default drive on Windows and C as in City Group.
- dualogy 14y ago[[[EDIT: wrote this little rant before realizing you specifically refer to HN search rather than general search. Yeah why would I ever search on a specific Go topic exclusively on HN, instead of web-searching?]]] 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.
- TylerE 14y agoYour examples make no real sense, other than "Basic". Perl is absolutely NOT a common word. Pearl is common, but Perl is the programming language (only)
- dualogy 14y agozOMG you're right re pearl -- I'm kinda shocked at myself right now. In my defense, in German it's "Perle" so not that different... 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.
- TylerE 14y agoI found a list of English words by frequecy of use in Project Gutenberg texts. "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.
- songgao 14y agoAccording to golang FAQ, the origin of the name is that, “Ogle” would be a good name for a Go debugger. [1] 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 http://golang.org/doc/faq#What_is_the_origin_of_the_name
- jerf 14y agoWell, Go is a dynamic name, a verb, it evokes travel, motion, activity. Goo is a very static name evoking "slimy", "disgusting", and also, "useless for building things". I don't think Goo is a very name for a computer language. Then again... http://en.wikipedia.org/wiki/Goo_%28programming_language%29 http://en.wikipedia.org/wiki/Goo_%28programming_language%29 , although the homepage http://people.csail.mit.edu/jrb/goo/ 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.
- jholman 14y agoI think you should consider the possibility that the FAQ is joking. 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.)
- songgao 14y agoI didn't know that! Thanks :-)
- coldtea 14y ago>Seriously, try searching for articles about Go on HN. 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.
- scott_s 14y agoI didn't even have to use that Google feature. "go hacker news" works great.
- morhus 14y agojust type go language, go programming
- naner 14y agoYes, the name can be difficult to search for. Same with C. Nothing is going to be done about it so most of us have moved on. 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.
- tomp 14y ago"C" might be even shorter, but I think it's much less frequent in the english language (as a word) than the word "go".
- tptacek 14y agoThe name "Go" is a problem, but the name "C" isn't? Silly.
- anon1385 14y agoWho said the name "C" isn't a problem?
- tptacek 14y agoI do indeed have the impression that anyone who would bring up Golang's name as a serious flaw would also believe that C's name has held it back as well.
- chc 14y agoWell, you're a bit mistaken. There are a couple of reasons why this isn't the case: 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.
- emmelaich 14y agoC and R used to be hard to search for, but these days Google search does brilliantly given a bit of context. If Go is hard to search for now, be sure it will get better. I do wish they had chosen a different name, but I realise it matters less and less.
- jlgreco 14y agoHonestly R is still a pain in the ass to search for, much more-so than Go currently is. This might be a fluke of my personalized google search results though.
- tel 14y agoWhy the \cdot? Is Unicode required to parse assembly?
- vanderZwan 14y ago"Source code is Unicode text encoded in UTF-8." http://golang.org/ref/spec#Source_code_representation 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 http://news.ycombinator.com/item?id=5185334
- Xeoncross 14y agoThat is pretty neat. I'm glad he mentioned that the Go compiler will not inline functions written in assembly, but it will inline small Go functions.
- dualogy 14y agoYeah but the list of restrictions preventing inlining is pretty exhaustive...
- georgemcbay 14y agoThis is true currently but both the inlining and the garbage collector have improved tremendously over the past year and should continue to get better. 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).
- pcwalton 14y agoMost C dialects (for example, GCC and Clang) provide some form of explicit inline qualifier that forces inlining, for example "attribute((always_inline))".
- dualogy 14y agoGreat write-up. As I'm perusing the math/somefeature_arm.s and math/somefeature_amd64.s files in Go's math package, I can't help notice most of them look like this: http://golang.org/src/pkg/math/remainder_arm.s 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")?
- cdoxsey 14y agoIn this case there is a 386 implementation: http://golang.org/src/pkg/math/remainder_386.s http://golang.org/src/pkg/math/remainder_386.s The other two call the go version: http://golang.org/src/pkg/math/remainder.go http://golang.org/src/pkg/math/remainder.go
- dualogy 14y agoYeah that was kinda my point ;)) so basically 386 users get some highly specialized hand-tuned asm optimization whereas arm and amd64 merely get a commoner's gc treatment -- or am I missing something? ;)
- cdoxsey 14y agoYep. I would guess the compiler produced sufficiently optimized code for the other platforms. Very little of the Go standard library is written in anything but Go.
- stephencanon 14y agoSeveral things: - 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.
- Peaker 14y agoExcept for his bullet about compiler speed, which might be faster than GHC, all of his bullets apply to GHC Haskell too.
- Tyr42 14y agoWait, even "Go comes with a complete set of documentation available from the command line". I use hoogle from the command line, is there anything else for Haskell?
- Peaker 14y agoHoogle type search is great: Give a type, get back names implementing that type or a generalization of it. There's the haddock auto-generated documentation from cabal (if you enable it). Not sure if that qualifies for "available from the command line".
- jerf 14y agoHaving used both a bit (Haskell substantially, still fiddling with Go), there's no "might" about it. But then, "Go compiles quickly" was an explicit design goal from day one. "GHC compiles quickly" is certainly much further down on the list of GHC design goals. 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.)
- papsosouid 14y agoI write haskell code all day. I spend my day writing it at work (with occasional HN breaks obviously) and then I go home and write personal projects in it. I advocate haskell on a semi-regular basis. I certainly fall on the pro-haskell side of things. But GHC absolutely does not meet all those bullet points. 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.
- pbsd 14y agoDoes Go only support that crazy Plan 9 (amd64) assembler syntax that nobody uses anywhere?
- vanderZwan 14y agoWell, since two of the original three developers (Pike and Thompson) were part of the Plan 9 team, it makes perfect sense that they based the compilers on the Plan 9 ones.
- cpeterso 14y agoI see recent commits in Go's mercurial history to fix bugs on Plan 9. Is anyone at Google actually using Plan 9 to develop Go? Or is building for Plan 9 just a sanity test for maintaining cross platform code? Wikipedia says the last "stable" release of Plan 9 was in 2002, but there seem to be a number of recent forks.
- burntsushi 14y agoThere are people that don't work at Google who contribute to Go. It's an open source project.
- 4ad 14y agoPlan 9 is on a rolling release since 2002.
- drivebyacct2 14y agoGo also offers a set of features in the build system that make it obvious and intuitive to write assembly for different targets, all without having to muck with makefiles or macros. http://golang.org/pkg/go/build/ http://golang.org/pkg/go/build/
- pjmlp 14y agoThis is a nice example how to do low level programming while using a safe strong typed language most of the time.
- arlasbane 14y agoYou can always search "go programming", and the search engine should give you the results of go that occur in the context of programming, which should usually pertain to the go programming language.
- deleted 14y ago[deleted]
- justsomedood 14y agoThis reminds me of a topic that had come up earlier last year: Intermitten problems with 32bit programs in go. If I remember correctly programs would crash intermittently if the initial 512MB memory block requested wasn't contiguous. Does anyone know if this still is the case? Is the solution still to always just use 64bit?
- dualogy 14y agoAs I'm only on 64b right now, I can't quite remember whether that was fixed by 1.0.3 or will be in 1.1 -- but I'm pretty pretty sure one of these is the case.
- charlieflowers 14y agoNow this is an impressive argument. Particularly the first section about the tool chain (and the assembly part is really cool too). 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.
- felixge 14y agoGo supports panic/recover which is very similar to exceptions. Instead of wrapping a try...catch block around something, you get to handle exceptions every time they are about to cause a function to be exited. 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).
- jlgreco 14y agoI think the real value of panic/recover over try/catch is the vastly improved idiomatic usage. Only to be used in exceptional cases, and never to cross package boundaries. I just find that so much more pleasant.
- charlieflowers 14y agoHmmm, interesting. The "defer" approach is a different spin on things. But yes, panic/recover does look like it would address my concerns. I never did like exceptions across package boundaries much, but inside a cohesive module I want to use them instead of a bunch of code that checks return values for error codes.
- charlieflowers 14y agoAlthough, another post above says it's not idiomatic, so I guess working with go means accepting the lack of an exception mechanism.
- damien 14y agoSo what does that middle dot actually do before the function names? It doesn't seem to be mentioned in the linked documentation of the Plan 9 assembler, and if I have to use a character that I can't easily type with my keyboard, I'd like to at least know what it actually does. :) 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?
- mseepgood 14y ago> So what does that middle dot actually do before the function names? http://stackoverflow.com/a/13490787 http://stackoverflow.com/a/13490787 http://article.gmane.org/gmane.comp.lang.go.general/78328 http://article.gmane.org/gmane.comp.lang.go.general/78328
- rartichoke 14y agoI only have 2 problems with Go. 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.
- iand 14y agoTry http://godoc.org/ http://godoc.org/ Because Go uses URLs for package names its easy to build tools like godoc.org that automatically aggregate packages from the web.
- rartichoke 14y agoIt's a good start but it needs many more features to be considered usable. For example, I just did a search for "redis" and about 30 libs came up. Half of them don't even have a description. 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.
- jlgreco 14y agoHow do you handle that with any other language? There is no shortage of redis libs for any language.
- flogic 14y agoIf we look at CPAN http://search.cpan.org/search?query=redis&mode=all http://search.cpan.org/search?query=redis&mode=all , there are a few things right in the search results. We have version numbers, release dates, and a review score. All of those give you a chance at finding a half decent library. The first result was updated a week or 2 ago and has 4 significant digits in the version number. None of it's a guarantee but it's a place to get started.
- cjh_ 14y agoThis font renders odd in IceWeasel 10.0.12 , all occurrences of the letter 'e' have their left side 'cut off' so they stand out and are very difficult to read. Chromium Version 22.0.1229.94 Debian 7.0 (161065) works fine.
- Aissen 14y agoSame on Mozilla's official Firefox 19 (beta channel). Raising the font size (Ctrl +) makes the issue go away.
- csense 14y agoThis assembler is awful. I thought that AT&T had a monopoly on ghastly assembly language syntax -- but this article causes me to question that assumption: 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!
- jlgreco 14y agoHow does it require unicode?
- csense 14y agoThe article talks about making a label whose name begins with a middle dot.
- reinhardt 14y agoIt's amusing that the first line is considered "terrible" but the latter is "comprehensible". For someone versed in modern languages they both look like gibberish.
- csense 14y agoHere's an explanation suitable for someone only familiar with high-level languages: 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.
- WalterBright 14y agoHere's how to do inline assembler in D: 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.
- strmpnk 14y agoWell, this article wasn't about _inline_ assembler. Regardless, inline forms have a number of problems, the biggest one being supporting multiple platforms w/o a bunch of preprocessor noise. That doesn't stop it from being useful for certain languages but it matters less and less given how compilers behave these days.
- WalterBright 14y agoThere is a steady drift away from using assembler even in languages that support it. Intrinsics, for example, often work better. But there are a few things where it really comes in handy.
- strmpnk 14y agoI wonder if we'll see more user-side emulation of intrinsics given new __attribute__ flags compilers are implementing. It certainly is easier to reason about. 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.