2020年,大火的Python和JavaScript是否会被取而代之?

Python 和 JavaScript 是目前最火的两大编程语言。然而,他们不可能永远屹立不倒。最终,必将像其他编程语言一样跌下神坛。这很可能在接下来的十年左右上演。

那么什么编程语言将会取而代之呢? 下面给出我的候选者名单!

Dart

多亏了 Flutter 框架和 Google 的认可,该语言迅速流行开来。这和 Rails 框架让 Ruby 流行起来的原因非常相似。如果谷歌的 Fuchsia 系统能够火起来,Dart 将受益最大。

  • 核心优势:它是一种比 JavaScript 更棒的编程语言。

  • 主要缺点:不得不面对 JavaScript 语言和 JavaScript 的强烈拥护者的挑战。

  • 曼德布洛特集样本:

    class Complex {

    double _r,_i;

    Complex(this._r,this._i);

    double get r => _r;

    double get i => _i;

    String toString => "($r,$i)";

    Complex operator +(Complex other) => new Complex(r+other.r,i+other.i);

    Complex operator *(Complex other) =>

    new Complex(r*other.r-i*other.i,r*other.i+other.r*i);

    double abs => r*r+i*i;

    }

    void main {

    double start_x=-1.5;

    double start_y=-1.0;

    double step_x=0.03;

    double step_y=0.1;

    for(int y=0;y<20;y++) {

    String line="";

    for(int x=0;x<70;x++) {

    Complex c=new Complex(start_x+step_x*x,start_y+step_y*y);

    Complex z=new Complex(0.0, 0.0);

    for(int i=0;i<100;i++) {

    z=z*(z)+c;

    if(z.abs>2) {

    break;

    }

    }

    line+=z.abs>2 ? " " : "*";

    }

    print(line);

    }

    }

    Elixir

    Elixir 是基于一种基于 Erlang 虚拟机的函数式编程语言,对并发的支持非常好。作为一个纯粹的函数式编程语言,它有望将这种范式变为主流。

  • 核心优势:它让函数式编程变得异常简单,对并发的支持非常棒。

  • 主要缺点:需要有 OTP 基础,但掌握 OTP 却没那么容易。

  • 曼德布洛特集样本:

    defmodule Mandelbrot do

    def set do

    xsize = 59

    ysize = 21

    minIm = -1.0

    maxIm = 1.0

    minRe = -2.0

    maxRe = 1.0

    stepX = (maxRe - minRe) / xsize

    stepY = (maxIm - minIm) / ysize

    Enum.each(0..ysize, fn y ->

    im = minIm + stepY * y

    Enum.map(0..xsize, fn x ->

    re = minRe + stepX * x

    62 - loop(0, re, im, re, im, re*re+im*im)

    end) |> IO.puts

    end)

    end

    defp loop(n, _, _, _, _, _) when n>=30, do: n

    defp loop(n, _, _, _, _, v) when v>4.0, do: n-1

    defp loop(n, re, im, zr, zi, _) do

    a = zr * zr

    b = zi * zi

    loop(n+1, re, im, a-b+re, 2*zr*zi+im, a+b)

    end

    end

    Mandelbrot.set

    Golang

    得益于其闪电般的编译速度、简单和高效的并发支持,另外一个谷歌受支持的编程语言 Golang 已经崭露头角。唯一缺的就是泛型支持,但是这个特性已经在规划上了。

  • 核心优势:上手简单,对并发的支持非常出色。

  • 主要缺点:缺少泛型支持(暂时的)。

  • 曼德布洛特集样本:

    package main

    import (

    "fmt"

    "image"

    "image/color"

    "image/draw"

    "image/png"

    "math/cmplx"

    "os"

    )

    const (

    maxEsc = 100

    rMin = -2.

    rMax = .5

    iMin = -1.

    iMax = 1.

    width = 750

    red = 230

    green = 235

    blue = 255

    )

    func mandelbrot(a complex128)float64{

    i := 0

    for z := a; cmplx.Abs(z) < 2 && i < maxEsc; i++ {

    z = z*z + a

    }

    return float64(maxEsc-i) / maxEsc

    }

    func main{

    scale := width / (rMax - rMin)

    height := int(scale * (iMax - iMin))

    bounds := image.Rect(0, 0, width, height)

    b := image.NewNRGBA(bounds)

    draw.Draw(b, bounds, image.NewUniform(color.Black), image.ZP, draw.Src)

    for x := 0; x < width; x++ {

    for y := 0; y < height; y++ {

    fEsc := mandelbrot(complex(

    float64(x)/scale+rMin,

    float64(y)/scale+iMin))

    b.Set(x, y, color.NRGBA{uint8(red * fEsc),

    uint8(green * fEsc), uint8(blue * fEsc), 255})

    }

    }

    f, err := os.Create("mandelbrot.png")

    if err != nil {

    fmt.Println(err)

    return

    }

    if err = png.Encode(f, b); err != nil {

    fmt.Println(err)

    }

    if err = f.Close; err != nil {

    fmt.Println(err)

    }

    }

    Julia

    Julia 的优势在于对数学计算的支持非常出色。它对数学的语法支持非常好,堪称数据科学家的福音。假如有任何编程语言可以颠覆 Python, 它将是一个强有力的竞争者。

  • 核心优势:为科学家精心设计。

  • 主要缺点:面临着数据科学之王 Python 的竞争。

  • 曼德布洛特集样本:

    using Images

    @inline function hsv2rgb(h, s, v)

    const c = v * s

    const x = c * (1 - abs(((h/60) % 2) - 1))

    const m = v - c

    const r,g,b =

    if h < 60

    (c, x, 0)

    elseif h < 120

    (x, c, 0)

    elseif h < 180

    (0, c, x)

    elseif h < 240

    (0, x, c)

    elseif h < 300

    (x, 0, c)

    else

    (c, 0, x)

    end

    (r + m), (b + m), (g + m)

    end

    function mandelbrot

    const w, h = 1000, 1000

    const zoom = 0.5

    const moveX = 0

    const moveY = 0

    const img = Array{RGB{Float64}}(h, w)

    const maxIter = 30

    for x in 1:w

    for y in 1:h

    i = maxIter

    const c = Complex(

    (2*x - w) / (w * zoom) + moveX,

    (2*y - h) / (h * zoom) + moveY

    )

    z = c

    while abs(z) < 2 && (i -= 1) > 0

    z = z^2 + c

    end

    const r,g,b = hsv2rgb(i / maxIter * 360, 1, i / maxIter)

    img[y,x] = RGB{Float64}(r, g, b)

    end

    end

    save("mandelbrot_set.png", img)

    end

    mandelbrot

    Kotlin

    Kotlin 是升级版的 Java。 实际上,它可以完全替代 Java 编程语言,谷歌已经将其打造成 Android 开发的首选语言。

  • 核心优势:比 Java 更强大。

  • 主要缺点:Kotlin 非常庞大,甚至比 Java 更庞大。

  • 曼德布洛特集样本:

    import java.awt.Graphics

    import java.awt.image.BufferedImage

    import javax.swing.JFrame

    class Mandelbrot: JFrame("Mandelbrot Set") {

    companion object {

    private const val MAX_ITER = 570

    private const val ZOOM = 150.0

    }

    private val img: BufferedImage

    init {

    setBounds(100, 100, 800, 600)

    isResizable = false

    defaultCloseOperation = EXIT_ON_CLOSE

    img = BufferedImage(width, height, BufferedImage.TYPE_INT_RGB)

    for (y in 0 until height) {

    for (x in 0 until width) {

    var zx = 0.0

    var zy = 0.0

    val cX = (x - 400) / ZOOM

    val cY = (y - 300) / ZOOM

    var iter = MAX_ITER

    while (zx * zx + zy * zy < 4.0 && iter > 0) {

    val tmp = zx * zx - zy * zy + cX

    zy = 2.0 * zx * zy + cY

    zx = tmp

    iter--

    }

    img.setRGB(x, y, iter or (iter shl 7))

    }

    }

    }

    override fun paint(g: Graphics){

    g.drawImage(img, 0, 0, this)

    }

    }

    fun main(args: Array<String>){

    Mandelbrot.isVisible = true

    }

    Lua

  • 核心优势: Lua 是一种小巧、简单、快速、可嵌入、可移植和灵活的编程语言。

  • 主要缺点:Lua 被忽视了 26 年了。现在还能掀起风浪吗?

  • 曼德布洛特集样本:

    local maxIterations = 250

    local minX, maxX, minY, maxY = -2.5, 2.5, -2.5, 2.5

    local miX, mxX, miY, mxY

    function remap( x, t1, t2, s1, s2 )

    local f = ( x - t1 ) / ( t2 - t1 )

    local g = f * ( s2 - s1 ) + s1

    return g;

    end

    function drawMandelbrot

    local pts, a, as, za, b, bs, zb, cnt, clr = {}

    for j = 0, hei - 1 do

    for i = 0, wid - 1 do

    a = remap( i, 0, wid, minX, maxX )

    b = remap( j, 0, hei, minY, maxY )

    cnt = 0; za = a; zb = b

    while( cnt < maxIterations ) do

    as = a * a - b * b; bs = 2 * a * b

    a = za + as; b = zb + bs

    if math.abs( a ) + math.abs( b ) > 16 then break end

    cnt = cnt + 1

    end

    if cnt == maxIterations then clr = 0

    else clr = remap( cnt, 0, maxIterations, 0, 255 )

    end

    pts[1] = { i, j, clr, clr, 0, 255 }

    love.graphics.points( pts )

    end

    end

    end

    function startFractal

    love.graphics.setCanvas( canvas ); love.graphics.clear

    love.graphics.setColor( 255, 255, 255 )

    drawMandelbrot; love.graphics.setCanvas

    end

    function love.load

    wid, hei = love.graphics.getWidth, love.graphics.getHeight

    canvas = love.graphics.newCanvas( wid, hei )

    startFractal

    end

    function love.mousepressed( x, y, button, istouch )

    if button == 1 then

    startDrag = true; miX = x; miY = y

    else

    minX = -2.5; maxX = 2.5; minY = minX; maxY = maxX

    startFractal

    startDrag = false

    end

    end

    function love.mousereleased( x, y, button, istouch )

    if startDrag then

    local l

    if x > miX then mxX = x

    else l = x; mxX = miX; miX = l

    end

    if y > miY then mxY = y

    else l = y; mxY = miY; miY = l

    end

    miX = remap( miX, 0, wid, minX, maxX )

    mxX = remap( mxX, 0, wid, minX, maxX )

    miY = remap( miY, 0, hei, minY, maxY )

    mxY = remap( mxY, 0, hei, minY, maxY )

    minX = miX; maxX = mxX; minY = miY; maxY = mxY

    startFractal

    end

    end

    function love.draw

    love.graphics.draw( canvas )

    end

    Pharo

    Pharo 是 Smalltalk 的现代版变体,是一个非常高效的面向对象编程语言。事实上,Smalltalk 是面向对象的典范,几乎所有的其他面向对象编程语言都受到它的启发。却没有一个编程语言比 Smalltalk 面向对象的程度更高。

    Pharo 也是世界上最简单、最优雅的编程语言之一,你只需要 15 分钟就能掌握 Smalltalk 的全部语法。

  • 关键优势:开发效率非常高,编程效率能提升接近 5 倍。

  • 主要缺点:它需要一种与众不同的编程思维。但是人总是害怕改变,很难接受这种编程思维。

  • 分形树样本:

    Object subclass: #FractalTree

    instanceVariableNames: ''

    classVariableNames: ''

    poolDictionaries: ''

    category: 'RosettaCode'

    "Methods for FractalTree class"

    tree: aPoint length: aLength angle: anAngle

    | p a |

    (aLength > 10) ifTrue: [

    p := Pen new.

    p up.

    p goto: aPoint.

    p turn: anAngle.

    p down.

    5 timesRepeat: [

    p go: aLength / 5.

    p turn: 5.

    ].

    a := anAngle - 30.

    3 timesRepeat: [

    self tree: p location length: aLength * 0.7 angle: a.

    a := a + 30.

    ]

    ].

    draw

    Display restoreAfter: [

    Display fillWhite.

    self tree: 700@700 length: 200 angle: 0.

    ]

    "Execute"

    FractalTree new draw.

    Rust

    由于内存安全特性——借用检查器,Rust 已经赢得广泛认可。这一特性实际上消除了所有内存相关错误。Rust 提供了更安全的编程特性。

  • 关键优势:有助于提高软件的可靠性。

  • 主要缺点:它学起来很难。借用检查器比较复杂且难以理解。

  • 曼德布洛特集样本:

    extern crate image;

    extern crate num_complex;

    use std::fs::File;

    use num_complex::Complex;

    fn main {

    let max_iterations = 256u16;

    let img_side = 800u32;

    let cxmin = -2f32;

    let cxmax = 1f32;

    let cymin = -1.5f32;

    let cymax = 1.5f32;

    let scalex = (cxmax - cxmin) / img_side as f32;

    let scaley = (cymax - cymin) / img_side as f32;

    // Create a new ImgBuf

    let mut imgbuf = image::ImageBuffer::new(img_side, img_side);

    // Calculate for each pixel

    for (x, y, pixel) in imgbuf.enumerate_pixels_mut {

    let cx = cxmin + x as f32 * scalex;

    let cy = cymin + y as f32 * scaley;

    let c = Complex::new(cx, cy);

    let mut z = Complex::new(0f32, 0f32);

    let mut i = 0;

    for t in 0..max_iterations {

    if z.norm > 2.0 {

    break;

    }

    z = z * z + c;

    i = t;

    }

    *pixel = image::Luma([i as u8]);

    }

    // Save image

    let fout = &mut File::create("fractal.png").unwrap;

    image::ImageLuma8(imgbuf).save(fout, image::PNG).unwrap;

    }

    TypeScript

    TypeScript 是一个增强版的 JavaScript. 它主要新增了静态类型的特性。

    由于 TypeScript 和 JavaScript 完全兼容,已经掌握了 JavaScript 的前端 web 开发者们可以轻松掌握 TypeScript,因而深受他们青睐。

  • 核心优势:它是 JavaScript 的超集 , 对 JavaScript 开发者来说没啥太大变化。

  • 主要缺点:由于它是 JavaScript 的超级,这就导致了它同样也继承了 JavaScript 的一些历史包袱。

  • 分形树样本:

    // Set up canvas for drawing

    var canvas: HTMLCanvasElement = document.createElement('canvas')

    canvas.width = 600

    canvas.height = 500

    document.body.appendChild(canvas)

    var ctx: CanvasRenderingContext2D = canvas.getContext('2d')

    ctx.fillStyle = '#000'

    ctx.lineWidth = 1

    // constants

    const degToRad: number = Math.PI / 180.0

    const totalDepth: number = 9

    /** Helper function that draws a line on the canvas */

    function drawLine(x1: number, y1: number, x2: number, y2: number): void {

    ctx.moveTo(x1, y1)

    ctx.lineTo(x2, y2)

    }

    /** Draws a branch at the given point and angle and then calls itself twice */

    function drawTree(x1: number, y1: number, angle: number, depth: number): void {

    if (depth !== 0) {

    let x2: number = x1 + (Math.cos(angle * degToRad) * depth * 10.0)

    let y2: number = y1 + (Math.sin(angle * degToRad) * depth * 10.0)

    drawLine(x1, y1, x2, y2)

    drawTree(x2, y2, angle - 20, depth - 1)

    drawTree(x2, y2, angle + 20, depth - 1)

    }

    }

    // actual drawing of tree

    ctx.beginPath

    drawTree(300, 500, -90, totalDepth)

    ctx.closePath

    ctx.stroke

    WebAssembly

    WebAssembly 是一匹黑马。在接下来的十年左右的时间,它可能会衍生出一系列编程语言,这些编程语言有望登顶编程语言排行榜。

    虽然 WebAssembly 只是一个编译目标,但是它有充足理由被应用到 Web 领域之外。哪种基于 WebAssembly 的编程语言能够荣登榜首?谁也说不准。

    原文:

    https://hackernoon.com/programming-languages-of-the-future-b61332kd

    人工智能数学基础系列公开课通过人工智能热点问题开始,引出其中蕴涵的数学原理,然后构建解决实际问题的数学模型和方法,兼具趣味性与实用性。

    1月16日晚8:00, 哈工大屈教授在线直播课—『看得见 』的数学,带大家解密计算机视觉背后的数学知识!

    加入公开课福利群,每周还有精选学习资料、技术图书等福利发送、60+公开课免费学习

    声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

    上一篇 2020年1月11日
    下一篇 2020年1月11日

    相关推荐