<p>So this is a simple question - it would be better for people to answer either way. (So that answers don't self-select just for people who are/aren't annoyed by it.)</p>
<p>Question: if you have programmed in Go for several months (i.e. written at least thousands or tens of thousands of lines of Go) - do you (still) find it annoying that Go's type declarations go after, not before as with other languages?</p>
<p>Simple question, simple answer. (By the way my expectation is that most answers would be 'not at all, got totally used to it.')</p>
<hr/>**评论:**<br/><br/>adelowo: <pre><p>When I started around 5 months ago, it was a little bit weird but I read a blog post by Rob pike on this -- > <a href="https://blog.golang.org/gos-declaration-syntax" rel="nofollow">https://blog.golang.org/gos-declaration-syntax</a> - and I have been fine with it since then</p></pre>throwawaybeginr: <pre><p>I'm also fine with it. It's just still "a little weird" for me and I'm just curious if it will stop being "a little weird" for me after a few months. Thanks for your reply!</p></pre>shazow: <pre><p>It hasn't been weird for me after a few months, but it's definitely frustrating when I switch between Go and C... especially when writing inline C and they're in the same file. :S</p>
<p>(Edit: To clarify, I do prefer the Go way at this point.)</p></pre>throwawaybeginr: <pre><p>Thanks for this reply.</p></pre>TheRealMrTux: <pre><p>It's the other way around for me. I was forced to write some java the past weeks and found myself writing types after the variable name. We had good laugh after</p></pre>throwawaybeginr: <pre><p>Thanks for this feedback. So writing go is totally natural for you. Could I ask if that extends to every part of the language? (every syntactical portion). For example slices seem a bit weird for me still, etc. To you is everything natural now?</p></pre>TheRealMrTux: <pre><p>I am by no means an go expert.
I guess, the language you're writing the most in l, feels the most natural to you.
What part of slices seem weird to you?
Writing in go is a great experience and I like every part of the language, even though I still discover new things every now and then.</p></pre>metamatic: <pre><p>I've done the same thing, written types after variable names in other languages.</p>
<p>Slices seem natural enough to me because back in the day I implemented a similar data structure for lists (arbitrary-sized arrays) in object-oriented Pascal. </p>
<p>The way slices work is basically how you make lists work without the overheads of linked-list traversal; the only thing that's weird compared to other languages is that the details are visible to the programmer.</p></pre>sh41: <pre><p>Please compare <a href="https://cdecl.org/?q=char+%28*%28*x%28%29%29%5B5%5D%29%28%29" rel="nofollow">cdecl.org</a> vs <a href="https://godecl.org/?q=var+x+func%28%29+%2A%5B5%5D%2Afunc%28%29+rune" rel="nofollow">godecl.org</a> and tell me which you'd rather deal with on a daily basis.</p></pre>md2perpe: <pre><p>Why should it be annoying? I think that it's as natural to have the type after the variable as before it (or around it as often is the case in C). In Pascal one writes for example "var x : integer;" and in Haskell one writes "x :: Integer".</p></pre>throwawaybeginr: <pre><p>I guess because I didn't write Pascal or Haskell. I'll take your reply as "totally natural since day 1" for you :)</p></pre>justinisrael: <pre><p>I've been writing production Go for a couple years now, and started coding Go back when it was pre 1.0. I honestly don't care about the types being before or after. It is just the way Go does it vs another language. That being said, if I write a bunch of Go and then have to jump into a C++ project, I will end up writing the type after the name and then get confused for a second when it complains. </p></pre>throwawaybeginr: <pre><p>I'd like to ask you this same thing (copied from another comment):</p>
<blockquote>
<p>can you do me a favor and as you write your next program, tell me the last few syntax errors you make - whatever they are. Even if you leave off a bracket or brace or something.</p>
<p>you can reply at any time. (i.e. if you're not writing anything now.)</p>
</blockquote>
<p>you could take a few days to get back to me. I'm just curious what things still stick with people after a few months. even if it's something mundane like parentheses, etc.</p>
<p>thanks.</p></pre>justinisrael: <pre><p>I can tell you one I make all the time. I always accidentally type :+ instead of := because of poor timing with the key combinations. But other than that, I usually have no problem with syntax. It's such a small spec, there isn't too much for me to mess up.
I switched to C++ and accidentally defined the return type of a function at the end before the braces. </p></pre>lyfaradey: <pre><p>I'm mostly a Java dev at the office but all personal backend projects write in Go. it's kinda weird when I write types in Go-style in Java and than scratching my head trying to understand why it's underlined. :D </p></pre>bobahop: <pre><p>I like its consistency. I think "here is my variable which is a..." and I either infer the type or specify it, so the type is always derived from what comes after it. I've found it harder to not immediately type an open parentheses after "if."</p></pre>Kraigius: <pre><p>Only when I switch language but then I find it more annoying when I start to type without parentheses. :3</p></pre>donglord1337: <pre><p>nope, always been that way for me</p></pre>throwawaybeginr: <pre><p>What are you saying "nope" to, and always been what way to you?</p></pre>donglord1337: <pre><p>if i find it annoying that the type comes after (not before, like C) - it's always been this way for me.</p></pre>throwawaybeginr: <pre><p>thanks.</p></pre>nevyn: <pre><p>Annoying is the wrong word.</p>
<p>Mentally I think of it more like switching between UK/US driving, it takes only a couple of seconds for the thinking part of your brain to accept/know/whatever that the rule is X or Y ... but after years of exposure the non-thinking part of the brain just does things on it's own sometimes and is wrong, so the thinking part of your brain trusts it a little less.</p>
<p>And it's almost never the order of "data string" vs. "string data" but the parsing order of the type "[]string" vs. "string[]" and sometimes the "x, y string" shortcut. This is esp. annoying with the parsing order because I know it's not just different but better the non-C way.</p></pre>throwawaybeginr: <pre><p>thanks for this!</p></pre>adiabatic: <pre><p>It was weird for a while, but the rationale made sense. </p>
<p>I still tend to get tripped up by omitted types in longer function definitions like <code>f(a A, t, u T, z Z)</code>. I'll look at something like that and wonder what the type of <code>t</code> should be. </p></pre>holyjeff: <pre><p>No for me go's way feels more natural.</p></pre>superchalupa: <pre><p>No.</p></pre>PaluMacil: <pre><p>Not even at first (while I do C#, I also do TypeScript which is the same order as Go).</p></pre>BadlyCamouflagedKiwi: <pre><p>Nope.</p>
<p>It annoyed me probably more than anything else about the language at first, but at some point I got used to it and now I find it fine. I'm not sure I like it better overall but that's just taste; it's certainly at least as good if taken in isolation from previous experience.</p></pre>nhooyr: <pre><p>What's with all the down votes on the OP?</p></pre>
after several months do you (still) find it annoying that types come after (not before, like C)?
xuanbao · · 562 次点击这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传