Researchrsc: Gofmt
research.swtch.com
research.swtch.com
Oh and, that -r pattern-matching search-and-replace is nice.
func main()
{
println("hello world")
}
Instead, if you run gofmt -w on the above code, you get this: func main() { println("hello world!") }
This compiles fine, but it looks ugly.I can compile (with 6g) the hello world example from golang.org with any brace indentation style.
Or you can read the relevant mailing list thread:
http://groups.google.com/group/golang-nuts/browse_thread/thr...
func main()
{
is read as: func main();
{
due to the new semicolon-inserting lexer rules. If you use the gofmt style, you won't notice this breaking change.Also, banner indenting style is superior!
"It's shorter" isn't a reason, it's a legacy.
For instance one of my beefs with Ruby (My main language) is: elsif. Would it really have been so difficult to have "elseif"? No.
Let's say you are skimming your code. Are you going to quickly and easily see the difference between "elseif" and "else if"?
Creating a new word, while superficially unwieldly, keeps you from wasting valuable time debugging one of those "d'oh!" bugs.
Now, in Ruby, if you type "elseif" your code will not run. Problem avoided.
The point of Ruby's "elsif" and Python's "elif" is to have visually disparate representations of the two kinds of code blocks (that have different control flows!) that a developer could easily overlook.
The difference is there to help out you and every other developer that use languages that don't use a visible token to separate code blocks, I promise.
can you give an example where this would make a difference?
I appreciate it; it's become an aesthetic, actually.
goformat is easier to understand than 'gofmt'. 3 characters.
Why? This smacks of religion to me.
goformat is easier to understand than 'gofmt'.
Only if you can't be arsed to learn the language or tools. If the fact that the tool has a different name than you would like is that troublesome, symlink or alias it.
Would it be better if I had to type out 'secure-file-transport-protocol' in the shell instead of 'sftp'?
The dogma of explicit names is preferable to the dogma of legacy.
"Only if you can't be arsed to learn the language or tools."
I contend that resolving fmt to format increases the complexity in reading and learning Go. Complexity is only tolerable when it provides benefit. The two proposed benefits are token brevity and legacy. I do not believe that preserving the legacy names of commands and packages is a benefit for a "new systems programming language" that is intended to replace the very legacy it is preserving.
Look there's no excuse here. goformat isn't that much larger than gofmt, easier to understand on initial read, and doesn't hurt a damn thing.
If Computers have no problem reading Brainfuck then they should have no problem reading a Programming Language that reads easily to humans. You know, those things that actually write and develop in these languages? Ruby made a stand in this and it turned out very very well.
In the language itself, fmt (something completely different from gofmt) is used as a package identifier. In the Go style, package identifiers are typed repeatedly, the identifiers inside a package are not imported into the global namespace. So if code contains many calls to the Printf function, there will be many instances of fmt.Printf. In this case, fmt instead of format is a good decision too. It's a package name (not a function name) and it is typed repeatedly, so the shorter it is, the less visual noise.
fmt.Printf is exactly the kind of crap that I hate. format.PrintFormattedString() is readable. If you are calling it all the time, then i'd suggest you have an output() function local to your class that forwards the call on. This is good practice anyway because you should minimize the tight coupling of your object with a foreign object.
If you watch the Go presentations, the examples using fmt are pronounced "fumt". fumt neither expresses the domain meaning or the implementation, and is perpetuating a bad habit.
Fortunately, you can have it your way by using gofmt to show you format.PrintFormattedString() when you edit, but give fmt.printf to the compiler.
As for the command name, there's always "ln -s ~/bin/gofmt ~/bin/goformat" or "alias goformat gofmt".