2020年编程语言展望

时下最热门的语言是JavaScript,Java和Python,但是编程语言的新陈代谢也在不断发展着,新的优秀语言层出不穷,立足取代他们地位。有一首歌唱的好:"由来只有新人笑,有谁知道旧人哭",对编程语言也是如此。那么在2020的今天,谁是最有前途的语言呢?我们需要拉一个列表,一起说道说道。

成都创新互联公司专注于市中企业网站建设,响应式网站设计,商城建设。市中网站建设公司,为市中等地区提供建站服务。全流程按需开发网站,专业设计,全程项目跟踪,成都创新互联公司专业和态度为您提供的服务

Dart

和Ruby借助RoR一样,Dart语言也是借助有一个强有力的框架Flutter以及有个好爹谷歌的缘故,该语言迅速流行起来。

优势:一种比JavaScript更好的语言。

缺点:与JavaScript及其庞大生态系统直面竞争。

实例:

 
 
 
  1. class Complex { 
  2.  
  3. double _r,_i; 
  4.  
  5. Complex(this._r,this._i); 
  6.  
  7. double get r => _r; 
  8.  
  9. double get i => _i; 
  10.  
  11. String toString() => "($r,$i)"; 
  12.  
  13. Complex operator +(Complex other) => new Complex(r+other.r,i+other.i); 
  14.  
  15. Complex operator *(Complex other) => 
  16.  
  17. new Complex(r*other.r-i*other.i,r*other.i+other.r*i); 
  18.  
  19. double abs() => r*r+i*i; 
  20.  
  21. } 
  22.  
  23. void main() { 
  24.  
  25. double start_x=-1.5; 
  26.  
  27. double start_y=-1.0; 
  28.  
  29. double step_x=0.03; 
  30.  
  31. double step_y=0.1; 
  32.  
  33. for(int y=0;y<20;y++) { 
  34.  
  35. String line=""; 
  36.  
  37. for(int x=0;x<70;x++) { 
  38.  
  39. Complex c=new Complex(start_x+step_x*x,start_y+step_y*y); 
  40.  
  41. Complex z=new Complex(0.0, 0.0); 
  42.  
  43. for(int i=0;i<100;i++) { 
  44.  
  45. z=z*(z)+c; 
  46.  
  47. if(z.abs()>2) { 
  48.  
  49. break; 
  50.  
  51. } 
  52.  
  53. } 
  54.  
  55. line+=z.abs()>2 ? " " : "*"; 
  56.  
  57. } 
  58.  
  59. print(line); 
  60.  
  61. } 
  62.  
  63. } 

Elixir

Elixir有一个美好的名字,翻译为中文是"灵丹妙药,长生不老药",它源自于Erlang,改进了语法以及对有更强大的并发人支持。作为一种纯函数式语言,是否可以作为了主流,并长久不衰,长生不老呢?需要我们拭目以待。

优势:功能编程非常简单,强大的并发性。

缺点:需要熟悉函数式编程和函数式思维,学习曲线不直。

实例:

 
 
 
  1. defmodule Mandelbrot do 
  2.  
  3. def set do 
  4.  
  5. xsize = 59 
  6.  
  7. ysize = 21 
  8.  
  9. minIm = -1.0 
  10.  
  11. maxIm = 1.0 
  12.  
  13. minRe = -2.0 
  14.  
  15. maxRe = 1.0 
  16.  
  17. stepX = (maxRe - minRe) / xsize 
  18.  
  19. stepY = (maxIm - minIm) / ysize 
  20.  
  21. Enum.each(0..ysize, fn y -> 
  22.  
  23. im = minIm + stepY * y 
  24.  
  25. Enum.map(0..xsize, fn x -> 
  26.  
  27. re = minRe + stepX * x 
  28.  
  29. 62 - loop(0, re, im, re, im, re*re+im*im) 
  30.  
  31. end) |> IO.puts 
  32.  
  33. end) 
  34.  
  35. end 
  36.  
  37. defp loop(n, _, _, _, _, _) when n>=30, do: n 
  38.  
  39. defp loop(n, _, _, _, _, v) when v>4.0, do: n-1 
  40.  
  41. defp loop(n, re, im, zr, zi, _) do 
  42.  
  43. a = zr * zr 
  44.  
  45. b = zi * zi 
  46.  
  47. loop(n+1, re, im, a-b+re, 2*zr*zi+im, a+b) 
  48.  
  49. end 
  50.  
  51. end 
  52.  
  53. Mandelbrot.set 

Golang

谷歌的又一个嫡儿子。在攻城掠土方面,Golang已经取得了不错的成绩。Golang编译速度快,便捷的语法,静态变量,基于协程的高性能并发支持。当然也有槽点,比如繁琐错误语法、混乱模块机制,和缺乏泛型,当然golang社区也一直在努力改进,这些槽点预计将来都会消失。

优势:语法简单,静态类型,很好的并发性。

缺点:缺少泛型,错误语法,模块机制。

实例:

 
 
 
  1. package main 
  2.  
  3. import ( 
  4.  
  5. "fmt" 
  6.  
  7. "image" 
  8.  
  9. "image/color" 
  10.  
  11. "image/draw" 
  12.  
  13. "image/png" 
  14.  
  15. "math/cmplx" 
  16.  
  17. "os" 
  18.  
  19. ) 
  20.  
  21. const ( 
  22.  
  23. maxEsc = 100 
  24.  
  25. rMin = -2. 
  26.  
  27. rMax = .5 
  28.  
  29. iMin = -1. 
  30.  
  31. iMax = 1. 
  32.  
  33. width = 750 
  34.  
  35. red = 230 
  36.  
  37. green = 235 
  38.  
  39. blue = 255 
  40.  
  41. ) 
  42.  
  43. func mandelbrot(a complex128) float64 { 
  44.  
  45. i := 0 
  46.  
  47. for z := a; cmplx.Abs(z) < 2 && i < maxEsc; i++ { 
  48.  
  49. z = z*z + a 
  50.  
  51. } 
  52.  
  53. return float64(maxEsc-i) / maxEsc 
  54.  
  55. } 
  56.  
  57. func main() { 
  58.  
  59. scale := width / (rMax - rMin) 
  60.  
  61. height := int(scale * (iMax - iMin)) 
  62.  
  63. bounds := image.Rect(0, 0, width, height) 
  64.  
  65. b := image.NewNRGBA(bounds) 
  66.  
  67. draw.Draw(b, bounds, image.NewUniform(color.Black), image.ZP, draw.Src) 
  68.  
  69. for x := 0; x < width; x++ { 
  70.  
  71. for y := 0; y < height; y++ { 
  72.  
  73. fEsc := mandelbrot(complex( 
  74.  
  75. float64(x)/scale+rMin, 
  76.  
  77. float64(y)/scale+iMin)) 
  78.  
  79. b.Set(x, y, color.NRGBA{uint8(red * fEsc), 
  80.  
  81. uint8(green * fEsc), uint8(blue * fEsc), 255}) 
  82.  
  83. } 
  84.  
  85. } 
  86.  
  87. f, err := os.Create("mandelbrot.png") 
  88.  
  89. if err != nil { 
  90.  
  91. fmt.Println(err) 
  92.  
  93. return 
  94.  
  95. } 
  96.  
  97. if err = png.Encode(f, b); err != nil { 
  98.  
  99. fmt.Println(err) 
  100.  
  101. } 
  102.  
  103. if err = f.Close(); err != nil { 
  104.  
  105. fmt.Println(err) 

Julia

Julia是一门强大的数值计算语言。其语法对数学支持非常好,很适合数据科学家编写应用。是取代Python统计分析和数值计算的预备选手之一。

优势:对数学友好。

缺点:要与Python竞争。

实例:

 
 
 
  1. using Images 
  2.  
  3. @inline function hsv2rgb(h, s, v) 
  4.  
  5. const c = v * s 
  6.  
  7. const x = c * (1 - abs(((h/60) % 2) - 1)) 
  8.  
  9. const m = v - c 
  10.  
  11. const r,g,b = 
  12.  
  13. if h < 60 
  14.  
  15. (c, x, 0) 
  16.  
  17. elseif h < 120 
  18.  
  19. (x, c, 0) 
  20.  
  21. elseif h < 180 
  22.  
  23. (0, c, x) 
  24.  
  25. elseif h < 240 
  26.  
  27. (0, x, c) 
  28.  
  29. elseif h < 300 
  30.  
  31. (x, 0, c) 
  32.  
  33. else 
  34.  
  35. (c, 0, x) 
  36.  
  37. end 
  38.  
  39. (r + m), (b + m), (g + m) 
  40.  
  41. end 
  42.  
  43. function mandelbrot() 
  44.  
  45. const w, h = 1000, 1000 
  46.  
  47. const zoom = 0.5 
  48.  
  49. const moveX = 0 
  50.  
  51. const moveY = 0 
  52.  
  53. const img = Array{RGB{Float64}}(h, w) 
  54.  
  55. const maxIter = 30 
  56.  
  57. for x in 1:w 
  58.  
  59. for y in 1:h 
  60.  
  61. i = maxIter 
  62.  
  63. const c = Complex( 
  64.  
  65. (2*x - w) / (w * zoom) + moveX, 
  66.  
  67. (2*y - h) / (h * zoom) + moveY 
  68.  
  69. ) 
  70.  
  71. z = c 
  72.  
  73. while abs(z) < 2 && (i -= 1) > 0 
  74.  
  75. z = z^2 + c 
  76.  
  77. end 
  78.  
  79. const r,g,b = hsv2rgb(i / maxIter * 360, 1, i / maxIter) 
  80.  
  81. img[y,x] = RGB{Float64}(r, g, b) 
  82.  
  83. end 
  84.  
  85. end 
  86.  
  87. save("mandelbrot_set.png", img) 
  88.  
  89. end 
  90.  
  91. mandelbrot() 

Kotlin

Kotlin是优化版本的Java,作为Java的取代者之一。谷歌已经在安卓开发中支持Kotlin。

优势:更强大的Java。

缺点:好要依靠Java的阴影活着。

 
 
 
  1. import java.awt.Graphics 
  2.  
  3. import java.awt.image.BufferedImage 
  4.  
  5. import javax.swing.JFrame 
  6.  
  7. class Mandelbrot: JFrame("Mandelbrot Set") { 
  8.  
  9. companion object { 
  10.  
  11. private const val MAX_ITER = 570 
  12.  
  13. private const val ZOOM = 150.0 
  14.  
  15. } 
  16.  
  17. private val img: BufferedImage 
  18.  
  19. init { 
  20.  
  21. setBounds(100, 100, 800, 600) 
  22.  
  23. isResizable = false 
  24.  
  25. defaultCloseOperation = EXIT_ON_CLOSE 
  26.  
  27. img = BufferedImage(width, height, BufferedImage.TYPE_INT_RGB) 
  28.  
  29. for (y in 0 until height) { 
  30.  
  31. for (x in 0 until width) { 
  32.  
  33. var zx = 0.0 
  34.  
  35. var zy = 0.0 
  36.  
  37. val cX = (x - 400) / ZOOM 
  38.  
  39. val cY = (y - 300) / ZOOM 
  40.  
  41. var iter = MAX_ITER 
  42.  
  43. while (zx * zx + zy * zy < 4.0 && iter > 0) { 
  44.  
  45. val tmp = zx * zx - zy * zy + cX 
  46.  
  47. zy = 2.0 * zx * zy + cY 
  48.  
  49. zx = tmp 
  50.  
  51. iter-- 
  52.  
  53. } 
  54.  
  55. img.setRGB(x, y, iter or (iter shl 7)) 
  56.  
  57. } 
  58.  
  59. } 
  60.  
  61. } 
  62.  
  63. override fun paint(g: Graphics) { 
  64.  
  65. g.drawImage(img, 0, 0, this) 
  66.  
  67. } 
  68.  
  69. } 
  70.  
  71. fun main(args: Array) { 
  72.  
  73. Mandelbrot().isVisible = true 
  74.  
  75. } 

Lua

Lua是一种小型,简单,快速,可嵌入,可移植且灵活的语言。

优点:小型、内嵌,nginx编程

缺点:已经26年了,年事已高。

实例:

Pharo

Pharo是Smalltalk的现代化变体,是一种非常有生产力的面向对象语言。实际上,Smalltalk是OOP的典范,并且已经启发了几乎所有其他OOP语言。但是,也没有其他一种语言能比Smalltalk更好地实现OOP。

Pharo也是世界上最简单和最优雅的语言之一,可以让我们在15分钟内学习Smalltalk的全部语法,

优势:生产率高,生产率提高5倍。

缺点:需要不同的编程思想。

实例:

Rust

Rust是一种设计为内存安全的编程语言,通过borrow和变量生命周期控制消除了与存储器相关的编程错误。Rust承诺编程会更安全。而且Rust效率也非常高,语法也非常优雅,目前热度很高,Github中Rust新项目层出不穷。

优势:开发更加可靠,有从系统级到应用级,浏览器引擎(Firefox),Web开发等各方面的实例。门槛有点高,可以筛选掉一批写bug的码农。

缺点:学习曲线比较陡峭,门槛较高,把一批新手挡在外面。

实例:

WebAssembly

WebAssembly可以说是一匹黑马。预计在接下来十年左右的时间里,可能会衍生出许多升至顶级的语言。WebAssembly 是一种接近机器语言的跨平台二进制格式。目前四大主流浏览器厂商谷歌Chrome、苹果Safari、微软Edge 和 Mozilla FireFox 均以支持了WebAssembly 的初始版本,而且为了安全规范,去年各大厂商又成立了字节码联盟,立足于通过协作制定和实施标准,完善 WebAssembly 在浏览器之外的生态。

优点:广泛的浏览器和语言支持。

缺点:生态体系尚未完善。

实例:

 
 
 
  1. request = new XMLHttpRequest(); 
  2.  
  3. request.open('GET', 'simple.wasm'); 
  4.  
  5. request.responseType = 'arraybuffer'; 
  6.  
  7. request.send(); 
  8.  
  9. request.onload = function() { 
  10.  
  11. var bytes = request.response; 
  12.  
  13. WebAssembly.instantiate(bytes, importObject).then(results => { 
  14.  
  15. results.instance.exports.exported_func(); 
  16.  
  17. }); 
  18.  
  19. }; 

新闻标题:2020年编程语言展望
链接URL:http://wkslyf.com/article/cohigdc.html