Programming language for server backend

Very well written, reprint it and share it with everyone!



This article is compiled and translated by csdn  cedricliang . If there is  any reprint, please indicate the translator and the source of the original text at the beginning of the original text to show respect!

Translation: cedricliang

Original text: http://blog.csdn.net/cedricliang/article/details/48437437

What backend programming language would I choose for a large new project in a startup that needs web services? On the client side there are CSS, html and JavaScript (including derivatives such as CoffeeScript and TypeScript) to choose from. For storage, I have used MySQL and Redis , which is basically enough. But choosing a server-side language is not that easy. I've been using PHP for a long time because it was the easiest and cheapest when I first started programming. But times have changed, and now I don't have to worry about expensive server hosting fees anymore. Even though I don't have that much experience with web projects, I would like to share some of my thoughts.

Definition: Backend and Security

Just a heads up: I'm only talking about the backend. The so-called backend refers to the data access layer that processes server requests. It needs to handle many requests (greater than 100 requests per second) and fast requests (average processing time is less than 300ms). Those that can be calculated ahead of time, or do not need to be directly exposed to the client, are not suitable for back-end processing. These jobs can be accomplished in other ways in other languages. The back-end also does not directly deal with the presentation to the user, which is what the front-end should do. But back-end developers should have a clear understanding of how to provide data to the front-end. The clearest way I've seen is to use a pure Restful API to interact between the front and back ends.

The backend language should also be easy to verify the data sent by the frontend, easily connect to the database , and save or retrieve files from the file system.

In the following pages, I will describe language security. But that doesn't mean that you can't write safe code in unsafe languages, but that compilers in different languages ​​can guarantee that your code doesn't have certain bugs. For example, C's compiler doesn't do bounds checking, so it's a very unsafe language. And those errors that can be checked by automated tools include:

  • Grammatical errors
  • read out of bounds
  • Out of memory (C/C++ doesn't check, but it's almost impossible in java)
  • unused variable
  • Type issue: This issue is slightly ambiguous because you can write strongly typed code in every language. But in some languages, types are more common. Some languages ​​also use type systems to find errors. For example, php is very insecure in this sense. can even 123=="123ab"be true. Python is slightly safer, but you can return values ​​however you want. Java is much safer by comparison. Haskel is safer in this regard, as its strong type system will refuse to execute any nonsensical expressions and will not perform any kind of coercion.

During the runtime of the program, there are also some errors will be found. In different languages, the handling of such runtime errors is completely different. For example, C and C++ fail silently. (As said in this link ) This is of course very bad. Compared with C/C++'s ignoring of out-of-bounds errors, Rust will issue obvious prompts. (The previous heartbleed is a typical example, you can check this article )

Of course, all of these problems can be found with good testing . However, the more processes that can be automated, the fewer surprises can happen when you don't test enough.

Java

Java是跑在Java虚拟机的面向对象的语言。对于商业网站而言,java是使用最广泛的语言。为什么呢?

上述是Java的优点,那么它的缺点呢:

  • 非常笨拙的语法。为了完成一个功能,你可能要打很多字。。当然自动补全是必不可少的,但是要打的东西还是不少。代码越多,维护起来成本越高。
  • 要把一个工具跑起来难度很高
  • 那些被设计用来扩展的super-abstract结构,事实上可能永远不会被用到。
  • 因为没有指针的存在,Java不能访问越界的数组,所以比C/C++安全一些。那些烦恼你的内存溢出也几乎不存在了。但是付出的代价就是,语法更加的复杂,而且你如果一不小心,就会掉入Java中得不安全的陷阱。
  • 速度和内存使用量:Java在速度上并不突出,而在内存使用上则是相当的多。但是这并没给它的大范围使用带来太多的问题。感兴趣的可以看看这篇文章

对于Java还可以参考以下文章:

Javascript: Node.js

Node.js自从2009年发布一下,使用十分广泛。Node.js具有异步,事件驱动以及可扩展的特性。Node.js应用是由JavaScript开发的,因此它具有JavaScript的所有优点:

  • 享受到了JavaScript V8引擎的好处
  • 灵活而轻量级的语法
  • 跟Java一样,JavaScript出现在1995年。所以语言本身发展历史很长,相对稳定。 

还有什么要补充的?

  • Node很快,而且可扩展。(参考 Performance Comparison Between Node.js and Java EE
  • JavaScript不太安全。即使很小的语法错误也只会在执行的时候暴露出来。因此单元测试十分重要。
  • Node.js被LinkedIn,Yahoo!, Uber, Paypal使用
  • 有很多人从Node.js转向了Go 1 2 3

参考:

Go

Go是由Google开发的,静态类型的编译语言。它直到2009年才出现,十分短暂。

  • Go提供了那些你进行web开发需要的基本工具 
  • 有不错的教程和一些web开发的材料
  • 有一些任务在Go语言中超过预期的复杂,比如排序,详见link
  • Go有一些跟其他语言完全不同的diffuser,比如如果你想声明一个public方法,那这个方法的第一个字母一定要是大写的。还有未被使用的变量会导致编译错误。

参考:

C

C#是由微软开发的具有静态类型的编译语言。但是它却有很多动态特性。 它出现在2000年。而针对web开发的框架ASP.NET直到2002年才发布。

C#的生态系统包括:

我对C#/ASP.NET的理解并不深入,因此无法更详尽的分析它的优略。

Python

python是现在在用的最古老的语言之一。它最早出现于1991年。Python是具有动态的类型,面向对象的解释性语言。而且它具有函数编程的特性。 
尽管我曾经在很多项目中使用过Python,但并不包括web项目。因此那些重要的工具和框架可能会被遗漏:

我认为Python最主要的优势在于代码容易撰写,而且可读性很高。我对Python显然是有偏爱的,而且我坚信很多人和我有着同样的观点。

PHP

PHP是动态类型的服务器端语言,它在1995年被推出。

PHP最大的优势是学习门槛低。它基本可以在任何地方被执行,托管和非常简单。Wikipedia使用的就是PHP,所以很明显使用PHP来创建可用的大型网站是可行的。 
write picture description here

Hack

Hack是由Facebook在2014年开发的编程语言。它是PHP的变体。它与PHP最主要的不同在于:

  • 函数参数和返回值是指定类型的
  • Hack并不完全支持PHP的一些特性source,比如goto、可变变量、字符串自增,这有时候也挺好的。

参考:

Rust

Rust是很安全的语言,但是对于它在生产环境的使用,仍有疑虑。

参考:

其他

Ruby with Rails: 我知道它应用广泛,但是我对Ruby的了解并不充分。Ruby的语法与Python类似。

参考

结论

仔细想来,对我来说以下的语言更适合我做后端:

  • Go:很快,而且是编译型的
  • node.js: 很好的可扩展性
  • Python: 这是我最了解的语言。除此之外,它有非常清晰的语法,很好的社区开发的变法风格,以及易读性。

对我来说不适合的语言:

  • PHP: 因为语言的不一致,导致建立稳定的后端没那么简单。
  • C#: 这个语言太以微软为中心了
  • Java:语法有点拖沓,成本高。

其他语言可能也是很好的选择,只是我知之甚少。我对rust在后端使用的可行性非常好奇。Hack语言非常年轻,让我们对它未来的发展拭目以待。

Original link: http://martin-thoma.com/languages-for-back-ends/#tocAnchor-1-11

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324539758&siteId=291194637