6 ms·
I must be one of the idiot complainers he talks about, because his first "good thing" annoys me right off the bat. If you want to change a private method to pub
by stickfigure 14y ago
I must be one of the idiot complainers he talks about, because his first "good thing" annoys me right off the bat. If you want to change a private method to public, you have to go through all your code and capitalize every use of it?
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.
- tptacek 14y agoRob Pike's Go FAQ says that this is one of their favorite features about Go, and I agree; it's how I've been writing C code since 1995. So, I mean, if conformance to my C programming style guide matters, YOU LOSE THE ARGUMENT! :) 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.
- stickfigure 14y agoIf I'm fixated on changing private -> public, that's because it's a common case. I doubt I'm alone with a programming approach of "start with everything private and expose public behavior only as necessary". 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.
- tptacek 14y agoThe two major virtues of case-based visibility: 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.
- stickfigure 14y agoPlease convince me this is a good idea. #1 does not seem to be a real issue. Most similar languages have the common, popularly understood, and easily-remembered keyword "public". Whereas capitalization is an exotic special rule that must be learned. If "you don't ever have to wonder how to expose something" is an important measure, I think Go is at a disadvantage here - especially if you want your code to be read by neophytes. #2 is the argument for hungarian notation. Why is it important to visually distinguish public/private as opposed to, say, local vs member variable? I point this out because IDEs have a long history of visually distinguishing local vs member variables and some programmers even use naming prefixes like '_' or 'm_'. Yet I've never seen an IDE highlight members based on visibility. Given this backdrop, it's certainly not obvious that visibility requires such an important visual reference. And why shouldn't the IDE be responsible for this decision? Counterarguments that programming languages should be designed for 80-col amber VT100s sound pretty wacky in 2013. Regarding terseness of the language, I'm not convinced. Without exceptions, Go adds an ton of "if error then return error" boilerplate to practically every function call. This is a lot more typing than adding 'public' to struct members.
- tptacek 14y agoI think you have to look at this in the context of the whole language. Go doesn't just not have a "public" keyword. It also doesn't have classes. The way Go structures code is optimized to maximize code reuse while minimizing declarative syntax. So Go has an integrated package system (unlike C++) because that helps you build modules of code that can easily be used across projects, but doesn't have inheritance (unlike C++) because that is a feature that is less about reusing code and more about modeling systems. I'm sure you've had the experience of working with libraries in other languages where the designer couldn't or didn't make up their mind about whether to expose capabilities as free functions or classes that needed instantiation, or, worse, exposed factories and singletons to get around their discomfort with simple functions. Go sidesteps this problem. I found it helpful to think of it not as removing the "public" keyword from struct defs, but as creating a mechanism to "promote" functions and variables in packages --- something that would feel very shady in C++, but doesn't in Go. As a result, a lot of packages do The Simplest Thing That Could Possibly Work and just expose simple functions. The result is usually refreshingly clear. I agree with you about error handling; Go's error handling makes its source code (though not its library interfaces) fussy and hard to read.
- CJefferson 14y agoActually, I find public->private is not a breaking change, because before I do a 'public->private' change, I first remove all the public calls. Therefore, all I have left to do is to check the in-class calls.
- alanctgardner2 14y agoThat's great for you, but I suppose you've never published a module on CPAN, a ruby gem, a Python... egg (man, that's a weird convention). As soon as someone else depends on your module - and Go is very modular, this behavior is encouraged - suddenly it's an exercise in putting fluids back into containers, or whatever they say.
- cdcarter 14y agoNot only is tptacek completely correct, the Go maintainers are completely against code colorizing, so having visual markers in syntax is quite nice.
- tptacek 14y agoThey're against code colorizing?
- seanmcdirmid 14y agoThey mean syntax and semantic highlighting. It's mostly a generational thing that goes along with 80 column line widths on amber terminals.
- papsosouid 14y agoI wonder how much of that is older programmers being used to not having highlighting, and how much is younger programmers having never tried programming without it. I think the default assumption is that it is all old people resisting change (hence the 80 columns amber terminals bit), but I'm a younger anti-highlighting example. I am not old, I learned to code with coloured syntax highlighting. I didn't realize how much of a hindrance it is until after I had been programming for years and tried turning it off.
- waterlesscloud 14y agoI'm old enough to have done both, and it doesn't matter much to me one way or the other. If anything, I think coloring is slightly helpful, but I'm fine without it.
- seanmcdirmid 14y agoSometimes paradigm shifts are just that and indicate generational pivots. Ask an electrician today to do some wiring without color coded wires and they'll think you are batsh*t crazy, but it probably wouldn't have been so crazy a hundred or so years ago when color wasn't viable. The same thing applies to code; these people grew up programming before color monitors were much of an option.
- Jabbles 14y agogo through all your code and capitalize every use of it Due to the ease of parsing go, it comes with a tool called gofix, designed for exactly this kind of change. http://golang.org/cmd/fix/ http://golang.org/cmd/fix/
- rsaarelm 14y agoIf you want to change private bar to public Bar from package foo, the standard trick is to use gofmt's rewrite option and run "gofmt -r 'foo.bar -> foo.Bar' -w *.go".
- NateDad 14y agoNot all code is read in an IDE. Also, most IDEs don't color names differently at call sites. For example: 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.
- snprbob86 14y agoIf you're are changing a... ...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.
- deleted 14y ago[deleted]
- vanderZwan 14y agoYeah, I guess it could be handled with a refactoring IDE... if Go has one. It does: http://golang.org/cmd/gofmt/ 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 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.