Is it worth learning PHP if you already know Go?

agolangf · · 1034 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>As a web developer do you ever find your PHP skills being useful in some situations, or is it just an obsolete skill if you already know something like Go or Python?</p> <hr/>**评论:**<br/><br/>albgr03: <pre><p>Not really, unless you really have to use it for some reason (professional project, host constraints, ...). Go and Python are good alternatives to PHP. The latter has a lot of mature web frameworks (Flask or Django, for instance).</p></pre>DanChm: <pre><p>Wouldn&#39;t PHP be useful for quick prototyping and such?</p></pre>cs_gopher: <pre><p>No. That would be a waist of time. Unless you need to use php for a professional reason or you just wanna learn it. Otherwise definitely not.</p></pre>cesarliws: <pre><p>I work with Go and PHP, and I find way easier to prototype with go.</p></pre>albgr03: <pre><p>For prototyping yes, because you can insert PHP directly into an HTML page. But you can with Flask too, although you can&#39;t put Python code into HTML, like in PHP.</p></pre>cs_gopher: <pre><p>That is very misleading and wrong. You are assuming someone is using Apache as part of the server stack which is not necessarily the case.</p></pre>titpetric: <pre><p>Actually true, I&#39;m using the stdlib CGI wrapper to invoke PHP scripts in a special case. While it doesn&#39;t apply for a general high-traffic endpoint, it&#39;s very useful where you don&#39;t want to recompile Go API code for small changes. I&#39;m using this as a part of a back-end service which doesn&#39;t get a lot of traffic and had prior code written in PHP.</p> <p><code>http.HandleFunc(&#34;/api/&#34;, phpHandler(&#34;/api.php&#34;))</code></p> <p>And the actual handler:</p> <pre><code>func phpHandler(filename string) func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) { handler := new(cgi.Handler) handler.Dir = &#34;/var/www/deploy/borneo.mmc.lan/bin-cgi/&#34; handler.Path = handler.Dir + &#34;api&#34; args := []string{r.RequestURI} handler.Args = append(handler.Args, args...) fmt.Printf(&#34;%v&#34;, handler.Args) handler.ServeHTTP(w, r) } } </code></pre> <p>Ideally, I would write all the endpoints in Go, however implementing it like this saved a lot of time in terms of refactoring several endpoints which are not trivial, and at the same time avoiding additional dependencies like nginx and php-fpm services &amp; keeps complexity down.</p></pre>albgr03: <pre><p>Maybe I missed something, but PHP is an hypertext preprocessor since its inception. If you can run PHP, you can put PHP code into an HTML file (or anything else). For development, you can use the built-in server. If you use, let&#39;s say, nginx, you will need PHP-FPM.</p></pre>Pardalean: <pre><p>If you can&#39;t see how an interpreted language can lead to faster development, perhaps you shouldn&#39;t be giving programming advice.</p></pre>albgr03: <pre><p>Python is interpreted too.</p></pre>Pardalean: <pre><p>Then he needs go&amp;python, not go||python.</p></pre>albgr03: <pre><p>That&#39;s pretty much what I wanted to say. Sorry if it was not very explicit.</p></pre>a1454a: <pre><p>Familiarity with the tool is the most important factor for anything quick.</p> <p>If you don&#39;t have much experience working in real projects in PHP, the time it takes you to get its runtime and or web server configured, permission issues resolved, composer and directory hierarchy configured, etc would have eliminated anything &#34;quick&#34; a very long time ago.</p> <p>On the other hand if you are very familiar with Go and have many boilerplate starting points that you made from previous projects all ready to go, you could be prototyping in very short amount of time.</p></pre>wwwweeee: <pre><p>Unless you have to work with a legacy codebase i&#39;d say no.</p></pre>comrade-jim: <pre><p>if you&#39;re a masochist </p></pre>bigfoot13442: <pre><p>It really depends on what you plan on doing. It sounds like you are gearing up to find a job (or a new job).<br/> If you work at a consulting firm or an agency, then having a wide array of knowledge can be very useful. In this context you can often switch projects frequently and don&#39;t usually get to choose the language.<br/> If you work at a company that has a web product or service then you are most likely going to be working in one or two languages. This context often allows you time to learn the syntax of a new language. So spending time getting really good at programming and not just knowing a language will be much more beneficial. </p></pre>watermanio: <pre><p>Sure, if you can get a job in PHP and you can&#39;t in go. </p> <p>But technically there is no need, Go can do what PHP does just as well - maybe you&#39;ll gain some performance at the expense of established easy to use frameworks.</p> <p>The only reasons I could think to learn PHP if you know Go are professional - quite a few Go developers started with PHP so there might be some projects with cross over. </p></pre>mwholt: <pre><p>I was a PHP developer for ~8 years, moved to Go, then never looked back. (Been writing Go for 5+ years now.)</p></pre>Pardalean: <pre><p>You might want to x-post this one to <a href="/r/php" rel="nofollow">/r/php</a> too, to get some balanced advise. The answers in this thread are strongly biased.</p></pre>RalphCorderoy: <pre><p>Obligatory <a href="https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/" rel="nofollow">https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/</a></p> <p>The only reason PHP knowledge is useful is debugging PHP, typically from problems caused by the language&#39;s design. You need to tell us why you are asking; in the comments you ask about jobs. And tell us what you already know so we can see where you&#39;d benefit.</p> <pre><code>$ php -r &#39;$a = &#34;&#34;; $a[] = &#34;y&#34;;&#39; $ php -r &#39;$a = &#34;x&#34;; $a[] = &#34;y&#34;;&#39; Fatal error: [] operator not supported for strings in /tmp/php-wrap-jpk45H on line 2 $ </code></pre></pre>DanChm: <pre><p>I&#39;ve been learning Go for the last 3-5 months but I can see that the market for Go developers isn&#39;t too big. Most job sites have something like ~5000 PHP jobs and ~50 Go jobs. So I&#39;m wondering whether learning PHP would be a good idea (mostly thinking about remote back-end jobs). </p></pre>MetalMatze: <pre><p>Let me tell that when you get a Go job, they are most of the time better than the PHP ones. :)</p></pre>a1454a: <pre><p>There&#39;s a lot of PHP jobs because a shit ton of things were already made in PHP. They need people to maintain legacy code. Given PHP was created to be a very simple thing in the beginning but as it matures features were added, concepts borrowed from other languages, the legacy code you will be dealing with is very likely to have lived through all these stages or made by programmers choosing to only use feature from a certain point in its evolution timeline. Working with this kind of massive code base is nightmarish, you most likely won&#39;t enjoy the work.</p></pre>RalphCorderoy: <pre><p>Look for something other than PHP. You probably found Go not too hard to learn, and quite a small language, with a well-designed standard library. With PHP you have to memorise a myriad of exceptions to good orthogonal design to avoid making mistakes, and debug others&#39; code where they haven&#39;t. In addition, there are many large PHP frameworks where you have to fit in with their regimental way of doing things, having learnt what that is.</p> <p>See how many Python jobs there are. The language is smaller and simpler, though slowly getting worse with age. There are libraries to help web applications, and also bigger frameworks. Both tend to be better designed than PHP ones, probably due to the authors having the judgement to choose, or being influenced by, Python.</p></pre>AusIV: <pre><p>What do you want out of a job? </p> <p>If you want to build cool things, PHP isn&#39;t what you&#39;re after. The companies that are building new cool things aren&#39;t doing it with PHP. </p> <p>If you want job security, PHP may be the right choice. There are a lot of legacy systems out there in PHP, often written by people who didn&#39;t really know how to program, and thus require a lot of continuing maintenance. So long as a company doesn&#39;t replace their PHP systems with something else, the jobs will be around for a while. </p></pre>SpiffyJr: <pre><p>Every language has its quirks. The user never deals with the majority of what&#39;s in this blog post. PHP can be a great language of written by experienced developers. Unfortunately, most the jobs out there are maintaining legacy code that&#39;s nasty.</p></pre>RalphCorderoy: <pre><p>PHP doesn&#39;t just have a few quirks. It&#39;s practically nothing but. It&#39;s hard to find an area of the language that isn&#39;t warty. Experienced developers writing in a common subset of PHP aren&#39;t common. Most places that could mandate this happening could also migrate to better languages.</p></pre>black_anarchy: <pre><p>Here to say that things have greatly improved in PHP. With PHP 7 the language itself has come to a more mature state</p></pre>RalphCorderoy: <pre><p>The PHP encountered will be a mixture of all the different PHP versions written by a plethora of passing-by coders using many <em>style du jour</em>. :-) To improve, PHP would have to eradicate all the oddities, edge cases, and brain damage, and wouldn&#39;t be PHP any more.</p></pre>shark1337: <pre><p>No, if you wanna learn an interpreted language, go for node js. I remember when I first started to programming I went on node and had no regrets at all, the community and documentation/support is amazing, really liked it. After a while I switched to golang for a stronger backend. PHP is still used, but you&#39;ll see that the node enviroment is much more awesome ;)</p></pre>DanChm: <pre><p>Are there as many jobs for node developers as PHP developers?</p></pre>asyncrep: <pre><p>I think a better question is &#34;what kinds of jobs are available for PHP developers?&#34;</p> <p>Take a look around :)</p> <p>edit: question, not job</p></pre>mrfrobozz: <pre><p>Without actually doing the searches on job boards, I&#39;d say that node jobs are probably going to surpass PHP jobs if they haven&#39;t already. It seems like it&#39;s the new darling of the IT world. I see new projects at my company using it (Fortune 500 sized), Microsoft is providing pretty good support for it on Azure and in their dev tools (Visual Studio and friends), and new, big companies are constantly announcing popular libraries being available for it.</p> <p>At any rate, it&#39;s gaining tons of mind share among tech companies that matter and it definitely isn&#39;t something to be ignored. It may end up blowing over like Ruby on Rails, but even it does, it will still have a great many uses, including honing your JavaScript skills which is always useful for writing browser-side code on the web.</p></pre>a1454a: <pre><p>Jobs requiring Node has been increasing rapidly in recent years. </p> <p>Node has some pretty attractive qualities in my opinion that made it popular. A wonderful package management system built right in, performance is very nice for such simple language(can be very memory hungry though), familiarity and convenience of a single language for the entire stack, etc. </p> <p>But some of the early pioneer in node like TJ has abandoned node in favor of Go though ;) I don&#39;t think you need to doubt your choice of learning Go.</p></pre>23inhouse: <pre><p>There are lots of jobs in many languages other than PHP.</p></pre>kfirufk: <pre><p>Talking from experience... I moved from php to nodejs to go and I never looked back. If I need something quick I do it in bash

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

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