对于在Windows和OS X上运行的程序,最好使用哪种编程语言? [英] For a program to be run on Windows and OS X, what programming language(s) is best to use?

查看:101
本文介绍了对于在Windows和OS X上运行的程序,最好使用哪种编程语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个在Windows或OS X上运行的工程计算程序。我打算在MS Word中使用/访问它,并在那里定义和运行模块。计算的代码可能很广泛,但我需要界面与Word无缝,所以当计算完成后,完整的报告就准备好了。



什么编程语言(s )你认为这会使这项工作对UI最有效和最好吗?

解决方案

这不是关于语言,而是关于技术。



为什么?首先,您需要意识到一件您似乎没有意识到的重要事情: Windows和Mac OS X上没有可执行模块可以本地运行 。这里的关键词是本地。我的意思是,您需要了解本机代码的编程是如何完成的:您可以开发一些程序并编译/链接它,获取用CPU指令编写的二进制代码,可执行模块。然后,在其核心安装中有一些操作系统,没有任何附加层,您可以获取已编译的代码并在此系统上进行复制。它仅在代码针对兼容的操作系统时才有效。



例如,您可以开发可在多个不同Windows版本上运行的Windows代码。但不是在Mac OS X上。反之亦然。甚至你的目标是相同的CPU,而且这些CPU在两个操作系统上都使用相同的CPU。 在这方面,这些操作系统没有任何共同点。代码需要重新编译。即使这样,由于不同的平台API,它也不会不兼容。只有最简单的仅控制台代码才能直接重新编译,以便两个平台本机运行。然而,跨平台开发仍然存在问题。在两个系统上都需要一些抽象层,一些平台单独开发并在两个系统上移植。您的代码应该为此抽象层开发,而不是专门针对核心操作系统。



另请参阅Richard MacCutchan对问题的评论。

因此,我们需要讨论一些非原生的跨平台编程方法。



非原生:P代码



首先,让我们探索非本地的可能性。我将它们分为两个主要方法:系统使用 p代码(字节代码)和使用脚本(解释)语言的系统。您可以在此处找到基于p代码的系统信息: https://en.wikipedia.org/wiki/Bytecode [ ^ ]。



到目前为止,两个使用最广泛的系统是JVM和CLR。 JVM几乎适用于所有现代操作系统,CLR由.NET和Mono for Windows以及Mono for Mac OS X表示。旗舰语言是Java和C#,但有一大堆不同的语言提供相同的p代码,JVM的Java字节代码或CLR的CIL。请参阅:

https://en.wikipedia.org/wiki/Java_virtual_machine [< a href =https://en.wikipedia.org/wiki/Java_virtual_machinetarget =_ blanktitle =New Window> ^ ],

https://en.wikipedia.org/wiki/Java_virtual_machine [ ^ ],

https://en.wikipedia.org/wiki/Java_%28programming_language%29 [ ^ ];

https:// en .wikipedia.org / wiki / Common_Intermediate_Language [ ^ ] ,

https://en.wikipedia.org/wiki/.NET_Framework [ ^ ],

https://en.wikipedia.org/wiki/Mono_%28software%29 [ ^ ],

https://en.wikipedia.org/wiki/Common_Intermediate_Language [ ^ ]。



针对不同操作系统的这些平台的实现之间的兼容性问题可能是无休止讨论的主题,但是通常,如果您以跨平台方式编写代码,而不是直接使用任何特定于操作系统的功能,您将获得可以直接执行的程序tly在不同的操作系统上执行,无需重新编译



非原生:脚本



现在,让我们讨论基于解释语言的脚本的技术 https ://en.wikipedia.org/wiki/Interpreted_language [ ^ ]。

正如你所看到的,它们中有太多,很多人都可以在这里查看。除了一个:JavaScript。为什么?正如您应该理解的,在这种情况下,抽象层将是一些运行时引擎解释和执行代码。在所有通用操作系统上只使用一个引擎:嵌入在浏览器上的JavaScript引擎。你可以做一般的软件开发基础吗?当然是。一个常见的误解是JavaScript和浏览器本身仅适用于Web。事实并非如此:您可以开发和运行完全独立于Web的代码。毕竟,请看两篇文章中的几个例子:

俄罗斯方块画布 [ ^ ],

JavaScript Calculator [ ^ ]。



Web因素是导致事务状态的最有力因素,其中JavaScript是此类产品中最稳定和标准化的语言: https ://en.wikipedia.org/wiki/ECMAScript [ ^ ]。



两个不仅仅基于常用浏览器的有趣例子是Chrome OS和d Apache Cordova:

https://en.wikipedia.org/wiki/Chrome_OS [ ^ ](抱歉此示例与Windows和Mac无关) ,

https://en.wikipedia.org/wiki/PhoneGap [ ^ ],

https://cordova.apache.org [ ^ ]。



其中一个限制是文件存储I / O,但这个问题是可以解决的:

http://en.wikipedia.org/wiki/Web_storage [ ^ ],

https://developer.mozilla.org/en-US/Add-ons/Code_snippets/File_I_O [ ^ ]。



原生:重新编译, OS和UI抽象层库



最后,让我们快速探索本机代码中编译的编译语言。在这种情况下,抽象层将是一些操作系统抽象层,它主要应该涵盖一个在兼容性方面最有问题的东西:UI。这个抽象层可以只是在两个操作系统上实现相同API的库。



再次,它不可能讨论所有可能性,但我只强调两个:免费Pascal和C ++。



免费的Pascal是开源的,可以使用在许多平台上实现的IDE开发,Lazarus。 Lazarus带有出色的跨平台UI库。请参阅:

https://en.wikipedia.org/wiki/Free_Pascal [< a href =https://en.wikipedia.org/wiki/Free_Pascaltarget =_ blanktitle =New Window> ^ ],

https://en.wikipedia.org/wiki/Lazarus_(IDE) [ ^ ]。



这是我的最爱这种跨平台产品的例子,仍然处于测试版和积极开发阶段。你甚至可以享受它;它实际上非常有用:

https://en.wikipedia.org/wiki/Double_Commander [ ^ ],

http://doublecmd.sourceforge.net/ [ ^ ]。



最后,关于C ++中的跨平台开发;请看我过去的答案:

针对目标操作系统Windows和Linux的Visual Studio应用程序 [ ^ ],

如何将Visual Studio C ++编译为linux和os-mac [ ^ ],

这个绘图程序win32的问题是什么 [ ^ ],

写c / c ++可视化程序(跨平台)与IDE和编译器一起使用? [ ^



祝你好运,

-SA

I am looking at writing a program for engineering calculations run on either Windows or OS X. I intend it to be used/accessed in MS Word with modules being defined and run from there. The code for calculations could be extensive but I need the interface to be seamless with Word so when the calculations are finished a complete report is ready.

What programming language(s) do you think would make this job the most efficient and good for a UI?

解决方案

This is not about language, but about technology.

Why? First of all, you need to realize one important thing you don't seem to realize: no executable module can run natively on both Windows and Mac OS X. Key word here is natively. I mean, you need to understand how programming of native code is done: you can develop some program and compile/link it, get binary code written in CPU instructions, executable module. Then, having some OS, in its core installation, without any additional layers, you can take your compiled code and copy on this system. It will work only if the code is targeted to a compatible OS.

For example, you can develop Windows code which will run on several different Windows versions. But not on Mac OS X. And visa versa. Even of you target identical CPU and those are exact the same CPU uses on both OS. In this aspect, these OS have nothing in common. The code will need recompilation. And even then it cannot be incompatible, due to different platform API. Only the simplest console-only code could be recompiled directly for two platforms to run natively. And yet, cross-platform development, being problematic, is still possible. You need some abstraction layers on both systems, some platforms developed separately and ported on both systems. Your code should be developed for this abstraction layer, not specifically for core OS.

See also the comment to the question by Richard MacCutchan.
So, we need to discuss some non-native approach to cross-platform programming.

Non-native: P-code


First of all, let's explore non-native possibilities. I would classify them into two major approaches: system working with p-code ("byte code") and systems working with scripting (interpretive) languages. You can find the information on the systems based on p-code here: https://en.wikipedia.org/wiki/Bytecode[^].

By far, two most widely used systems are JVM and CLR. JVM is implemented for nearly all modern OS, and CLR is represented by .NET and Mono for Windows, and Mono for Mac OS X. The flagship languages are Java and C#, but there is a big set of different languages giving equivalent p-code, Java byte code for JVM or CIL of CLR. Please see:
https://en.wikipedia.org/wiki/Java_virtual_machine[^],
https://en.wikipedia.org/wiki/Java_virtual_machine[^],
https://en.wikipedia.org/wiki/Java_%28programming_language%29[^];
https://en.wikipedia.org/wiki/Common_Intermediate_Language[^],
https://en.wikipedia.org/wiki/.NET_Framework[^],
https://en.wikipedia.org/wiki/Mono_%28software%29[^],
https://en.wikipedia.org/wiki/Common_Intermediate_Language[^].

The issues of compatibilities between implementations of these platforms for different OS could be a topic of endless dis discussions, but generally, if you write your code in cross-platform manner, not directly using any OS-specific features, you will get the programs which can be directly executed on different OS, without recompilation.

Non-native: scripting


Now, let's discuss the technologies using scripting based on interpreted languages: https://en.wikipedia.org/wiki/Interpreted_language[^].
As you can see, there are too many of them, to many to review any here. Except just one: JavaScript. Why? As you should understand, the abstraction layer in this case would be some run-time engine interpreting and executing the code. There is just one engine used on all general-purpose OS: JavaScript engine embedded on browsers. Can you do general software development bases on this? Yes, of course. One common misconception is that JavaScript and the browser itself is only for Web. This is not so: you can develop and run code totally independent from Web. After all, look at a couple of examples in two my articles:
Tetris on Canvas[^],
JavaScript Calculator[^].

The "Web factor" is the most powerful factor which lead to the states of affairs where JavaScript is the most stable and standardized language in this class of products: https://en.wikipedia.org/wiki/ECMAScript[^].

Two interesting examples not based on just the common-use browsers are, say, Chrome OS and Apache Cordova:
https://en.wikipedia.org/wiki/Chrome_OS[^] (sorry that this example is unrelated to both Windows and Mac),
https://en.wikipedia.org/wiki/PhoneGap[^],
https://cordova.apache.org[^].

One of the limitation is file storage I/O, but this problem is solvable:
http://en.wikipedia.org/wiki/Web_storage[^],
https://developer.mozilla.org/en-US/Add-ons/Code_snippets/File_I_O[^].

Native: recompilation, OS and UI abstraction-layer libraries


And finally, let's quickly explore the compiled language compiling in native code. The abstraction layer in this case will be some OS abstraction layer, which mostly should cover one thing most problematic in terms of compatibility: the UI. This abstraction layer can be just the library with the same API implemented on both OS.

Again, its impossible to discuss all possibilities, but I would emphasize just two: Free Pascal and C++.

Free Pascal is open-source and can be developed with the IDE implemented on many platforms, Lazarus. And Lazarus comes with excellent cross-platform UI library. Please see:
https://en.wikipedia.org/wiki/Free_Pascal[^],
https://en.wikipedia.org/wiki/Lazarus_(IDE)[^].

This is my favorite example of such cross-platform product, still in beta and active development. You can enjoy it even now; it's actually very useful:
https://en.wikipedia.org/wiki/Double_Commander[^],
http://doublecmd.sourceforge.net/[^].

And, finally, about the cross-platform development in C++; please see my past answers:
Visual Studio Application for Target OS Windows and Linux[^],
How to Compile Visual studio C++ to linux and os-mac[^],
What`s the Problem with this Plot Program win32[^],
writing c/c++ visual programs (cross-platform) with which IDE and compiler?[^.

Good luck,
—SA


这篇关于对于在Windows和OS X上运行的程序,最好使用哪种编程语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆