[英]Would it be better to use Javascript or Python for calculations on my website
I am considering working on a project to emulate circuits in order to get more invested in an electronic circuits class that I am currently taking.我正在考虑开展一个模拟电路的项目,以便对我目前正在使用的电子电路 class 进行更多投资。 I have found it useful to create Python scripts to work on my homework calculations, but now I would like to make a website to share with classmates to use these scripts.
我发现创建 Python 脚本来处理我的作业计算很有用,但现在我想创建一个网站与同学分享以使用这些脚本。
From my understanding, I can run only run Javascript
on the browser and can only use Python
on the backend.据我了解,我只能在浏览器上运行
Javascript
并且只能在后端使用Python
。 I've gotten comfortable with using Python
for math and have heard that it's better in general for mathematics.我已经习惯了使用
Python
进行数学运算,并且听说它通常更适合数学运算。 In my assignments, the most that I've worked with is pi
and long floating point numbers.在我的作业中,我使用的最多的是
pi
和长浮点数。
Also as a follow-up question, could I use Flask
to run Python
in the browser?另外作为后续问题,我可以使用
Flask
在浏览器中运行Python
吗?
Thank you!谢谢!
The only case in which one would definitely be preferable to the other would be if the calculations to be performed may get very expensive, in which case it would be much more user-friendly to have the server shoulder the load, rather than having the client do it (since low-end clients may become unresponsive for too long while calculating).唯一一种肯定比另一种更可取的情况是,如果要执行的计算可能会变得非常昂贵,在这种情况下,让服务器承担负载而不是让客户端来对用户友好得多这样做(因为低端客户端在计算时可能会因为太长时间而变得无响应)。
If that's a potential issue for your case, running the expensive code on the backend would be the way to go.如果这对您的情况来说是一个潜在问题,那么在后端运行昂贵的代码将是 go 的方法。 (It doesn't have to be Python on the backend - it could even be server-side JS, or even PHP or whatever else you prefer and is performant enough for your needs.)
(后端不必是 Python - 它甚至可以是服务器端 JS,甚至是 PHP 或其他任何您喜欢的,并且性能足以满足您的需求。)
If that isn't something to worry about for your case, then feel free to choose whatever you like (calculate on the client or on the server), using whatever approach you're most comfortable with - there isn't an objective way to choose between them.如果这不是您的情况需要担心的事情,那么请随意选择您喜欢的任何东西(在客户端或服务器上计算),使用您最熟悉的任何方法 - 没有客观的方法来在它们之间进行选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.