5 ms·
I'm more surprised that the Go 1.4 compiler is written in C. Writing a compiler in C sounds very unpleasant compared to a language like OCaml. Does anyone know
by cheepin 12y ago
I'm more surprised that the Go 1.4 compiler is written in C. Writing a compiler in C sounds very unpleasant compared to a language like OCaml. Does anyone know why they made this choice for the initial design?
- dsymonds 12y agoThe Go compiler in 2007 was written in C because it was an adaptation of the Plan 9 C compiler. That was done because it was the expedient choice at the time, especially while the language was still being designed and would change quite a lot. Nowadays the language is stable, and we have existing Go compilers, so we can reasonably bootstrap a Go compiler written in Go.
- enneff 12y agoKen Thompson wrote it. He's pretty good at C.
- tbrock 12y agoYeah someone also asked him if they did "code reviews" while developing Unix. The response always makes me laugh. Interviewer: Was there any concept of looking at each other's code or doing code reviews? KT: [Shaking head] We were all pretty good coders.
- zek 12y agoWhy does being a good coder preclude code reviews? Even experts make mistakes and even when there are no mistakes an outside perspective can often be useful. People think in different ways and may have something to add even if you are all really good programmers.
- farresito 12y agoThat's exactly the joke (if you can consider it a joke).
- moe 12y agoAnd sometimes you just want to get stuff done. The kind of mistakes that good programmers make are not normally caught in code reviews. That's pretty much the definition of a good programmer; their mistakes are rare and subtle.
- lpw25 12y ago> The kind of mistakes that good programmers make are not normally caught in code reviews. That's pretty much the definition of a good programmer; their mistakes are rare and subtle. I think the opposite is true. Good programmers know where the risks of subtle bugs are, and will use the appropriate tools (e.g. good use of a decent type system, well documented code with well designed abstractions) to make completely sure they don't exist. This just leaves simple stupid bugs in the parts of the code where any such bug will manifest itself quickly and obviously, exactly the kind of thing caught by code review. Another way to put it would be: good programmers design their code in such a way that all bugs are catchable by code review.
- ayrx 12y ago> The kind of mistakes that good programmers make are not normally caught in code reviews. That's pretty much the definition of a good programmer; their mistakes are rare and subtle. That's just arrogance. Good programmers make stupid mistakes all the time as well. It's the ability to recognize and fix such mistakes that separate "good" programmers from "normal" programmers and that's precisely where code review comes in.
- smosher_ 12y agoDid he? I was under the impression he wasn't approved to write C at Google when Go was initially being developed. http://www.theregister.co.uk/2010/04/21/ken_thompson_take_our_test/ http://www.theregister.co.uk/2010/04/21/ken_thompson_take_ou...
- chubot 12y agoThat article is misleading -- it's really about C++, not C, and isn't really relevant to the Go compilers (which are written in C). I have Coders at Work and I think Ken Thompson was exaggerating a bit for the humor of it. There is a "readability" process for C++, which is the thing he says he never got. Not much code is written in plain C -- the Go compilers would be an exception. If I recall correctly, the book Coders at Work also talks a bit how the some of the Go/Plan 9 guys sat near to Bjarne while he was developing C++ at Bell Labs. They are not really fans :)
- 4ad 12y agoYes, Ken wrote the compilers: https://github.com/golang/go/commits/master/src/cmd/gc?author=ken https://github.com/golang/go/commits/master/src/cmd/gc?autho... Use your local git(1) for better history browser.
- scottlamb 12y ago> Did he? I was under the impression he wasn't approved to write C at Google when Go was initially being developed. It's not that strict. Google has a big source repository which holds essentially all applications which run on Google's production machines. (They share a lot of library code.) In this repository, code written in any of several languages must have been written or approved by someone who has "readability" in that language. There's no C readability, but C++ readability applies to files ending in .cc or .h. (Not sure about .c.) There's no shortage of people around with C++ readability, so Ken wouldn't have had a hard time getting anything approved. He also could have easily gotten readability if he wanted it. This process wouldn't necessarily apply at all to separate git/Mercurial repositories used by open source things like Go.
- nl 12y agoKen Thompson wrote it. He's pretty good at C. Indeed he is. All the more reason for code reviews. [;] [;] http://cm.bell-labs.com/who/ken/trust.html http://cm.bell-labs.com/who/ken/trust.html
- rsc 12y agoThat's exactly why it makes no sense to review Ken's code. Review his binaries, maybe.
- andrewchambers 12y agoC isn't as bad for compilers as it is for servers.
- danieldk 12y agoOne advantage is that nearly any system has a C compiler. [1] http://gcc.gnu.org/git/?p=gcc.git;a=commit;h=2b15d2ba7eb3a25dfb15a7300f4ee7a141ee8539 http://gcc.gnu.org/git/?p=gcc.git;a=commit;h=2b15d2ba7eb3a25...