6 ms·
I'm historically a braces-on-their-own-line guy, so getting used to the strict enforcement of the other style was a pain for me Wait, what?
by CamperBob 15y ago
I'm historically a braces-on-their-own-line guy, so getting used to the strict enforcement of the other style was a pain for me
Wait, what?
- FreakLegion 15y agovoid func() { } vs. void func() { } Does Go really enforce the latter? That would be incredibly silly.
- enneff 15y agoIt does, but for a good reason. Its so the parser can find the line endings without needing complicated rules and look-ahead. Go style is enforced mechanically with gofmt (http://weekly.golang.org/cmd/gofmt/ http://weekly.golang.org/cmd/gofmt/), anyway, so one typically drops the pretension of these kinds of style quibbles. It is more important to have one consistent style than to make everyone happy. The gofmt style forced me to change several of my own habits, but it was definitely worth it for my code to look like everyone else's. I've never encountered a Go programmer who hasn't become grateful for gofmt, in the end.
- FreakLegion 15y agoThanks for answering! I have no idea why someone downvoted your reply. People: downvoting is for mean and/or stupid comments, not things you disagree with. Anyway, in that case I imagine we'll see a Go preprocessor that takes all the line-initial braces and moves them up a break before sending code to the compiler. People get pretty worked up about this stuff.
- nakkiel 15y agoI work in a place where people don't use spaces and don't use empty lines to separate logical groups of lines. It's a real pain for me who is a code format junkie as our code ends up being an ugly pack of unrelated crap that's really hard to read. It's Python code and I find it uglier than some fairly large C++ project I used to work on. Anyway, I wish there was a gofmt in Python because at least, I'd drop all hopes of forging my own rules (silly junkies) and some basic clarity would be forced into our codebase. I know there are beautifiers but when such things are enforced and not negotiable, it's just so much simpler and people just stop caring as well.
- cageface 15y agoIt's Python code and I find it uglier than some fairly large C++ project I used to work on. I've always argued that if your team can't bother to even indent code properly than you have much bigger problems than any language formatting rules can solve.
- scott_w 15y agoOne time we worked on some code, and one of the developers had the same habit: "It works, so why do I need to format it?" We decided to make our build system run PEP over the code, resulting in a failure if PEP didn't pass. It annoyed the hell out of him, but we quickly got the formatting up to a better standard.
- FreakLegion 15y agoI completely support enforced style -- it's part of what I love about Python and F#'s light mode -- but it has to be the right style. I strongly believe that code should look like a screenplay, not a novel. More white space, in other words, is rarely a bad thing. Inline braces decrease white space and make unfamiliar code harder to scan, so to me they're Not Good. Also wow, I didn't know it was even possible to write Python without spaces. Are we talking no spaces in arguments, like def func(arg1,arg2): print "Indented" return or full-on no spaces? def func(arg1,arg2): print "Not indented" return I thought the latter was prohibited.
- nakkiel 15y ago
- ma2rten 15y agoDon't want to make this a big meta discussion, but I noticed that often the best comments are downvoted first, and eventually end up on the the top of the page. Don't worry this type of thing corrects itself.
- amattn 15y agoNothing in go is silly. There are multiple reasons why it's required. The answer usually given is faster compile times and the removal of semicolons from the language. I don't know the details, but someone new complains about it on the mailing list fairly frequently. Also having a tool enforced brace style is just plain practical. Less silly arguments/bikeshedding. I was also a brace on its own line kinda guy, but between javascript and go, I've gotten over it.
- mbreese 15y agoPerhaps this will be Go's version of Python's whitespace issue. People will balk at the seemingly arbitrary nature of the syntax and avoid trying the language. However, after time, the rest of the language's advantages will lead people to get over their syntax aversion and try the language. Then after 6 months they'll look back and wonder what the big fuss was before. Not that I have any experience with that...
- karterk 15y agoWhat about using two characters for assignment? a := 1 vs a = 1
- kinghajj 15y ago":=" is type-inferred variable declaration and assignment, while "=" is just assignment.
- alextgordon 15y agoIt is a bit annoying having to press 3 keys using two hands instead of just one. With '=' I can "hyperthread" my typing. While I'm finishing the LHS and pressing space I can move my right hand to press '=', while keeping my left hand thumb in place to press the space bar for the right side. With ':=' I have to stop everything to press shift with my left hand, then press ':', then release shift and press '='. It's very inefficient for something that happens often.
- 15y ago
- jbarham 15y agoIt's a FAQ: http://weekly.golang.org/doc/go_faq.html#semicolons http://weekly.golang.org/doc/go_faq.html#semicolons
- CamperBob 15y agoFrom that page: "At the moment, all implementations use 32-bit ints, an essentially arbitrary decision. However, we expect that int will be increased to 64 bits on 64-bit architectures in a future release of Go." So, in other words, it's Amateur Hour. All righty, then. /backs toward door, reaches for doorknob, still smiling and nodding
- 4ad 15y agoFantastically dumb comment. FWIW int in C is also 32 bit on all mainstream 64 bit operating systems, and Go has int64.
- CamperBob 15y agoFantastically dumb comment. FWIW int in C is also 32 bit on all mainstream 64 bit operating systems, and Go has int64. ROFL. I challenge you to find documentation for the C language or any other language commonly used in production where they speculate that they might wake up one day and change sizeof(int) on an existing platform. "Fantastically dumb," indeed.
- 4ad 15y agoC is that language, among so many others, sizeof(int) is implementation specific, and indeed it does vary, though (S)?ILP64 is rare. On the other hand sizeof(long) varies all the time. You seem very ignorant, please learn and stop the FUD.
- CamperBob 15y agoYou seem very ignorant Yeah, that must be it.
- alok-g 15y agoI see the line of reasoning behind this as explained by various comments here. But why can't this just be an user/editor preference while the file saved may use whatever convention?
- canop_fr 15y agoYou don't read only your code, but also code from other people. Go make it really easy, in my opinion, to fast decipher foreign code, due to shortness, clarity, and conventions. Convention help you recognize in that case the structure of the function without having to make your mind around the habit of the other coder.
- alok-g 15y agoI do not care who wrote the code -- It should be shown to me using my formatting preferences, just as I can use my own visual theme in the editor. Those themes do not affect the code as it is saved into the file, and those formatting preferences should not either.
- JulianMorrison 15y agoFormatting is semantic in Go, newlines are significant, so a brace across a newline is quite reasonably different from a brace on the same line.
- tzury 15y agovoid func() { } Is my natural choice anyway, so I guess, this will not stand in my way. Let's go!