golang go语言

I’ve been programming using PHP professionally since 10 years now. After my Computer Engineering degree, all I knew was that Java was not my piece of cake any more (after 6+ years using it for personal and academic projects), I wanted a much simpler stack and I figured out that a quick way to market myself as an independent developer was getting into the rising PHP CMS market.

从10年以来,我一直在专业地使用PHP进行编程。 在获得计算机工程学位之后,我所知道的就是Java不再是我的小菜了(在个人和学术项目中使用Java超过6年之后),我想要一个简单的堆栈,并且发现了一种快速的市场营销方式我自己作为独立开发人员正在进入上升PHP CMS市场。

Over the years PHP has changed a lot and while many people like to bash or criticize it, many do it based on very old and very little experience. Modern PHP, especially if you have the luxury to use PHP 7 types and leave behind PHP 5.x, is very nice to work with, and of course PHP has the advantage of being, for some reason, the language that you can deploy nearly everywhere, which is why many CMS are built in PHP, and why they are so successful because they are PHP-based (Grav included).

多年来,PHP发生了很大变化,尽管许多人喜欢抨击或批评它,但许多人是基于非常古老且很少的经验来进行此操作的。 现代PHP(特别是如果您愿意使用PHP 7类型并抛弃PHP 5.x)非常好用,当然,由于某些原因,PHP的优势是几乎可以部署该语言到处都是,这就是为什么许多CMS用PHP内置的原因,以及为什么如此成功是因为它们基于PHP(包括Grav )。

Of course PHP is just one tool, and recently I’ve been delving into Go head first.

当然,PHP只是一个工具,最近我一直在深入研究Go。

Compared to PHP, Go is a completely different language and environment.

与PHP相比,Go是一种完全不同的语言和环境。

This is not a rant or an article aimed at moving you away from PHP, but rather to introduce you, PHP developer, at why Go is a good language to learn as a complementary tool.

这不是旨在使您脱离PHP的喧嚣或文章,而是向您介绍PHP开发人员,为什么Go是一种作为辅助工具而学习的好语言。

首先,什么是Go? (First things first: what is Go?)

Go is an imperative, object-oriented programming language designed at Google 10 years ago.

Go是10年前由Google设计的命令式,面向对象的编程语言。

The combined knowledge of the founding members, and the original philosophy in creating the best language for the needs they had, led to Go.

创始成员的综合知识以及为满足他们的需求创建最佳语言的原始哲学促成了Go。

Go is a compiled language, statically typed, with garbage collection and concurrent programming features built-in.

Go是一种静态类型的编译语言,具有内置的垃圾回收和并发编程功能。

没什么新鲜的 (It’s nothing new)

The way Go goes about innovating is quite interesting. It completely ignores the hype about what supposed new features a modern language should have, and what other programming languages provide, but instead cherry-pick core concept from battle-tested languages, aggregating decades of programming experience into a beautiful tool to use.

Go进行创新的方式非常有趣。 它完全忽略了关于现代语言应该具有的新功能以及其他编程语言所提供的功能的炒作,而是取而代之的是从久经考验的语言中挑剔的核心概念,将数十年的编程经验汇总为一个漂亮的工具来使用。

The task of the programming language designer is consolidation not innovation – Hoare, 1973

编程语言设计师的任务是巩固而不是创新– Hoare,1973年

Go has many unique features, of course, it’s not just a mashup language. Go introduced goroutines, which are an amazing way to handle concurrency. Go introduced defer, a great way to execute something when the outer function returns (now added into Swift, as well).

Go具有许多独特的功能,当然,它不仅仅是一种混搭语言。 Go引入了goroutines ,这是处理并发的一种了不起的方法。 Go引入了defer ,这是在外部函数返回时执行操作的好方法(现在也添加到Swift中)。

Go was the first language to introduce a formatter in the standard tools. And the ability to compile for other platforms without friction, plus many more “new” things.

Go是在标准工具中引入格式化程序的第一语言。 并能够在没有摩擦的情况下为其他平台进行编译的能力,以及更多“新”事物。

Go has strong roots. A beautiful presentation at GopherCon 2015 by Robert Griesemer illustrates it: Go merges many principles of both C and Oberon-2, which is a language coming from the Pascal family. Both these languages originate from Algol 60, which was introduced in 1960.

Go扎根。 Robert Griesemer在GopherCon 2015上的一次精彩演讲演示了这一点:Go融合了C语言和Oberon-2的许多原理,这是一种来自Pascal家族的语言。 这两种语言都起源于1960年推出的Algol 60。

So the next time someone ask why Go looks like a language from 20 years ago, you can just as well answer that it actually has over 60 years of experience under its belt. As Robert Griesemer once said, it takes 10 years for a programming language to become mainstream.

因此,下次有人问为什么Go看起来像20年前的语言时 ,您也可以回答,它实际上已有60多年的经验。 正如罗伯特·格里斯麦默(Robert Griesemer)所说,一种编程语言成为主流需要10年。

Go is just getting started, which is pretty exciting thinking about its future and what people can build with it!

Go才刚刚起步,这对它的未来以及人们可以用它构建什么感到非常激动!

Go是PHP的补充 (Go is complementary to PHP)

If you ever used Ruby or Python in addition to PHP, you might have realized that they more or less boil down to a different version of PHP, if you remove fanboyism and personal preferences from the equation, as all are interpreted, loosely typed languages.

如果您除了PHP之外还使用Ruby或Python,您可能已经意识到,如果您从等式中删除了狂热主义和个人喜好,因为它们都是解释性的,松散类型的语言,那么它们或多或少可以归结为PHP的不同版本。

One could switch to Ruby to PHP and Python and do the same things. The only “web language” that differs quite substantially is JavaScript, which is different because of the non-blocking model (but that’s been migrated to other languages, including PHP as well through libraries) and because it’s the only language currently running natively in the browser, which gives it an enourmous advantage. Also, it’s a much more wild ecosystem of uncontrolled executing environments, all different in possibly subtle ways.

可以将Ruby转换为PHP和Python,然后做同样的事情。 唯一有很大不同的“网络语言”是JavaScript ,这是由于非阻塞模型(但已通过库迁移到其他语言,包括PHP和非阻塞模型)而不同,并且它是当前唯一在本地运行的语言。浏览器,这给它带来了巨大的优势。 而且,它是一个不受控制的执行环境,更加狂野的生态系统,所有这些都可能以微妙的方式有所不同。

Go on the other hand is a completely different beast. It’s a system language, like C. And unlike dynamic languages, Go is fast.

另一方面,这是完全不同的野兽。 它是一种系统语言,例如C。与动态语言不同,Go的运行速度很快。

PHP is built in C, and you can write and run PHP C extensions, so the concept of a system language should not be that alien to you.

PHP是建立在C,您可以编写和运行PHP Ç扩展,这样的系统语言的概念不应该外星人给你。

Go is capable of replacing your web stack, and there are web frameworks available for that, making it easy, but PHP still has its place, especially when prototyping and you still don’t know what part of your code will need heavy optimization, and if your code will be really used after all.

Go能够替换您的Web堆栈,并且可以使用它来简化Web框架,但是PHP仍然占有一席之地,特别是在进行原型设计时,您仍然不知道代码的哪一部分需要大量优化,并且毕竟您的代码是否真的会被使用。

So, when should you use Go? When you’re using PHP but PHP is not really the best tool for the job. If PHP is consuming too much memory or resources for a particular piece of functionality, and a highly optimized Go program will perform much better. Simple as that. PHP 7 has been amazing at improving the PHP performance. That was a free gift. But when you need to process millions of database entries, or fetch Gigabytes of data from an API with a long running process, PHP might not be the right tool.

那么,什么时候应该使用Go? 当您使用PHP时,PHP并不是真正的最佳工具。 如果PHP为某个特定功能消耗了过多的内存或资源,那么高度优化的Go程序的性能会更好。 就那么简单。 PHP 7在改善PHP性能方面令人赞叹。 那是免费的礼物。 但是,当您需要处理数百万个数据库条目,或者需要长时间运行从API获取千兆字节的数据时,PHP可能不是正确的工具。

I’ve relied on Node.js for quite a few years to solve this problem, but as I got to know Go, so far anything that I come up with Go is a far simpler and better solution.

我已经依靠Node.js解决了这个问题很多年了,但是据我所知,Go到目前为止,我提出的任何东西都是一个更简单,更好的解决方案。

And it does not stop there, of course. With Go you build cross-platform, concurrent applications in a breeze, and this is very different from PHP web development, way more challenging, but also — personally speaking — more interesting, and it could open up for you many rewarding jobs.

当然,它并不止于此。 使用Go,您可以轻松地构建跨平台的并发应用程序,这与PHP Web开发非常不同,这更具挑战性,但就个人而言,也更有趣,它可以为您带来许多有意义的工作。

So, as a PHP developer you could start handing off demanding tasks to Go, while becoming skilled at it will surely enrich your career choices.

因此,作为PHP开发人员,您可以开始将艰巨的任务交给Go,同时熟练掌握它肯定会丰富您的职业选择。

为什么不使用C C ++或Java? (Why Go and not C C++ or Java?)

Any language has its place. Surely Go can’t beat C and C++ performances. There are many benchmarks you can find.

任何语言都有它的位置。 当然,Go不能击败C和C ++性能。 您可以找到许多基准。

Go sits in the middle between those 2 mainstream and historic languages and dynamic languages: you want more performance than what you can get from an interpreted language, but you’re not ready or not willing to use C or C++, which are faster but they are too low level, and you’d need to manually manage memory, and it would take way more time to develop. Go fits that place.

Go介于这两种主流语言和历史性语言以及动态语言之间:您想要的性能要比解释语言所能提供的更多,但是您还不准备或不愿意使用C或C ++,它们虽然更快,但它们级别太低,您需要手动管理内存,这将花费更多的时间来开发。 去适合那个地方。

For a heavily optimized piece of code — C or C++ might be a better solution, if you’re highly proficient with them. I could say the same for Assembly.

对于经过高度优化的代码,如果您精通C或C ++,则可能是更好的解决方案。 我可以对大会说同样的话。

In comparison to Java, it’s a completely different situation. Java requires a lot of overhead in terms of environment, while Go programs are a single file, light, portable and native.

与Java相比,情况完全不同。 Java在环境方面需要大量开销,而Go程序是单个文件,轻巧,可移植且本地。

And we’re probably comparing apples to oranges, you’d never use Go where you use Java, and the opposite stands true.

而且我们可能正在将苹果与橘子进行比较,您永远不会在使用Java的地方使用Go,而事实恰恰相反。

心动简单 (Go is simple at heart)

(And remember: simple does not mean easy) Avoiding feature creep was clearly one of the goals of the designers of Go. Legendary Ken Thompson, one of the 3 original designers of Go, also creator of UNIX and the B language (among many other things), once said

(并且要记住:简单并不意味着容易)避免功能蠕变显然是Go设计师的目标之一。 传奇人物肯·汤普森(Ken Thompson)是Go的三位原创设计师之一,也是UNIX和B语言的创造者(还有许多其他事情),他曾经说过

When the three of us [Thompson, Rob Pike, and Robert Griesemer] got started, it was pure research. The three of us got together and decided that we hated C++. [laughter] … [Returning to Go,] we started off with the idea that all three of us had to be talked into every feature in the language, so there was no extraneous garbage put into the language for any reason.

当我们三个人(汤普森,罗伯·派克和罗伯特·格里瑟姆尔)开始时,这纯粹是研究。 我们三个在一起,决定讨厌C ++。 [笑声]……[回到Go],我们从一个想法开始,即我们三个人都必须与该语言的每个功能进行对话,因此,不会由于任何原因在该语言中添加多余的垃圾。

This resulted in a language that is amazingly simple for any experienced developer that’s been coding in any language.

对于任何使用任何语言进行编码的经验丰富的开发人员来说,这都使得该语言非常简单。

Java, C++, C, C#, Erlang, JavaScript, Swift, almost all modern programming languages are way more complex than Go.

Java,C ++,C,C#,Erlang,JavaScript,Swift,几乎所有现代编程语言都比Go更复杂。

And here I mean complex to use for the programmer, complex to read, complex to become a master. Inside, Go hides all the complexity and exposes a simple API. Not only Go has garbage collection, but there is no exposed memory management functionality at all.

在这里,我的意思是供程序员使用的复合体,易于阅读的复合体,成为熟练的复合体。 在内部,Go隐藏了所有复杂性并公开了一个简单的API。 Go不仅具有垃圾回收功能,而且根本没有公开的内存管理功能。

Just think that PHP has 67 keywords, while Go has 25.

试想一下,PHP有67个关键字,而Go有25个关键字。

The key point here is our programmers are Googlers, they’re not researchers. They’re typically, fairly young, fresh out of school, probably learned Java, maybe learned C or C++, probably learned Python. They’re not capable of understanding a brilliant language but we want to use them to build good software. So, the language that we give them has to be easy for them to understand and easy to adopt. — Rob Pike

关键是我们的程序员是Google员工,而不是研究人员。 他们通常相当年轻,刚从学校毕业,可能学习过Java,也许学习过C或C ++,可能学习过Python。 他们无法理解出色的语言,但我们希望使用它们来构建优秀的软件。 因此,我们为他们提供的语言必须易于理解和采用。 —罗伯·派克

This is core to the Go philosophy, and explains why Go choses to avoid implementing features (avoiding feature creep), and why many concepts of functional programming are left out, as they are complex to reason about, opening debates. Pure functional programming is too much away from the machine concepts to be relevant to Go, which is an imperative language at heart.

这是Go语言哲学的核心,并解释了为什么Go选择避免实现功能(避免特征爬升),以及为什么函数编程的许多概念由于推理复杂而被遗漏了。 纯粹的函数式编程与机器概念相距太远,无法与Go相关,后者是一种核心命令语言。

That said, Go has many concepts of functional programming implemented, like first-class functions (allowing functions to be assigned to variables), closures, recursion.

也就是说,Go具有许多实现的函数式编程概念,例如一流的函数(允许将函数分配给变量),闭包,递归。

But compared to PHP or JS, you don’t have functional operations like map, reduce or filter, you must rely on loops. Why? Because those operations are inefficient, and Go must find a balance.

但是与PHP或JS相比,您没有诸如map,reduce或filter之类的功能性操作,必须依靠循环。 为什么? 因为这些操作效率低下,所以Go必须找到一个平衡点。

Speaking of things missing, there are no exceptions to handle errors. There are no classes (even though it’s object-oriented, with structs with associated methods, forcing composition over inheritance — if you have knowledge of JavaScript’s prototype object implementation, this will be familiar, but very different), no generics (although PHP does not have them too), and here is why.

说到缺少的东西,没有例外可以处理错误。 没有类(即使它是面向对象的,具有带有关联方法的结构,也可以在继承上强加组成 -如果您了解JavaScript的原型对象实现,这将是熟悉的,但有很大的不同),没有泛型(尽管PHP没有)也有), 这就是原因 。

Less is more, or (even better!) less is exponentially more.

少即是多 ,或者(甚至更好!) 少即是指数级的多 。

The “secret” to good software design wasn’t in knowing what to put into the code; it was in knowing what to leave OUT! It was in recognizing where the hard-spots and soft-spots were, and knowing where to leave space/room rather than trying to cram in more design

好的软件设计的“秘密”不是在知道要在代码中添加什么。 那是在知道剩下什么! 这是在识别硬点和软点在哪里,并且知道在哪里留出空间/房间,而不是试图在更多设计中塞满东西。

There’s just one way to write a loop: for. Forget while and do — while and foreach (something more?).

只有一种编写循环的方法: for 。 忘记whiledo — whileforeach (更多的东西?)。

[…] what makes Go successful is what has been left out of the language, just as much as what has been included.

[…]使Go取得成功的原因是该语言所遗漏的内容,与所包含的内容一样多。

The ability to return multiple values from a function avoids lot of tricks (the simplest example is returning an array containing 2 values, and having to extract them without knowing the exact type passed).

从函数返回多个值的能力避免了很多麻烦(最简单的示例是返回包含2个值的数组,并且必须在不知道传递的确切类型的情况下提取它们)。

Simplicity is inherited by the tooling. gofix automatically fixes breaking API changes in new Go releases.

工具继承了简单性。 gofix自动修复新版Go中API的重大更改 。

And Go is simple by design, and will always stay simple.

Go在设计上很简单,并且将始终保持简单。

As Rob Pike says, many other languages are copying features from each other, losing their unique aspects (think about JavaScript introducing the classes syntax to please Java and PHP developers) and they are all ideally converging to a conceptually unique language.

正如Rob Pike所说的那样 ,许多其他语言正在互相复制功能,从而失去了它们独特的方面(例如JavaScript向Java和PHP开发人员引入了类语法),并且它们都在理想情况下融合为概念上独特的语言。

Go does not compete in features. This reminds me of this Getting Real article.

Go不能在功能上竞争。 这使我想起了《 Getting Real》的这篇文章 。

当心:围棋是两极分化的 (Beware: Go is polarizing)

Go has lots of fans, and lots of haters too. As a PHP developer I’m sure you developed a thick skin on this kind of flame wars, and we can quickly move on to the next point. It’s very popular and developers have strong opinions.

Go有很多粉丝,也有很多仇恨者。 作为一名PHP开发人员,我敢肯定您在这种火焰战争中开发了厚厚的皮肤,我们可以快速进行下一步。 它非常受欢迎,并且开发人员有很强的见解。

No matter what trade-offs you make, there will always be criticisms, because no programming language can be perfect

无论您做出什么取舍,总是会有批评,因为没有一种编程语言可以是完美的

Go solves a problem, beautifully. And you don’t need to be a genius to start using it, although this might hurt your feelings.

Go很好地解决了问题。 而且您不必成为天才就可以开始使用它,尽管这可能会损害您的感觉。

Go非常自以为是,约定清晰 (Go is very opinionated and has clear conventions)

One of the first things you’ll notice about Go is that almost all the code you can find looks almost the same.

您会发现关于Go的第一件事是几乎所有可以找到的代码都几乎相同。

This is because Go has clear and forced conventions. The built-in tooling provides 2 commands related to conventions (gofmt and golint, with the first auto-formatting code, and the second just printing warnings), and they can check if your code complies, and even automatically adjusting your style to the Go guidelines.

这是因为Go具有明确和强制的约定。 内置工具提供了2条与约定相关的命令( gofmtgolint ,其中第一个自动格式化代码,第二个仅打印警告),它们可以检查代码是否符合要求,甚至可以自动将样式调整为Go准则。

This is different than JS ESLint / JSHint, as those tools are team-wide application. As in everything JS, you can customize anything in the preferences. gofmt is one, no configuration, that-is-the-way-to-go-style.

这与JS ESLint / JSHint不同,因为这些工具是团队范围的应用程序。 就像在所有JS中一样,您可以自定义首选项中的任何内容。 gofmt是一种没有配置的样式。

This is great to provide consistency on your own code (code you wrote 5 years ago in PHP or JavaScript might be very different from your current conventions and preferences) and on code that everyone distributes.

这对于在您自己的代码(五年前用PHP或JavaScript编写的代码可能与您当前的约定和首选项可能非常不同)和每个人分发的代码上提供一致性非常 有用

Imagine no more internal team discussions on the best code styling, imagine all PRs to your open source project formatted and linted in the same way. Spaces vs0 tabs, save mind cycles - it’s tabs. Braces on same line or in the next? One the same line, always (there’s a reason for this, and it’s to allow to omit semicolons).

想象没有更多的内部团队讨论最佳代码样式,想象一下开源项目中所有PR都以相同的方式格式化和倾斜。 分隔vs0选项卡,节省思维周期-它是选项卡。 大括号是在同一行还是在下一行? 总是同一行(这是有原因的,它允许省略分号)。

Go raises a compile error if a variable or import is not used, preventing your programs to accumulate garbage over time.

如果未使用变量或导入,Go会引发编译错误,从而防止程序随时间累积垃圾。

Naming conventions are so important that the access modifiers has been totally removed from the equation. Lowercase variable? Private. Capitalized variable? Public. Simple as that, a simple conventions removes tons of useless screen space usage, plus it’s immediately understandable.

命名约定是如此重要,以至于访问修饰符已从等式中完全删除。 小写变量? 私人的。 大写变量? 上市。 如此简单,一个简单的约定就消除了大量无用的屏幕空间使用,并且立即可以理解。

Comments serve a special need, and you write them in a special syntax so your package can be inspected using go doc and you have all the documentation you need without searching for it on Google.

注释有特殊需要,您可以使用特殊语法编写注释,以便可以使用go doc检查软件包,而无需在Google上搜索即可获得所需的所有文档。

go get is at your disposal, built-in (which is great for open source and distribution). Although PHPland is much more advanced in my opinion in terms of dependencies management.

go get内置,随时可用(非常适合开源和发行)。 虽然在我看来,PHPland在依赖项管理方面要先进得多。

PHPUnit/Codeception? No need, go test is already there for your *_test.go files.

PHPUnit /代码接收? 不需要, *_test.go文件已经在那里进行go test

它使您成为更好的程序员 (It makes you a better programmer)

If you’re coming from PHP, learning Go will make you think in a different, new way. It will make you a better programmer much like learning any different language will: it introduces you to new concepts. If it feels strange and alien, it’s a good sign you’re learning and growing as a developer.

如果您来自PHP,那么学习Go会让您以另一种全新的方式思考。 这将使您成为更好的程序员,就像学习任何其他语言一样:它为您介绍了新概念。 如果感觉陌生而陌生,则表明您正在学习并成长为一名开发人员。

To start with, Go is compiled instead of interpreted. Completely different workflow and deployment.

首先,Go是编译而不是解释的。 完全不同的工作流程和部署。

If you don’t have experience with strong typing, that’s a paradigm change. PHP 7 comes with typing checking, and it’s a great help if you don’t have to support older PHP versions. Go is strongly typed. Many if not all types issues are solved at compile time.

如果您没有使用强类型的经验,那将是一个范式更改。 PHP 7附带了类型检查功能,如果您不必支持较早PHP版本,这将是一个很大的帮助。 Go是强类型的。 许多(如果不是全部)类型问题在编译时已解决。

Go is amazingly simple, designed to be simple, and being a Go developer means recognizing this simplicity and taking advantage of it, and not try to write Java-like Go, but embrace it.

Go非常简单,设计得很简单,而成为Go开发人员意味着要认识到这种简单性并加以利用,而不是尝试编写类似于Java的Go,而是要接受它。

And by simple I don’t mean Go is a toy language, it certainly isn’t, and it’s not a language I’d introduce someone to coding.

简单地说,我并不是说Go是一种玩具语言,它当然不是,并且它不是我要向某人介绍编码的语言。

By simplicity I mean more minimalism and no-fluff.

简单来说,我的意思是更多的极简主义轻松感

When a language offers you many ways to do the same thing, you are forced to think which is best, distracting from the problem you’re trying to solve.

当一种语言为您提供多种方法来做相同的事情时,您就不得不思考哪种才是最好的,这会分散您要解决的问题的注意力。

您可以从PHP运行Go代码 (You can run Go code from PHP)

So one way I suggest to start with is to code some heavy routine or long-running piece of code that consumes too much memory as a Go service.

因此,我建议一开始的方法是编写一些繁重的例程或长时间运行的代码,这些代码作为Go服务会占用过多的内存。

There are many ways to directly call Go programs from PHP, but you might also choose to implement a service queue through ZeroMQ, or access a long-lived go program through exposing an API endpoint through a reverse proxy. You have many options.

目前有 很多 方法可以直接从PHP调用围棋程序,但你还可以选择来实现通过ZeroMQ服务队列穿过反向代理暴露的API端点,或访问一个长寿命的围棋程序。 您有很多选择。

Go的特殊武器:并发 (Go’s special weapon: concurrency)

PHP-FPM is known to handle concurrent requests very well, spawning a new process that execute the actual PHP code for each user. And usually in a web application the database is the bottleneck. But what about long-running processes (something that you don’t really want to build in PHP), or when you need to start a heavy computational loop within a PHP request, where you need to run tens of thousands of concurrent processes?

众所周知,PHP-FPM可以很好地处理并发请求,产生了一个新进程,该进程为每个用户执行实际PHP代码。 通常,在Web应用程序中,数据库是瓶颈。 但是,对于长时间运行的进程(您实际上并不想在PHP中构建的东西),或者当您需要在PHP请求中启动繁重的计算循环(您需要在其中运行成千上万个并发进程)呢?

PHP has threads support, so it can do concurrent processing, but while PHP (or even C and others) can do concurrency using the help of libraries external to the language, Go is designed with built-in concurrent programming, and provides native ways to communicate between goroutines.

PHP有线程的支持,所以它可以做并行处理,但在PHP(甚至C和其他人)可以使用外部的语言库的帮助下做的并发性,走的是设计有内置的并行编程,并提供原生的方法goroutine之间进行通信。

Threads are heavy, compared to goroutines. A system could support 10k threads, and the same system could support millions of goroutines, because of the internal implementation of the memory consumption of goroutines is much lighter, like in Java or Erlang.

goroutines相比,线程很重。 一个系统可以支持10k线程,并且同一系统可以支持数百万个goroutine,因为内部实现了goroutine的内存消耗要轻得多,例如Java或Erlang。

So even if you don’t need millions of concurrent requests, the performance gains are clear.

因此,即使您不需要数百万个并发请求,性能提升也很明显。

Plus, it’s very easy to digest goroutines and understand what the code does from a quick look.

另外,通过简单的方式消化goroutine并了解代码的作用非常容易。

No need to extend classes or include special extensions, which might not be always available (this effectively limits the extent that we can use PHP concurrency for self-installed distributed code)

无需扩展类或包括特殊扩展名,这些扩展名可能并不总是可用(这有效地限制了我们可以将PHP并发用于自安装分布式代码的程度)

Just type go someFunction() and that function will be executed in a goroutine.

只需输入go someFunction() ,该函数将在goroutine中执行。

结论 (Conclusion)

If you’re a PHP developer new to Go, I hope you’re now curios about this tool, and thinking about where it could have been useful, or if it’s the right choice for you.

如果您是Go的新手PHP开发人员,希望您现在对这个工具感到好奇,并考虑该工具在什么地方有用,或者是否适合您。

If you’re a programmer that prefers simplicity over complexity, favour direct and readable code over abstractions, then I’m sure you’ll find Go really interesting.

如果您是一个喜欢简单而不是复杂,而是喜欢直接和可读的代码而不是抽象的程序员,那么我相信您会发现Go真的很有趣。

翻译自: https://flaviocopes.com/golang-for-php-developers/

golang go语言

golang go语言_为什么Go是作为PHP开发人员学习的功能强大的语言相关推荐

  1. java语言的三个版本是_Java是一个全面且功能强大的语言,可用于多种用途。Java有三个版本分别是:_学小易找答案...

    [单选题]电路如图所示,电路中包含的网孔个数为( ). [单选题]各点电位的高低是()的,而两点之间的电压值是()的. [单选题]研究发现,影响睡眠障碍的生物学因素与非生物学因素(). [单选题]1 ...

  2. 前端要不要学习一门后端语言_这是一门免费课程,可帮助前端开发人员学习数学

    前端要不要学习一门后端语言 Are you looking to become a more effective developer by improving your fundamental mat ...

  3. java更好的语言_五个使Java变得更好的功能

    java更好的语言 我偶然发现了Brian Goetz 提出的有关Java数据类的建议 ,立即意识到我也对如何使Java更好地成为一种语言有一些想法. 我实际上有很多,但这只是五个最重要的简短列表. ...

  4. bs后端开发语言_哪种编程语言适合后端开发?Java和PHP的区别在哪?

    从技术上看在web开发上,Java和PHP哪个更好呢? 一位从多年PHP开发转Java的技术人员说,应是各有千秋,各有各的好处,这是非常实际的答案. java已经是一门很成熟的语言,曾经看到一篇文章, ...

  5. android开发人员要求_如何成为一名Android开发人员

    android开发人员要求 An Android Developer is somebody who creates our lives simple by creating a correspond ...

  6. 初级java开发学习路线_成为初级全栈Web开发人员的10分钟路线图

    初级java开发学习路线 So you have started your journey into the world of web development. But what do you lea ...

  7. Bitcoin.com开发人员正创建一个用Rust语言编写的BCH全节点

    近日,Bitcoin.com开发人员Gabriel Cardona在推特表示,自己正创建一个用Rust语言编写的BCH全节点,目的是为了改变完整节点的范式,让BCH代码库更加安全.编程人员技术贡献更加 ...

  8. java单词按字典排序_最终Java日志字典:开发人员最常记录的单词是什么?

    java单词按字典排序 最终的记录字典,或者:我们记录的最常见单词是什么? 日志文件是调试应用程序的最常用方法,当解决错误时,它们肯定可以引导我们朝正确的方向发展. 但是,大多数日志文件每天都会增加一 ...

  9. 自动化yaml文件_从YAML到TypeScript:开发人员对云自动化的看法

    自动化yaml文件 The rise of managed cloud services, cloud-native, and serverless applications brings both ...

最新文章

  1. iOS实录15:浅谈iOS Crash
  2. 服务器系统tcpip.sys,tcpip.sys
  3. [学习笔记]树链剖分
  4. VTK:PolyData之CurvaturesDemo
  5. (转)RTMP协议从入门到放弃
  6. 734. [网络流24题] 方格取数问题 二分图点权最大独立集/最小割/最大流
  7. 电脑提示找不到宽带连接怎么办
  8. Set、Map集合、栈、队列
  9. python 仅保留数字_python从入门到入土 | 基本语法元素(一)
  10. SQL Server 2008 R2下载地址
  11. TY_GASPX SQL
  12. HDU3595_GG and MM
  13. KAIOS软件下载-自己做的
  14. 接口文档神器---Swagger注解使用与实例
  15. Dos命令 --复制文件(夹)
  16. 分享超高清多机位现场直播间搭建方案
  17. html透明背景字体不透明,css3背景透明,文字不透明
  18. S60 Python 编程指南——如何创建pys60应用程序
  19. java源文件在哪_java源文件由什么组成?
  20. 三年级优秀书籍推荐_三年级好书推荐

热门文章

  1. 大疆app部门软件高级测试专家面试
  2. Xcode中delete键不可用了
  3. jQuery.i18n.properties 中文说明文档
  4. 关于电容器的实验和再认识
  5. html的绝对路径怎么选择,html的相对路径和绝对路径
  6. androidkiller 关键词修改方法
  7. Excel VLOOKUP实用教程之 05 vlookup如何从列表中获取最后一个值?(教程含数据excel)
  8. python 小说爬虫_小说爬虫python
  9. 配网低压绝缘子缺陷检测图像数据集(txt标签,1w多张,主要为绝缘子破损类缺陷)
  10. 短信营销时短信发送失败的原因有哪些?