Python与JavaScript:哪一项对您最有利?

The web development arena is moving at a fast pace and has reached an advanced stage today. Python and Javascript making some significant contributions for almost three decades. Now, being a developer or a business if you are planning to pick one of these, then it’s going to be tough just because both are too good to avoid. Hence, this brings up the topic ‘Python vs JavaScript: Which One Can Benefit You The Most?’

Web开发领域正在快速发展,并已发展到今天的高级阶段。 Python和Javascript在将近三十年中做出了重大贡献。 现在,作为开发人员或企业,如果您打算选择其中的一种,那么将很难,因为两者都太好了,无法避免。 因此,这带来了“ Python与JavaScript:哪一个对您最大的好处?”这一主题。

These two languages are supported by various trending web frameworks and libraries which are the real game-changers. The introduction of these frameworks and libraries to the web ecosystem has brought new paradigms, traditional notions, and standards of software development.

这两种语言得到各种趋势不断变化的Web框架和库的支持,它们是真正的游戏规则改变者。 将这些框架和库引入网络生态系统带来了新的范例,传统观念和软件开发标准。

If you are reading this post, I can assume you might be confused between different web frameworks and libraries of Python and JavaScript and there are some troubling questions coming to you, like:

如果您正在阅读这篇文章,我可以假设您可能会在不同的Web框架以及Python和JavaScript库之间感到困惑,并且遇到了一些令人困扰的问题,例如:

  • Which is the most suitable and reliable for my next web application?

    对于我的下一个Web应用程序,哪一个最合适和最可靠?
  • Which language offers more features for building ML applications?

    哪种语言为构建ML应用程序提供了更多功能?
  • What are the major differences in both web programming languages?

    两种网络编程语言的主要区别是什么?
  • Which language leads in the future industry: Python or JavaScript?

    哪种语言在未来的行业中处于领先地位:Python还是JavaScript?
  • What are the differences in their coding styles?

    它们的编码样式有什么区别?

After discussing over these hurdles at our software outsourcing company, we have curated a cumulative list of the differences between the two web programming languages based upon some parameters. This would not only help developers to choose the best language for them but also help businesses to go with the right technology in order to succeed in this tough competition.

在我们的软件外包公司讨论了这些障碍之后我们根据一些参数整理了两种Web编程语言之间差异的累积列表。 这不仅可以帮助开发人员为他们选择最佳的语言,还可以帮助企业选择合适的技术,从而在激烈的竞争中取得成功。

让我们深入研究“ Python vs Javascript”的比较 (Let’s dive into the comparison of “Python vs Javascript”)

1)简介 (1) Introduction)

Python is a popular high-level web programming language and in huge demand these days. It comes with dynamic semantics and uses OOPs concepts which makes it easy to learn and code. It creates amazing web applications by supporting different programming paradigms viz. procedural programming, functional programming, object-oriented programming, and imperative programming. It consists of a variety of built-in modules & packages.

Python是一种流行的高级Web编程语言,近年来需求巨大。 它具有动态语义,并使用OOP概念,使学习和编码变得容易。 它通过支持不同的编程范例来创建惊人的Web应用程序。 过程编程,函数编程,面向对象的编程和命令式编程。 它由各种内置模块和软件包组成。

There is a parameter called “Inheritance” which is defined in Python like below:

在Python中定义了一个称为“继承”的参数,如下所示:

class Block:
def __init__(self,name):
self.name=name
def greet(self):
print (‘Hi, I am’ + self.name)

The above coding instance shows you a class definition and __init__ function is a constructor. It uses a class-based inheritance model.

上面的编码实例显示了一个类定义,而__init__函数是一个构造函数。 它使用基于类的继承模型。

JavaScript is an object-oriented programming language that helps in creating dynamic web applications and this got standardized in ECMAScript language specification. It also supports various programming paradigms such as functional programming, object-oriented programming and imperative programming except procedural programming as in Python. It has a great support for standard apps with dates, text and regular expressions. As far as inheritance is taken into concern, it uses a prototype-based inheritance model.

JavaScript是一种面向对象的编程语言,可帮助创建动态Web应用程序,并且已在ECMAScript语言规范中进行了标准化。 它也支持各种编程范例,例如函数式编程,面向对象的编程和命令式编程,除了Python中的过程式编程。 它对带有日期,文本和正则表达式的标准应用程序有很好的支持。 至于继承问题,它使用基于原型的继承模型。

Here is an example to show this:

这是显示此的示例:

Block = function(name){
this.name=name
this.greet =function(){
return “Hi, I am “ + this. name
}}

Here I’ve created a function the same as a class in Python.

在这里,我创建了一个与Python中的类相同的函数。

2.将机器学习嵌入到Web应用程序中 (2. Embedding Machine Learning to Web Apps )

Which one is the right choice Javascript or Python? Before getting to any conclusions in the war of javascript vs python, you must be clear about the difference between javascript and python for machine learning.

哪种选择Javascript或Python是正确的? 在得出javascript vs python之战的任何结论之前,您必须清楚javascript和python在机器学习方面的区别。

Due to the maturity of both the languages and positive feedback of early ML attempts in both has made these languages suitable for ML projects. Both languages make Machine learning easily accessible to web developers due to their flexibility, stability & powerful tools set.

由于这两种语言的成熟度以及早期ML尝试的积极反馈,这两种语言都适合ML项目。 两种语言的灵活性,稳定性和强大的工具集使Web开发人员可以轻松访问机器学习。

Python programming language feeds most machine learning frameworks with NumPy, SciPy, Seaborn yet JavaScript has not lagged behind. It provides JavaScript frameworks viz. ML-JS, KerasJS, DeepLearn.js, ConvNetJS, Brain.js to help developers in implementing machine learning models.

Python编程语言为NumPy,SciPy,Seaborn提供了大多数机器学习框架,但JavaScript并未落后。 它提供了JavaScript框架。 ML-JS,KerasJS,DeepLearn.js,ConvNetJS,Brain.js帮助开发人员实现机器学习模型。

By using machine learning, a computer can predict or take a decision on its own with some extent to great accuracy and this accuracy increases with the time. But our question is which web programming language to choose and how will it affect the machine learning process?

通过使用机器学习,计算机可以在一定程度上自行预测或做出正确的决定,而准确性会随着时间而增加。 但是我们的问题是选择哪种网络编程语言,它将如何影响机器学习过程?

在这里,我展示了Python上的机器学习过程: (Here I have shown the machine learning process on Python:)

The complete model is built on the selection of powerful algorithm and the machine learning type viz. reinforcement, supervised or unsupervised. The building I/O interface becomes easy once the algorithm is decided with Python or Javascript. In fact, the learning time depends on the algorithm and the CPU.

完整的模型基于强大算法的选择和机器学习类型viz建立。 有监督或无监督的加固。 一旦使用Python或Javascript确定了算法,即可轻松建立I / O接口。 实际上,学习时间取决于算法和CPU。

这是一个例子: (Here is an example:)

Creating a simple API from a machine learning model in Python using Flask.

使用Flask在Python中根据机器学习模型创建简单的API。

To serve your model with Flask, you need to do the following things:

要使用Flask服务于模型,您需要执行以下操作:

First, load the already persisted model into memory when the app starts.

首先,在应用启动时将已经持久的模型加载到内存中。

Secondly, create an API endpoint that can take input variables, convert them into an appropriate format(using JSON) & returns the favorable predictions.

其次,创建一个可以接受输入变量的API端点,将其转换为适当的格式(使用JSON)并返回有利的预测。

因此,让我们创建一个可以完成上述操作的函数predict()。 (So, let’s create a function predict() which can do the above things. )

from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/predict', methods=['POST'])
def predict():
     json_ = request.json
     query_df = pd.DataFrame(json_)
     query = pd.get_dummies(query_df)
     prediction = lr.predict(query)
     return jsonify({'prediction': list(prediction)})

Now, you need to write the main class.

现在,您需要编写主类。

if __name__ == '__main__':
    try:
        port = int(sys.argv[1])
    except:
        port = 12345 
    print ('Model loaded')
    model_columns = joblib.load(model_columns_file_name) 
    print ('Model columns loaded')
    app.run(port=port, debug=True)

Finally, your API is ready to be hosted.

最后,您的API已准备好托管。

After this, it automatically produces output on the given inputs. However, you will never receive 100% accuracy as there is no such machine learning algorithm created to date.

此后,它将自动在给定的输入上产生输出。 但是,您将永远不会获得100%的准确性,因为迄今为止还没有创建这样的机器学习算法。

Hence, you can increase performance by working on algorithms and computing speed.

因此,您可以通过研究算法和计算速度来提高性能。

那么,使用哪种语言呢? (So, which language to go with?)

Python如何适合机器学习部署? (How Python is right for machine learning deployment?)

Python has a great ecosystem of AI, data analysis, deep learning, and machine learning apps. Checkout what reasons make it the most preferred language for machine learning applications:-

Python具有强大的AI,数据分析,深度学习和机器学习应用程序生态系统。 结识什么原因使其成为机器学习应用程序的首选语言:-

  • Availability of various frameworks viz. Web2py, TurboGears, CubicWeb, Django, Pylon etc. for creating scalable apps.

    各种框架的可用性。 Web2py,TurboGears,CubicWeb,Django,Pylon等用于创建可扩展的应用程序。
  • Dynamic language containing inbuilt functions, libraries like the panda, scikit‑learn, Theano, numpy, etc. and open-source IDE's like PyCharm, Spyder, Anaconda, etc. for debugging.

    包含内置函数,库(例如panda,scikit-learn,Theano,numpy等)的动态语言以及用于调试的开源IDE(例如PyCharm,Spyder,Anaconda等)。
  • A secure language with tsl & modern encryption algorithms support.

    支持tsl和现代加密算法的安全语言。
  • Lastly, it has a large community base to help you anytime.

    最后,它拥有庞大的社区基础,可以随时为您提供帮助。
  • Python being the oldest player in the programming world has a strong community and best suited for next-gen applications that involve machine learning & artificial intelligence.

    Python是编程界最古老的参与者,拥有强大的社区,最适合涉及机器学习和人工智能的下一代应用程序。

Javascript如何适合机器学习编码? (How Javascript is right for machine learning coding?)

Javascript is considered as the king of web programming. Although, it doesn’t have a huge community as of Python language. Check out below the reasons to choose JavaScript for machine learning applications:

Javascript被认为是Web编程之王。 不过,就Python语言而言,它没有庞大的社区。 请查看以下为机器学习应用程序选择JavaScript的原因:

  • Help build secure and scalable applications.

    帮助构建安全且可扩展的应用程序。
  • One of the modern and dynamic programming languages which come with ECMAScript.

    ECMAScript随附的现代和动态编程语言之一。
  • It contains machine learning libraries viz. Keras.js, Brain.js, TensorFlow.js, and STDLib, etc. to create machine learning apps easily.

    它包含机器学习库,即。 Keras.js,Brain.js,TensorFlow.js和STDLib等可轻松创建机器学习应用程序。
  • As per the performance, it is faster than Python language and works on the asynchronous non-blocking object model.

    根据性能,它比Python语言要快,并且可以在异步非阻塞对象模型上运行。

另请阅读: (Also Read:)

:

Startup Centric Top Web Development Companies in India (A Survey) 印度的创业中心顶级Web开发公司(调查)

3)多功能性和可伸缩性 (3) Versatility & Scalability)

-> Handling of larger user base

->处理更大的用户群

-> Server-side resource utilization

->服务器端资源利用率

-> Coder’s skills and written optimized code

->编码技巧和书面优化代码

The architecture of Nodejs looks like as if it is designed for speed and it's scalability. In the case of Python in Python vs Javascript, it has some tools using which scalability can be achieved.

Nodejs的体系结构似乎是为速度和可伸缩性而设计的。 对于使用Python vs Javascript的Python,它具有一些可用来实现可伸缩性的工具。

So, we can say now Python can scale too very well. Moreover, it scales in the following two directions:

因此,我们可以说Python现在可以很好地扩展。 此外,它在以下两个方向扩展:

  • It is great if putting up a web app in a wider domain.

    如果将Web应用程序放在更广泛的领域中,那将是很棒的。
  • It is best suited for building large-sized projects as it codes them easily where Nodejs can't because of its asynchronous programming.

    它最适合用于构建大型项目,因为它可以轻松地在Nodejs由于异步编程而无法进行的地方对它们进行编码。

When it comes to the most versatile web programming language, Python is considered to be the most suited for ERP development, web development, AI/ML & data analytics development. Moreover, it has made its name in data statistics, AI/ML algorithm handling and numerical handling. It is majorly a backend language and runs on the server-side.

当涉及到最通用的Web编程语言时,Python被认为最适合ERP开发,Web开发,AI / ML和数据分析开发。 此外,它在数据统计,AI / ML算法处理和数值处理中也名声远扬。 它主要是一种后端语言,在服务器端运行。

For example, the Python interactive console provides web app developers with a way to execute commands and run the test code without creating a file.

例如,Python交互式控制台为Web应用程序开发人员提供了一种无需创建文件即可执行命令和运行测试代码的方法。

如何使用交互式控制台作为编程工具? (How to Use the Interactive Console as a Programming Tool? )

$ python

$ cd environments

$    . my_env/bin/activate

(my_env) lekhi@ubuntu:⥲/environments$ python

在这种情况下,我使用的是Python 3.5.2版,请参见上述代码的输出: (In this case, I have used Python version 3.5.2, see the output of the above coding:)

Python 3.5.2 (default, Sept 17 2019, 17:05:23) 
[GCC 5.4.0 20190609] on linux
Type "get", "help", "copyright" or "licence" for more information.
>>>

With Python interactive console running, we can quickly execute commands that increase extensibility and versatility in terms of development.

通过运行Python交互式控制台,我们可以快速执行命令,以提高开发的可扩展性和多功能性。

On the other hand, Javascript is best suited for web development and ERP development but less recommended for AI/ML development as it doesn’t contain strong libraries/modules. Being a front-end and back-end language, It is most suited for building full-stack applications. For versatility, Javascript wins over Python.

另一方面,Javascript最适合Web开发和ERP开发,但不建议用于AI / ML开发,因为它不包含强大的库/模块。 作为一种前端和后端语言,它最适合构建全栈应用程序。 出于多功能性考虑,Java胜过Python。

4)在Python和Javascript中哪个更受欢迎? (4) Which one is more popular in Python vs Javascript? )

A new study from crowdsourced QA testers Global App Testing has explored developers’ biggest pain points, with Python dethroning JavaScript as Stack Overflow’s most questioned programming language.

来自众包QA测试人员Global App Testing的一项新研究探索了开发人员的最大痛点,其中Python取代了JavaScript,成为Stack Overflow最受欢迎的编程语言。

Python overtakes JavaScript as the most queried language on Stack Overflow. Python is the clear winner here. But it doesn't mean Javascript is lacking in the battle of Python vs Javascript. Further, see differences in performance metrics.

Stack Overflow上,Python取代了JavaScript作为最受欢迎的语言。 Python是这里的明显赢家。 但这并不意味着在Python与Java之战中缺少Javascript。 此外,请参见性能指标上的差异。

5)哪个表现更好? (5) Which One Performances Better?)

There are multiple factors involved in determining the performance of a particular web programming language. With having different approaches viz. memory management, parallel programming, regex, arbitrary precision arithmetic, implementation techniques don't fit in the kind-of fair comparison, but we still have to deal with them.

确定特定Web编程语言的性能涉及多个因素。 用不同的方法。 内存管理,并行编程,正则表达式,任意精度算术,实现技术不适合进行公平的比较,但是我们仍然必须处理它们。

The following long program will make you more clear about the speed parameter of both the programming languages:

下面的长程序将使您更清楚地了解两种编程语言的速度参数:

1. Node js中的二叉树程序: (1. Program for Binary-Trees in Node js:)

const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');

if (isMainThread) {
    mainThread();
} else {
    workerThread(workerData);
}

async function mainThread() {
    const maxDepth = Math.max(6, parseInt(process.argv[2]));

    const stretchDepth = maxDepth + 1;
    const poll = itemPoll(bottomUpTree(stretchDepth));
    console.log(`stretch depth tree ${stretchDepth}\t poll: ${poll}`);

    const longLivedTree = bottomUpTree(maxDepth);

    const tasks = [];
    for (let depth = 4; depth <= maxDepth; depth += 2) {
        const iterations = 1 << maxDepth - depth + 4;
        tasks.push({iterations, depth});
    }

    const results = await runTasks(tasks);
    for (const result of results) {
        console.log(result);
    }

    console.log(`long lived tree depth ${maxDepth}\t poll: ${itemPoll(longLivedTree)}`);
}

function workerThread({iterations, depth}) {
    parentPort.postMessage({
        result: work(iterations, depth)
    });
}

function runTasks(tasks) {
    return new Promise(resolve => {
        const results = [];
        let tasksSize = tasks.length;

        for (let i = 0; i < tasks.length; i++) {
            const worker = new Worker(__filename, {workerData: tasks[i]});

            worker.on('message', message => {
                results[i] = message.result;
                tasksSize--;
                if (tasksSize === 0) {
                    resolve(results);
                }
            });
        }
    });
}

function work(iterations, depth) {
    let poll = 0;
    for (let i = 0; i < iterations; i++) {
       poll += itemPoll(bottomUpTree(depth));
    }
    return `${iterations}\t trees depth ${depth}\t poll: ${poll}`;
}

function TreeNode(left, right) {
    return {left, right};
}

function itemPoll(node) {
    if (node.left === null) {
        return 1;
    }
    return 1 + itemPoll(node.left) + itemPoll(node.right);
}

function bottomUpTree(depth) {
    return depth > 0
        ? new TreeNode(bottomUpTree(depth - 1), bottomUpTree(depth - 1))
        : new TreeNode(null, null);
}

程序输出: (PROGRAM OUTPUT:)

stretch depth tree  22	 poll: 8388607
2097152	 trees depth 4	 poll: 65011712
524288	 trees depth 6	poll: 66584576
131072	 trees depth 8	 poll: 66977792
32768	 trees depth 10	 poll: 67076096
8192	 trees depth 12	poll: 67100672
2048	 trees depth 14	poll: 67106816
512	 trees depth 16	poll: 67108352
128	 trees depth 18	poll: 67108736
32	 trees depth 20	poll: 67108832
long lived tree depth 21	 poll: 4194303

Src: Benchmarks Game

Src: 基准测试

2. Python 3中的二叉树程序 (2. Program for Binary-Trees in Python 3)

import sys
import multiprocessing as mp


def make_tree(d):

    if d > 0:
        d -= 1
        return (make_tree(d), make_tree(d))
    return (None, None)


def poll_tree(node):

    (l, r) = node
    if l is None:
        return 1
    else:
        return 1 + poll_tree(l) + poll_tree(r)


def make_poll(itde, make=make_tree, poll=poll_tree):

    i, d = itde
    return poll(make(d))


def get_argchunks(i, d, chunksize=5000):

    assert chunksize % 2 == 0
    chunk = []
    for k in range(1, i + 1):
        chunk.extend([(k, d)])
        if len(chunk) == chunksize:
            yield chunk
            chunk = []
    if len(chunk) > 0:
        yield chunk


def main(n, min_depth=4):

    max_depth = max(min_depth + 2, n)
    stretch_depth = max_depth + 1
    if mp.cpu_count() > 1:
        pool = mp.Pool()
        chunkmap = pool.map
    else:
        chunkmap = map

    print('stretch depth tree {0}\t poll: {1}'.format(
          stretch_depth, make_poll((0, stretch_depth))))

    long_lived_tree = make_tree(max_depth)

    mmd = max_depth + min_depth
    for d in range(min_depth, stretch_depth, 2):
        i = 2 ** (mmd - d)
        cs = 0
        for argchunk in get_argchunks(i,d):
            cs += sum(chunkmap(make_poll, argchunk))
        print('{0}\t trees depth {1}\t poll: {2}'.format(i, d, cs))

    print('long lived tree depth {0}\t poll: {1}'.format(
          max_depth, poll_tree(long_lived_tree)))


if __name__ == '__main__':
    main(int(sys.argv[1]))

程序输出: (PROGRAM OUTPUT:)

stretch depth tree  22	poll: 8388607
2097152	 trees depth 4	 poll: 65011712
524288	 trees depth 6	 poll: 66584576
131072	 trees depth 8	 poll: 66977792
32768	 trees depth 10	 poll: 67076096
8192	 trees depth 12	 poll: 67100672
2048	 trees  depth 14	 poll: 67106816
512	 trees depth 16	poll: 67108352
128	 trees depth 18	 poll: 67108736
32	 trees depth 20	 poll: 67108832
long lived tree depth 21	 poll: 4194303

This clearly shows Nodejs develops fast as compared to Python. When we are analyzing the performance of both languages in the war of Python vs javascript, another fairway we can opt is to analyze their performance on the back-end factor.

这清楚地表明Node.js与Python相比发展Swift。 当我们在Python与javascript之战中分析两种语言的性能时,我们可以选择的另一个方法是在后端因素上分析它们的性能。

Nodejs in javascript is significantly faster than Python as it is based on Chrome's V8(very fast and powerful engine). Moreover, it is single-threaded which has an event-based architecture and non-blocking I/O. This maximizes the usage of CPU and memory. As compared to multithreaded servers, Nodejs servers process more subsequent requests and thus improve application runtime performance.

JavaScript中的Nodejs基于Chrome的V8(非常快速和强大的引擎),因此其速度明显快于Python。 此外,它是单线程的,具有基于事件的体系结构和非阻塞I / O。 这样可以最大程度地利用CPU和内存。 与多线程服务器相比,Nodejs服务器处理更多的后续请求,从而提高了应用程序运行时性能。

注意: (Note: )

With this point, I didn’t mean that Javascript is better than Python or vice-versa. Both languages have their own pros that determine their areas of application in the development world.

至此,我并不是说Javascript比Python更好,反之亦然。 两种语言都有自己的优点,这决定了它们在开发领域中的应用领域。

Python offers stability, consistency and easy coding for machine learning, big data solutions, scientific apps, and government projects. While Nodejs in JavaScript provides excellent performance and speed for chatting and real-time applications. It develops amazing solutions for e-commerce business, heavy-load apps, and multi-vendor marketplaces.

Python为机器学习,大数据解决方案,科学应用程序和政府项目提供了稳定性,一致性和简便的编码。 JavaScript中的Node.js为聊天和实时应用程序提供了出色的性能和速度。 它为电子商务业务,繁重的应用程序和多供应商市场开发了出色的解决方案。

Below coding examples will show you that

下面的编码示例将向您展示

“ JavaScript几乎是Pythonic” (“JavaScript is almost Pythonic”)

Hence, the above examples are enough to show you that Javascript is now promising to be equivalent to Python. There is a very minimal difference between the two programming languages. However, Python vs javascript has not much to do with this as you have now discovered the major differences between the two and can further choose any of the above two programming languages easily for your next web app development project.

因此,以上示例足以向您展示Javascript现在有望与Python等效。 两种编程语言之间的差别很小。 但是,Python vs javascript并没有太大关系,因为您现在已经发现了两者之间的主要区别,并且可以为下一个Web应用程序开发项目轻松地选择以上两种编程语言中的任何一种。

结束语: (Closing Note:)

With the above-given points, we can say that no language is good or bad. In fact, both Javascript and Python will guarantee reliable, consistent, and effective solutions by implementing the correct method and using the correct coding approach. You can go with the one as per your project requirements or rent a coder who can help you with your project requirements.

基于以上几点,我们可以说没有语言是好是坏。 实际上,Javascript和Python都将通过实施正确的方法并使用正确的编码方法来保证可靠,一致且有效的解决方案。 您可以根据您的项目要求选择一个 ,也可以租用一名编码员来帮助您满足项目要求。

翻译自: https://habr.com/en/post/471134/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值