Can Go do everything that PHP can?

agolangf · · 525 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Let&#39;s say I&#39;m creating a website for a small business client. Am I limited in any way, other than perhaps not being able to use Wordpress and Drupal? </p> <p>Are there any other things I would find missing or hard to accomplish in Go when working on a project?</p> <p>Update: I generally use Wordpress and Drupal together with the LAMP stack to make websites in a relatively short time. I usually work with clients who don&#39;t really care about what technology I use as long as the website works. I&#39;m not too happy with PHP and I&#39;m looking for an alternative. I&#39;m considering Python and Go as possible choices. From what I&#39;ve read on forums it seems like Python has a lot more options available from CMSs to quick prototyping with Django. Knowing very little about Go, I&#39;d love to know if Go can be suitable for tasks like these, am I looking at 5x the effort for virtually no significant gain compared to Python (PyPy) or can websites be developed in Go in similar time frames? I&#39;m ok with doing 2x the work as long as I&#39;m learning a good language in the process.</p> <hr/>**评论:**<br/><br/>mpinteractiv: <pre><p>If you&#39;re ready to start from scratch then yes. If you expect to write something like a complex Django App or a complex Ruby on Rails app then no. </p> <p>I started a Hacker news clone a few month ago, with no framework from scratch : <a href="https://github.com/Mparaiso/gonews" rel="nofollow">https://github.com/Mparaiso/gonews</a></p> <p>That little work took me 3 weeks. It would have taken me 3 days in PHP + framework. But most of the time spent was actually reimplementing from scratch things that can be found in Python,Ruby or PHP packages. So it really depends on the amount of work you&#39;re ready to put in since you&#39;ll have to start from almost nothing.</p></pre>m3wm3wm3wm: <pre><blockquote> <p>But most of the time spent was actually reimplementing from scratch things that can be found in Python,Ruby or PHP packages</p> </blockquote> <p>That&#39;s where I fail to understand why people say all you need is the stdlib.</p></pre>neoasterisk: <pre><blockquote> <p>That&#39;s where I fail to understand why people say all you need is the stdlib.</p> </blockquote> <p>Many people have turned to Go because their working hours have been made miserable by the usage of complex frameworks in other languages while the languages themselves do not help. Go itself was partly created because their creators hated writing C++.</p> <p>Naturally gophers are being very careful when they evaluate external packages in Go. That doesn&#39;t mean that they will not use a 3rd party package that brings real value in the project but it has to first prove that it outweighs the dependency cost.</p> <p>Personally I see this as a very good sign. It&#39;s what keeps Go codebases simple and readable. If we lose that, we might end up with projects that look like Ruby on Rails or Nodejs (in terms of number of dependencies).</p></pre>DanChm: <pre><p>That&#39;s really insightful. Do you think that If you had to create a similar project again you would be much faster than 3 weeks? Or would it still be a lot of extra work?</p></pre>mpinteractiv: <pre><p>You need to figure out what 3rd party lib you can leverage .</p> <p>Gorilla toolkit can help for a few stuffs ( sessions, forms, ... )</p> <p><a href="http://www.gorillatoolkit.org/" rel="nofollow">http://www.gorillatoolkit.org/</a></p> <p>Be sure to use check this namespace, a lot of useful stuff like bcrypt for password hashing, ect ...</p> <p><a href="https://godoc.org/?q=golang.org" rel="nofollow">https://godoc.org/?q=golang.org</a></p> <p>You can leverage libraries from other languages like PHP (doctrine, symfony, laravel ,...) in order to figure out how to write some stuff. But porting takes time.</p> <p>in general , PHP libs translate well in Go code since both lack of generics (unlike Java) and don&#39;t rely too heavily on meta programming like Ruby or Python.</p> <p>And do your thing. What suits somebody else, even Rob Pike, might not suit your own requirements. Don&#39;t be afraid to opt out the type system if needed otherwise you&#39;ll write a lot of boilerplate. As long as it doesn&#39;t panic and you understand the performance cost, that&#39;s ok.</p></pre>weberc2: <pre><p>Can you elaborate on what you found to be missing? This is a genuine question, not a challenge.</p></pre>scheldkultur: <pre><p>They&#39;re both turing complete ...</p></pre>DanChm: <pre><p>As I clarified in the comments I was mostly referring to available tools and frameworks not the languages themselves.</p></pre>DanChm: <pre><p>Seems like people are not liking the title of the post. The question was more to do with available tools and frameworks rather than the languages themselves.</p></pre>letsencrypt: <pre><blockquote> <p>Seems like people are not liking the title of the post</p> </blockquote> <p>It is because your post <em>(including your comment)</em> is too vague to give a proper answer. What tools do you use when you program in PHP? What framework features do you use the most? Without knowing your specific needs it is hard to say more than <em>&#34;Yes, you can use Go to do everything you do in PHP&#34;</em>, it has a good list of built-in packages including one for testing, one for I/O, one for HTTP, among many others. The tooling, in general, is very good</p></pre>DanChm: <pre><p>Thanks, checkout the updated question for more info.</p></pre>Redundancy_: <pre><p>It&#39;s a wide open question that&#39;s very difficult to answer without more information: There are web frameworks, there is HTML templating, REST APIs are done frequently, there are database drivers and redis support etc.</p> <p>What do you need?</p></pre>DanChm: <pre><p>I updated the question.</p></pre>Remi1115: <pre><blockquote> <p>Are there any other things I would find missing or hard to accomplish in Go when working on a project?</p> </blockquote> <p>This question is a bit hard to answer and will most likely result in opinions rather than plain facts, I&#39;m afraid.</p> <p>One fact I can tell you is that Go hasn&#39;t got such a framework culture as PHP has. Gophers tend to like to use smaller libraries, which they choose themselves. That might be limiting if you&#39;re new to the language. I&#39;d say it also depends on how much time you are willing to put into the client and how much time the client would like to give you.</p> <p>I hope this helps a bit.</p></pre>mgutz: <pre><p>You will be more productive with Django based on your description. I don&#39;t know of any widely used Go CMS. Beego might be an option in Go. But, I still believe Django, Rails is the right tool for web based applications when you want an admin and just want to get stuff done.</p> <p>We use Go exclusively on the back end for our APIs. Our application front end is React. We use Wordpress for static content so business folks can update that whenever they want without depending on devs.</p></pre>pinpinbo: <pre><p>Where there&#39;s a will, there&#39;s a way.</p> <ul> <li><p>Hosting: You cannot use shared hosting, so you need to pay VMs or container or something along that lines.</p></li> <li><p>You will be building a lot of CMS features yourself. Are you cool with that? Stdlib can solve all your problems if you build yourself.</p></li> <li><p>Come to think of it, this is just websites for random people right? With little interactivity? If so, just use Hugo, man. And host the static files somewhere cheap like AWS S3.</p></li> </ul></pre>DanChm: <pre><p>Great info. Yep, it&#39;s mostly static sites with content and occasionally some eCommerce. Also, could you elaborate a bit on the hosting? Why wouldn&#39;t I be able to use shared hosting?</p></pre>Yojihito: <pre><p>Because you need to execute the Go binary as root for Port 80. Most shared hosting services offer you LAMP/Python stacks preinstalled where you just upload your files. That&#39;s not possible with Go.</p> <p>But it depends on the hoster.</p></pre>pinpinbo: <pre><p>Shared hosting uses common infrastructure that you don&#39;t control. That common thing is usually a managed Apache with GUI for loading modules such as PHP.</p> <p>When running Go, you are running your own web server + your own app logic embedded inside that web server.</p></pre>DanChm: <pre><p>After some research I came across these hosting solutions:</p> <ul> <li>Google App Engine</li> <li>Heroku</li> <li>Any hosting company with VPS hosting or dedicated server</li> <li>Personal server (hardware) </li> </ul></pre>ultra_brite: <pre><blockquote> <p>Hosting: You cannot use shared hosting, so you need to pay VMs or container or something along that lines.</p> </blockquote> <p>Actually Go has full support for CGI. and most shared hosting providers allow CGI. In fact I already deployed a Go app as a CGI binary on an apache server for a small business. It works without any problem as the load is ridiculously low ( 200 users ).</p> <p>So it&#39;s completely possible to deploy a Go app on shared hosting.</p></pre>shovelpost: <pre><p>If you are building mostly static websites, then you could even use <a href="https://gohugo.io/" rel="nofollow">Hugo</a>.</p> <p>If you need eCommerce specifically then you&#39;ll probably need something less static.</p></pre>Morgahl: <pre><p>I&#39;ve been playing around with <a href="https://fragmenta.eu/" rel="nofollow">https://fragmenta.eu/</a> a little bit and enjoyed what I&#39;ve seen so far. I&#39;m not much of a front end guy so take my opinion with some salt but happy with what I&#39;ve seen sofar.</p> <p>edit: typos. everywhere....</p></pre>DanChm: <pre><p>I haven&#39;t heard much about fragmenta, what does it allow you to do exactly?</p></pre>DanChm: <pre><p>Never mind, I just read the homepage seems interesting.</p></pre>polypus74: <pre><p>If you are doing CMS type work, for the moment, stick with php/python/ruby. If you want a truly static site you might look at <a href="https://gohugo.io/" rel="nofollow">Hugo</a> (a go project). If you are doing anything else, you might evaluate go as a possible implementation language. </p> <p>I am working on a web based multiplayer game and it fits the bill perfectly. In my case I chose it because: It&#39;s a great server language with good concurrency support. It is more mature than some other very tempting choices which I actually prefer as languages (Rust/Pony). It has static typing and small fast little binaries which makes the deployment story very nice.</p> <p>My advice is, start learning it in your spare time. It is small and easy to learn and at some point you will surely have a use for it, especially given the tech agnosticism of your clients.</p></pre>

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

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