04-30.eri-test 试用代码

成为多语言编程的爱好者意味着经常切换语言。 重新认识特定的人需要进行简单的编程练习。 当然,我们可以打开我们喜欢的IDE并设置一个小项目。 即使只需几秒钟,也必须有一种更简单的方法,对吗?

对。

为什么不通过[RËP大号训练您的语言技能? [RËP大号是指[R埃德Ë评估-Pint大号oop, which describes pretty well how such tools work. You enter a command or an expression, which is then evaluated. If the code is valid its result is printed. Otherwise you will see an error message describing the problem. Usually [RËP大号s accumulate state, so once a variable has been defined you can inspect and alter its value. This is ideal for learning language behavior, for example how scope and visibility work.

Swift

如果您使用的是Mac,并且同时安装了Xcode和Xcode命令行工具,则只需打开终端并输入迅速。 在里面/ usr / bin。 如下面的屏幕快照所示,您可以输入要尝试的任何表达式和命令。

04-30.eri-test 试用代码

Entries are recorded in a history file and persisted through sessions (~/.lldb/lldb-repl-history). Hence, correcting a mistake is as easy as pressing the arrow-up-key. To quit the REPL, enter :q. :help prints a list of commands. For further information, take a look at the documentation provided by Apple

试用Swift的另一种方法是使用Xcode游乐场。 代码段执行后,您可以检查值。 更改不会立即生效,您需要重播更改后的行。 在输入期间执行静态代码分析,因此,如果代码无效,则会收到相应的错误消息。

04-30.eri-test 试用代码

游乐场背后的概念存在于多个IDE中。 例如,多年以来,Eclipse一直在提供所谓的剪贴簿页面来尝试Java代码。 IntelliJ具有暂存文件。 您很快就会看到它们。

Java

Java Development Kit的最新版本(实际上是从Java 9开始)附带了称为JShell的REPL。 基本用法类似于Swift REPL。 例如,您可以使用向上/向下箭头键浏览以前键入的表达式的列表。 Control-a将光标移动到当前行的开头,Control-e将光标移动到当前行的末尾。 Control-k删除(杀死)光标右侧的所有字符。

04-30.eri-test 试用代码

/救命打印命令列表。/出口退出JShell。 要获得特定命令的帮助,请使用类似/救命 save。

JShell真正的优点是您不需要提供一个托管方法或成员的类。 您可以专注于命令和表达式。 当然,完全支持类定义。 以下屏幕截图显示了如何输入类并稍后实例化对象。

04-30.eri-test 试用代码

JShell可以保存和还原会话。 这些文件由所谓的代码段(即您输入的Java代码段)组成(例如,语句,变量,方法和类定义)。/清单显示摘要列表。/编辑打开一个基本的编辑器。/下降删除一个片段。

Dart

The easiest way to try out the Dart programming language is through the so-called DartPad. Its main difference to a traditional REPL is that input is not evaluated until the Run button is pressed. So, there is no heap or stack that gets filled with the results of evaluated expressions. And there is no history. You do get results from a static code analysis while you type, though. A section of the screen provides documentation to library functions. Finally, a list of samples helps you get started with the Dart syntax.

04-30.eri-test 试用代码

Kotlin

JetBrains offers an online playground for its programming language, too. You enter your Kotlin program or choose from an extensive list of examples. After hitting the green Play button the code is executed. Static code analysis takes place during input. So issues are immediately visible in the Problems view.

04-30.eri-test 试用代码

就像DartPad一样,此在线编辑器也不是经典的REPL。 程序执行期间只有状态。 您必须提供一个入口点,在两种情况下主要()功能。

正如我已经提到的,JetBrains的IDE IntelliJ提供了类似于Xcode游乐场的功能。 暂存文件适用于多种语言。 以下屏幕截图显示了Kotlin的一张。

04-30.eri-test 试用代码

如果您停止键入两秒钟,则所谓的交互模式将运行暂存文件。 名为“使用REPL”的复选框仅执行已添加到临时文件末尾的新表达式。

Summary

游乐场和REPL是学习编程语言的语法和功能的理想之选,因为它们使您从设置项目和编写样板代码的工作中解脱出来。 因此,它们是多语言程序员的重要工具。 当然,其他语言也有其REPL。 将来的帖子可能正在讨论它们。 同时,请随时分享您对REPL的使用的想法和意见。

from: https://dev.to//tkuenneth/trying-out-code-2ng4