From bash / perl to golang?

agolangf · · 602 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;ve used Linux for the past 20 years.. normally do everything in bash scripts.. can read through a Perl script to adjust or fix things.. same with python, but the indentations get me mixed up.</p> <p>It seems lately that you need to learn to code to get promoted etc lately at my job.</p> <p>We do a lot of go coding at work. Do you think I should get more into python.. then switch over to go.. or jump into go straight from bash?</p> <p>Any popular tutorial sites? I&#39;ve seen a few.</p> <p>Thanks</p> <hr/>**评论:**<br/><br/>jot1109: <pre><p>Devops here. Used to do shell, perl, and python as scripting languages in the past. Did not cut it for me once the scripts got longer than one page. VERY happy with Go, wiped everything else off the table.</p> <p>Compared to Perl, you need to type more. I do type fast, so no worries. Error handling needed some patience from my side.</p> <p>You probably have to get used to the compile cycle though. I just open up two terminal windows, one &#39;vim&#39; and one &#39;watch go run main.go&#39;. Nice. The mindblowing difference is when you rollout the script on more than one server: one single binary without any external dependencies. No more CPAN, Python2 &lt;-&gt; Python3 libs, pip, rpm -dev packages. Copy one file - done.</p> <p>Most of my tasks are some sort of glue code, usually performance is not much of an issue. For 10% it is, and Go feels significantly faster to me than scripting languages: <a href="https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/go-python3.html" rel="nofollow">https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/go-python3.html</a>.</p> <p>JSON, XML, REST? Email? Email templates? tar, zip, gzip, bzip2? SHA 1-512? base64? csv? gif, jpg, png? check. All included in the standard library. Get vim, get vim-go, get go, Go!. My wild guess is that Go and containers will experience the same long-lasting symbiosis as C and Unix, so you are well prepared for the next 20 years.</p> <p>One last thing: if you like Linux/Unix, you might like one of the creators of Go. Even github respectfully reserved his anticipated user ID just in case (<a href="https://github.com/ken" rel="nofollow">https://github.com/ken</a>). </p></pre>thatarchguy: <pre><p>Coming from python I&#39;ve noticed it&#39;s much more work to do scripting. Please let me know otherwise though, I want to use Go! </p> <p>My recent task was to parse a rather large json response from a webserver and use the presence of a key to decide to kick off another process. </p> <p>Usually in python, I&#39;d: - pop open an interpreter - import requests - requests.get(url), json.loads() into dictionary - if data.get(&#39;item&#39;): do_this()</p> <p>It&#39;s easy since I can play around in the interpreter and play with the response json before putting this all into a script to use. </p> <p>But for go, I quickly realized I was in over my head. I had to create a struct of the json response. It had a lot of keys, and thankfully I found a webservice that converted json to go structs for me. From there it wasn&#39;t so bad. <code>json.Unmarshal()</code>is similar to <code>json.loads()</code>. But if that json to struct service didn&#39;t exist I would have given up on the spot and popped open a python file. </p> <p>I did later find out I could have used <code>map[string]interface{}</code> for the json unmarshall which makes things much easier. But it&#39;s still been massive trial and error for my other ETL scripts. Maybe I&#39;m just used to opening an interpreter with dynamically typed Python and copying it into a script when I have it right. Maybe I&#39;ve just been in python land too long. I just haven&#39;t found go as easy to use for scripting as I keep reading about. </p></pre>BrokenPhoneBooth: <pre><p>What type of application development would get you promoted? Just start doing it and demonstrate that you are not only capable, but already doing the work. </p> <p>If you are doing bash and perl I would imagine you are a sysadmin? I would say python and Ruby may be more what you need to learn but obviously any development experience will synergize.</p></pre>rbetts: <pre><p>Great answer. </p> <p>Go and (sane) Perl have some similarities (heavy use of builtin slices/arrays and maps/dicts) and curly-brace syntax. If you can read and write basic Perl, learning go should be pretty straight forward. </p> <p>But as mentioned above - there might be better reasons to learn python?</p></pre>expatMT: <pre><p>20+ years of Linux skills here too. Done Bash, Perl, PHP, and got into Go about three years ago. All are excellent tools for the job required and how happy you are to use for a particular task.</p> <p>That being said, I really enjoy working with Go far more than other languages, and management teams are becoming very interested in using Go more and more.</p> <p>Get into it. It&#39;s an excellent tool.</p></pre>arp242: <pre><p><a href="https://arp242.net/weblog/learning-a-programming-language.html" rel="nofollow">https://arp242.net/weblog/learning-a-programming-language.html</a></p> <p>In the specific case of Go, <a href="https://www.amazon.com/Programming-Language-Addison-Wesley-Professional-Computing/dp/0134190440" rel="nofollow">The Go Programming Language</a> is the best book that I know of. It does assume some programming knowledge though.</p> <p>As for Go vs. Python vs. Perl, I agree with the commenters that it would depend a lot on what you&#39;re hoping to do with it.</p></pre>hagge: <pre><p>Do Go directly if your company already is doing Go. Go works as a tooling language for DevOps/Sysadmin type work too so might as well jump over Python.</p></pre>s0merandomletters: <pre><p><a href="http://exercism.io/languages/go/about" rel="nofollow">http://exercism.io/languages/go/about</a></p></pre>Magnus919: <pre><p>Get straight into Go. With Python, you&#39;re going to have to get your head around Object Oriented Programming, which has a little bit of a learning curve coming from shell scripting. With Go, you&#39;re going from one functional language (bash) to a more sophisticated one (Go). If you were advanced in your use of bash scripting, I think Go is not going to be a cognitively steep hill to climb.</p></pre>chillysurfer: <pre><p>I love Go. It&#39;s a great tool. But if your primary job development is focused around bash scripts and automation, Python is most likely a natural next step. I haven&#39;t ever written a bash script and thought &#34;I should&#39;ve written this in Go&#34;.</p> <blockquote> <p>We do a lot of coding at work</p> </blockquote> <p>What kind of programming? Automation? Infrastructure tooling? We really can&#39;t answer the question of Python vs Go without knowing this.</p></pre>earthboundkid: <pre><p>Why Not Both Meme.gif </p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

602 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传