Thinking of migrating python API(s) to go..

xuanbao · · 534 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>So I am aware I am probably going to get a few biased opinions here, but I&#39;m asking around a few places because I can&#39;t quite make my mind up...</p> <p>So long story short, I am a team of one developer. I maintain 3 large Web projects for one company, basically a large CRM platform, a delivery planning Web based program and a b2b order platform. Each of these projects is around 5 years old, until last year all of these projects were written entirely in python, e.g they used a python templating language, as well as some backend pyramid code to handle authentication and other tasks such as view management etc. Anyway, last year I migrated all three to use a javascript front end (typescript with Angular), this was my first time writing any javascript code and I actually really enjoyed writing a statically typed language, and it&#39;s probably made my python code a lot cleaner.</p> <p>So now I have 3 code bases which are written in python that are simply API&#39;s, performing SQL requests and generating the odd PDF (yes I could do this in javascript) , but matplotlib and reportlab in python are great libraries and I have a few complex reports these currently manage to there as of yet hasn&#39;t been a need to migrate this code into javascript.</p> <p>Now being a team of one, I always try to stay on top of best code practices, reviewing my code and making sure it does not get left behind etc.</p> <p>I have been toying with the idea of migrating my backend code into Go for some time, but keep finding myself back at the same point asking &#39;will I actually see any benefits?&#39; I mean I don&#39;t see python support getting dropped anytime soon, but all of the articles I see seem to publish things like &#39;why we moved to Go and you should to&#39;. Is the Web trending to do more stuff with Go, or are these articles the same as the &#39;why we ditched postgres and do everything with Mongo...&#39; because if its the later, we all have probably read the &#39;what we learned from Mongo and why we are back with postgres&#39;.</p> <p>For me python does everything I need it to, I know python is super popular at the moment with machine learning etc, but for the sake of future proofing the code, would migrating to Go be a sensible idea? What draws me to Go is the fact that I could write everything in Vanilla Go (pretty much) and then just ship compiled binaries to my servers, some of my production code is close to 6 years old and could probably be a lot better than it is, a rewrite would definitely help fix most of this. When I look at the dependencies of my python projects, they are rather large and I worry about some package eventually holding me back, E.g reportlab.</p> <p>It&#39;s nothing that needs doing and other than a bit of speed performance (which if I am honest, my code won&#39;t really benefit from as it doesn&#39;t need to be blazingly fast, python isn&#39;t actually restricting me in this respect), but I&#39;m always curious what the rest of the Web industry is up to (excluding the likes of those featured on hacker news, E.g funded startups doing cool things) so for the rest of us solving actual business problems and paying customers needs/requirements , how are you finding Go for Web (api) development? Has anyone else been in a similar position, what did you do and why? If anyone has any comments I&#39;d also welcome those. </p> <hr/>**评论:**<br/><br/>rodbzro: <pre><p>There is no best-at-everything programming language, Go sure have its limitations too.</p> <p>I recommend you to create little projects to learn Go and get used to it before thinking about full rewrites.</p> <p>Also keep in mind that you can easily create a multi-language backend with grpc. The learning curve is steep, but it pay off a lot in the long run. </p></pre>gxti: <pre><p>There are a couple things Go does better than Python for basic rest API stuff and you touched on the obvious ones (speed and ease of deployment). But with a known-working codebase it doesn&#39;t sound like you really have a whole lot of reason to move. Anytime you rewrite a mature project you are taking on a significant risk -- there <em>will</em> be bugs -- so you should only do it with a clear objective in mind.</p> <blockquote> <p>When I look at the dependencies of my python projects, they are rather large and I worry about some package eventually holding me back, E.g reportlab.</p> </blockquote> <p>This is going to be a problem no matter what language you use. Both Go and Python have good tools for expressing dependencies on particular versions of things, and that can help you stay in place when you don&#39;t want a surprise upgrade, but it doesn&#39;t help you move forward when your dependencies no longer work together.</p> <p>I&#39;m not saying don&#39;t do it, just understand why you&#39;re doing it and whether the risk is worth it. Even if the reason is &#34;because I want to learn how to do it&#34; or &#34;because it&#39;ll be fun&#34;.</p> <p>For comparison, a project I recently rewrote had a large number of problems including:</p> <ul> <li>Bad performance</li> <li>Lots of copy-pasted code</li> <li>Difficult to prove that it was secure</li> <li>Business logic smeared all over the place</li> <li>Poor management of database connections</li> <li>Written in PHP</li> <li>Slightly different code in dev/test/prod and no source control (... yeah)</li> </ul> <p>So as you can see, that rewrite was a serious win.</p></pre>SimplySerenity: <pre><p>I don&#39;t understand. What are you future proofing against? You&#39;re the only one working with the code, and it seems all your needs are met?</p> <p>I will say that it&#39;s unlikely that you&#39;ll want to do it all in vanilla Go. It&#39;s just too easy to use an API framework. </p> <p>There are parts of Go that make writing an API in Go nice. Like how easy it is to make types that you can directly pull from SQL queries with sqlx. Then Marshal that same type into JSON.</p> <p>I will say that I don&#39;t think Go lends itself to easy web dev nearly as much as Python though. Probably because you&#39;re trading some abstraction and higher level language features for speed and simplicity.</p></pre>pobbly: <pre><p>I&#39;m a go dev but wouldn&#39;t do a rewrite if I were you. It sounds like your python setup does everything you need. Try go on some other project. Check out gin.</p></pre>BrokenPhoneBooth: <pre><p>Don&#39;t do a rewrite</p></pre>mackstann: <pre><p>It sounds like everything is more or less fine, and you&#39;re considering rewriting everything? Have you ever gone through a rewrite of an entire project? It&#39;s usually a terrible idea. It&#39;s a massive and risky undertaking. You and your successor(s) will be mired in it for <em>years</em>. It will fix some problems, but also cause many problems you never had before. You should have a very strong argument for why it makes more sense than keeping what you have, and even then it is still highly questionable. It kind of sounds like you&#39;re bored and trying to find excuses to change things up.</p> <p>Oldie but a goodie: <a href="https://www.joelonsoftware.com/2000/04/06/things-you-should-never-do-part-i/" rel="nofollow">https://www.joelonsoftware.com/2000/04/06/things-you-should-never-do-part-i/</a></p></pre>daveddev: <pre><blockquote> <p>It&#39;s nothing that needs doing</p> </blockquote> <h2></h2> <blockquote> <p>... future proofing the code ... write everything in Vanilla Go; the dependencies of my python projects, they are rather large ... just ship compiled binaries to my servers ... a rewrite would definitely help...</p> </blockquote> <p>Seems like you understand your situation. If you proceed with a rewrite, Go would be a great option (if the special behavior you require is available in libraries). Also consider replacing specific endpoints or groups of endpoints to ease into the Go world.</p> <p>Since it is normally common for ORMs to be leveraged in Python (not that it is forbidden in Go), you might want to consider using code generation to speed up development. If that is still too foreign for you, there are ORMs and ORM-like tools available.</p></pre>Damien0: <pre><p>Like with a lot of things... it depends. Go is very good for APIs, especially those where concurrency and performance are important criteria. Since it sounds like you have a simple CRUD style app, you should carefully weigh your development effort -especially if you are new to Go- to see if it is worth your time. You will probably see a performance improvement coming from Python.</p> <p>Go shines when what you are building plays into its strong suites: distributed, concurrent, performant systems that need to be easy to deploy, potentially in many environments. You should also be interested in the benefits a relatively strict type system provides. If you&#39;re expecting the breeze of dynamism e.g. Ruby/Python/ES6 you might be annoyed with how much boilerplate you have to write (I enjoy the tradeoff, but YMMV).</p> <p>I&#39;d be happy to chat with you more about my own experience of Go compared to other API systems I&#39;ve worked with in Python, Java and C#. It&#39;s fun stuff.</p></pre>

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

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