95 points · by ansible · 13y ago · 122 comments
It essentially presents a false dichotomy between programming research and programming practice. This is particularly unfortunate because the most practical and productive languages I know are the ones that embrace theory like OCaml and Haskell. After all, most programming research is all about being more productive in some way, and tends to approach the problem in a very organized and disciplined fashion, usually building on past results.
[1] http://www.youtube.com/watch?v=3DtUzH3zoFo [2] http://swtch.com/~rsc/regexp/regexp1.html
Allow me to provide some context [1] for the quote. Shortly after the language was released, somebody was ranting [2] about how Go was not innovative at all in comparison to other modern languages. I was not suggesting that programming research is useless and that we should ignore several decades of progress. I was, rather, saying that Go was applying those several decades of progress to systems programming to produce a more modern version of C. Here is the whole paragraph that quote was lifted from:
"The point the author fails to see is that Go is not meant to innovate programming theory. It’s meant to innovate programming practice. This is an upgrade to C. It’s a language that applies the innovations of the last thirty years to the systems world, where the state of the art is still portable assembler. So no, the language isn’t introducing brilliant new ideas. It’s taking tested old ideas, and introducing them into a new arena."
[1] http://blog.alieniloquent.com/2009/12/15/newsflash-go-is-exp...
Yeah, I guess it could be handled with a refactoring IDE... if Go has one.
This feels like a throwback to hungarian notation. Names should just be names, quit trying to cram code syntax into it. Besides, if you do have a competent IDE, it can colorize private vs public names differently.
I'd also contend that no language makes changing the visibility of a variable completely painless. You're fixating on the one case where you can change the token "private" to "public" and write new client code for a class. But you're ignoring public->private, which is a breaking change no matter what syntax you use; you're also ignoring the fact that moving a variable out of or into a class (for instance with class statics) is breaking no matter what you do.
As this article points out, the major win for simply using case to signal this is that the language gets to dispense with fussiness about where variables are; you can just put them in packages when they make sense.
It's all tradeoffs, of course. It's certainly your prerogative to be annoyed by design decisions in Go! I'm extremely annoyed by the import use requirement and refuse to not be annoyed by it no matter how many times Rob Pike and Russ Cox say it prevents bugs.
More philosophically, I have to wonder what the benefit of this capitalization scheme is. Just to avoid typing 'public'? Hardly seems worthwhile. To make it obvious when reading code? This is the same argument for hungarian notation, which even Redmond has abandoned. IDEs for static languages like Go are perfectly capable of presenting identifiers appropriately - if indeed public/private is really what you want to call attention to.
I admit that I've not done more than dabble in Go, but I'm somewhat skeptical of this last point. Of all the IDEs I have used for various static languages, I have yet to see any that visually distinguish public vs private identifiers. If calling attention to this distinction was so important that it should be built into the language, I would expect it to be common practice in IDE formatting already.
1. It creates a coherent syntax for making names visible that works both for member variables and package variables; you don't ever have to wonder how to expose something, because you always do it just by making the name uppercase.
2. It allows readers to see at a glance without thinking whether a value is public --- it's public if it's a proper name.
In practice, Go struct definitions are extremely succinct, almost (at first) to a fault, because of decisions like this that eliminate syntax from the language. Compare a Go package to an equivalently functional Java package to see what I mean.
Javascript - always capitalize classes
Python - underscore before private properties
C# - underscore in front of class level private properties
Python upgraded the whitespace convention to meaningful whitespace, why shouldn't Go upgrade the naming convention?
...private to public:
The only references are in your package. They can be found trivially with ack or grep.
...private mutable variable to public:
You want to inspect all usages anyway to ensure that you're not violating the public invariant.
...private function to public:
You want to inspect all usages anyway in case you'd prefer to call an internal version of the function without the same preamble, such as argument defaulting or validation logic. If you change 'foo' to 'Foo', you can leave 'foo' around and just have 'Foo' call it.
...public to private:
You need to find all the external references anyway to eliminate them. Since the references are capitalized, it's easy to find them with a grep or ack. You won't get lots of false positives from locals that are named without a capital.
;
Personally, I prefer languages that let you bend the rules when you need to, but I also work with small and skilled teams on largely exploratory projects. If I were working on a larger and ever evolving corporate team, I'd be all over Go. They have made some excellent design trade offs for that audience; ie Google's internal usage.
Due to the ease of parsing go, it comes with a tool called gofix, designed for exactly this kind of change.
I wonder if Rob Pike is colorblind.
It does: http://golang.org/cmd/gofmt/
This feels like a throwback to hungarian notation. Names should just be names, quit trying to cram code syntax into it.
Well, speaking of Hungarian notation:
http://www.joelonsoftware.com/articles/Wrong.html
Following that logic you are right, but it's a throwback to the good kind of Hungarian notation.
a = foo.Bar()
You know Bar is a public function of foo. It's not hungarian notation because you're not adding otherwise-nonsense characters to the beginning of an identifier, which would make them longer and harder to read.
You can use version control commands directly to get code from your own repository mirror or to get specific versions from a repository. As long as you clone the repository to the directory in the workspace corresponding to the import path, all of the other go tools will work with the code.
If you want to roll your own mirror simply change github.com/foo to my mirror.com/foo in your code. At least then you document the expected dependency with the code itself and can remove it if required. It also lets you very easily import a local package instead if you prefer. If the maintainer changes the location of their package and you have not taken a copy you might have to change your code, but this happens very rarely in my experience and isn't a big issue.
Go doesn't have versioning for packages yet, and they will need to add this, but that wouldn't be hard to add as an option to the current import scheme.
This is very messy. If a mirror changes, you have to go back through all of your source code and change all of the relevant imports.
I personally find the node.js/npm solution to the problem (separate the dependency mapping for external resources, allow changes to those without having to modify the source) to be more useful. It lets you swap local and remote versions effortlessly and, using a private npm server, maintain packages for a large internal network.
Have you run into real-life problems with this or is it more a hypothetical issue?
You can use local package import paths instead if you prefer to manage your dependencies separately (and have several different goroots too with different sets of packages), or use DNS/hosts to manage where your private package server domain points, there are lots of options which don't require specification of a package server in one place.
Instead of changing the code, use a version control command to clone your repository mirror to your workspace.
Replacing the imports is pretty easy, though - because Go is so draconian about certain elements of formatting and style (including restrictions on imports), it's relatively straightforward to migrate code like this.
(The 'go fix' tool is an even better example of the power that such an opinionated compiler provides as its tradeoff)
Let’s say I want to declare a pointer to a variable length
array (what Python calls a list and Go calls a slice) of
pointers to FooType objects:
var foo *[]*FooType
It reads very simply ...
What???? Not that it's better in other languages but this makes the article feel like satire. It reads like "The Ugly" and "The Bad".Aside: What's with the completely defective comment syntax on HN? Can anyone give some hints on how to quote and how to escape the star character?
edit: formatting, thanks spacemanaki
Go's declaration syntax is one of the best things about the language. I thought it would take me forever to get used to, but within a day it was the opposite: C feels backwards. It's especially excellent for references to functions.
[1] http://golang.org/doc/articles/gos_declaration_syntax.html
Simpler variables are declared as
var a int
or with type inference: var a = 10 [FooType]
and: Slice<FooType>
If you think you must, apply sigils. The position of the brackets in the Go version is atypically bad for readability.Where do your examples say they're pointers?
How would you express this using your first syntax?
*[4]*FooType var foo *[]*FooType
http://news.ycombinator.com/formatdocSo the author wants to type "./foo.go" rather than "go run"? Why not just build your executable, "go build", then you can run/move the resulting executable ./foo.
This really doesn't seem like a big deal / why do I want to compile a utility program every-time I run it?
But someone could write shebang-go wrapper to implement this functionality, but a modification to Unix would be needed, since shebang is a magic hack on the '#' character, not configurable,IIRC
Downside: couldn't read past "And what’s up with all the languages that claim all you need are linked lists? I’m sorry, this is not 1958, and you are not John McCarthy".
Did I miss anything amazing in the rest of the article? Thanks in advance.
Yes, you missed the fact that quitting articles or conversations because of some remark (which could even be tongue-in-cheek) doesn't make you any smarter and that "I stopped reading where he said" is not something to brag about.
This is the problem with the internet and with political discourse in the 21st century: as soon as someone says something that seems off-kilter, even if it is technically correct, people stop listening/reading.
Apparently, I missed that Go could have, but didn't, support a syntax with shell shebangs at the tops of files so it could be used for utility scripts. I feel like I probably made the right call stopping where I did. ;)
Grow up.
/tmp/dmd2/src/phobos/std$ wc -l *.d | grep total
162688 total
/tmp/dmd2/src/phobos/std$ time dmd -c *.d > /dev/null
std.cpuid has been deprecated. It will be removed in January 2013. Please use core.cpuid instead.
std.md5 is scheduled for deprecation. Please use std.digest.md instead
std.perf has been deprecated. It will be removed in January 2013. Please use std.datetime instead.
Notice: As of Phobos 2.055, std.regexp has been deprecated. Please use std.regex instead.
real 0m1.210s
user 0m1.016s
sys 0m0.188s
1.2 second to compile 162k LOC. Not too shabby!Calling people who disagree with a specific coding convention idiots was irritating, but it at least had a bit of merit - namely that 'readability counts' and that the code is more readable if it's written in consistent style.
The remark about linked lists in Lisps is both irritating and untrue. If even Schemes (I know. I just wrote a cute, little, hobby project in Racket and I used a list twice (by accident)) routinely deal with vectors and hashes then I can only imagine how many different builtin datastructures have CL (or Clojure) programmers at their disposal.
It probably was meant as a joke. Ok - it just isn't the sense of humor I share, that's all.
Also, the Less() method should not be defined for the slice types. They should be defined for the types in the slices. Every sane language lets you define comparing methods for types themselves, rather than bind them to the container types, to honor some software principles.
Also, "err" is a surprisingly common name for variables even in the same function. When it's previously defined, and the variable after it is not, the ":=" operator doesn't work (I seem to remember). Appending numbers to "err" is ugly IMO. I don't mind no exceptions if not for this. Speaking of it, making "err" a keyword or special global variable may be a good idea, like the "errno" in C.
x, err := f(a)
if err != nil { // probably time to return from the func }
y, err := g(x) // we have at least 1 new var, so := still works
if err != nil { // handle }
x, err = h(y) // since we're re-using both x and err, just use =
I've never appended a number to "err".A peeve: Just below the Accumulator Generator Challenge code, we find:
> The static typing adds a little noise, but it makes sense if you read it out loud: ....
It's not the static typing that is noisy, but the explicit typing. Haskell, for example has static typing, but it can avoid this kind of "noise".
I'm sure there is probably some way to implement the same thing in Go using duck typing. Just wanted to point out the difference though.
Sometimes an ad-hominen is the proper thing to say. And in particular cases any of the so-called "logical fallacies" can be very much true and useful.
For example, we use the "argument by authority" every-time we trust our doctor instead of our friend's intuition, and I'm perfectly fine with that.
An "argument by authority" might not be a perfect tool in 100% of the cases, but it's a perfectly good guideline when we don't have time to go through the details of the matter ourselves.
The old-wives-tales on "logical fallacies" point at their less than 100% accuracy and come to the wrong conclusion that they are bad and thus useless.