Skip to content

Commit c952beb

Browse files
committed
replaced console with command-line
Signed-off-by: Konstantin Läufer <[email protected]>
1 parent bf2c559 commit c952beb

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

source/imperative.rst

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ In this section, we discuss the different options for running Scala code, includ
104104
`The list performance example <https://github.com/lucproglangcourse/cs2-listperformance-scala/blob/main/src/test/scala/cs271/lab/list/TestList.scala>`_ illustrates this approach.
105105

106106

107-
- Finally, to turn an sbt-based Scala application into a script (console application) you can run outside sbt, you can use the `sbt-native-packager <https://github.com/sbt/sbt-native-packager>`_ plugin.
107+
- Finally, to turn an sbt-based Scala application into a script (command-line application) you can run outside sbt, you can use the `sbt-native-packager <https://github.com/sbt/sbt-native-packager>`_ plugin.
108108
To use this plugin, add this line to the end of ``build.sbt``:
109109

110110
.. code-block:: bash
@@ -226,13 +226,13 @@ This approach appears to work within IDEs such as IntelliJ but not in a standalo
226226
assertEquals("hello hello", lines(1))
227227
228228
229-
The role of console applications
230-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
229+
The role of command-line applications
230+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
231231

232-
Console applications have always been an important part of the UNIX command-line environment.
232+
Command-line applications have always been an important part of the UNIX environment.
233233
Each application typically focuses on a specific task, and several applications can be composed to solve a more complex task.
234234

235-
The typical console application interacts with its environment in the following ways:
235+
The typical command-line application interacts with its environment in the following ways:
236236

237237
- *environment variables* defined in your system
238238
- zero or more application-specific *command-line arguments* for passing options to the application: ``app arg1 arg2 ...``
@@ -288,13 +288,13 @@ Similarly, we can redirect input from a file using this notation:
288288
289289
$ wc -l < testdata.txt
290290
291-
There is a close relationship between UNIX pipes and functional programming: When viewing a console application as a function that transforms its input to its output, UNIX pipes correspond to function composition. The pipeline ``p | q`` corresponds to the function composition ``q o p``.
291+
There is a close relationship between UNIX pipes and functional programming: When viewing a command-line application as a function that transforms its input to its output, UNIX pipes correspond to function composition. The pipeline ``p | q`` corresponds to the function composition ``q o p``.
292292

293293

294-
Console applications in Scala
295-
`````````````````````````````
294+
Command-line applications in Scala
295+
``````````````````````````````````
296296

297-
The following techniques are useful for creating console applications in Scala.
297+
The following techniques are useful for creating command-line applications in Scala.
298298
As in Java, command-line arguments are available to a Scala application as ``args`` of type ``Array[String]``.
299299

300300
We can read the standard input as lines using this iterator:
@@ -331,7 +331,7 @@ In Scala, ``print`` and ``println`` print to stdout, which is is an instance of
331331
This class converts any ``IOException`` to a boolean flag accessible through its ``checkError()`` method.
332332
(See also `this discussion <https://stackoverflow.com/questions/62658078/jvm-not-killed-on-sigpipe>`_ for more details.)
333333

334-
Therefore, to use a Scala (or Java) console application in a UNIX pipeline as an upstream component that produces an unbounded (potentially infinite) output sequence, we have to monitor this flag when printing to stdout and, if necessary, terminate execution.
334+
Therefore, to use a Scala (or Java) command-line application in a UNIX pipeline as an upstream component that produces an unbounded (potentially infinite) output sequence, we have to monitor this flag when printing to stdout and, if necessary, terminate execution.
335335

336336
For example, this program reads one line at a time and prints the line count along with the line read.
337337
After printing, it checks whether an error occured and, if necessary, terminates execution by exiting the program:
@@ -348,7 +348,7 @@ After printing, it checks whether an error occured and, if necessary, terminates
348348
Command-line argument parsing
349349
`````````````````````````````
350350

351-
A common concern when developing console applications is command-line argument and option parsing.
351+
A common concern when developing command-line applications is argument and option parsing.
352352
As briefly mentioned above, arguments and options are application-specific settings we can pass an application in the form ``app arg1 arg2 ...`` at the time when we're invoking the application.
353353
Importantly, these settings are separate from the application's input data.
354354

@@ -431,7 +431,7 @@ For example, we could run the application with these arguments:
431431
Determining whether an app is running interactively
432432
```````````````````````````````````````````````````
433433
434-
In some cases, it's convenient to determine programmatically whether our console app is running interactively, i.e., reading from the console, or running in batch mode, where its standard input has been redirected from a file.
434+
In some cases, it's convenient to determine programmatically whether our command-line app is running interactively, i.e., reading from the console, or running in batch mode, where its standard input has been redirected from a file.
435435
For example, if our app running interactively, we might automatically want to prompt the user for console input.
436436
437437
We can use this technique to determine whether stdin is coming from the console.
@@ -450,8 +450,8 @@ Allowing the user to edit their input
450450
`````````````````````````````````````
451451
Many REPLs, including the Python and Scala ones, allow the user to edit their input in various ways, including scrolling through the input history using the up and down arrows, adding or deleting characters from the input line, etc.
452452
453-
To add this capability to a Java- or Scala-based console app, we can use the `JLine library <https://github.com/jline/jline3>`_, which is the Java equivalent of the `GNU Readline library <https://en.wikipedia.org/wiki/GNU_Readline>`_.
454-
If you want to make your console app convenient to use and give it a professional touch, consider using JLine instead of basic console input.
453+
To add this capability to a Java- or Scala-based command-line app, we can use the `JLine library <https://github.com/jline/jline3>`_, which is the Java equivalent of the `GNU Readline library <https://en.wikipedia.org/wiki/GNU_Readline>`_.
454+
If you want to make your command-line app convenient to use and give it a professional touch, consider using JLine instead of basic console input.
455455
JLine has excellent documentation; please look there for examples.
456456
457457
.. todo:: Determine whether JLine automatically suppresses prompts when redirecting stdin.
@@ -544,7 +544,7 @@ The importance of constant-space complexity
544544
545545
Common application scenarios involve processing large volumes of input data or indefinite input streams, e.g., sensor data from an internet-of-things device.
546546
To achieve the nonfunctional requirements of reliability/availability and scalability for such applications, it is critical to ensure that the application does not exceed a constant memory footprint during its execution.
547-
*These considerations apply to any potentially long-running application, be it a console app, mobile app, or back-end service.*
547+
*These considerations apply to any potentially long-running application, be it a command-line app, mobile app, or back-end service.*
548548
549549
550550
Using iterators to represent indefinite input
@@ -595,11 +595,11 @@ When working in a command-line environment, we can also use an interactive proce
595595
.. todo:: add suitable htop screenshot
596596
597597
598-
Making console applications testable
599-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
598+
Making command-line applications testable
599+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
600600
601-
Recognizing the importance of *testability* as a static nonfunctional requirement, we'd like to make our console applications testable.
602-
While we could use command-line tools to set up automatic testing of the end-to-end functionality of our applications, we would also like to unit-test the logical functionality of our applications in isolation from input/output code.
601+
Recognizing the importance of *testability* as a static nonfunctional requirement, we'd like to make our command-line applications testable.
602+
While we could use other command-line tools to set up automatic testing of the end-to-end functionality of our applications, we would also like to unit-test the logical functionality of our applications in isolation from input/output code.
603603
604604
A key barrier to achieving this goal is the tangling (interweaving) of logical functionality and input/output in our code, i.e., there is a lack of separation of these two concerns.
605605
In particular, how can we make our code testable *without* sacrificing the important dynamic nonfunctional requirement of a constant-space memory footprint?

0 commit comments

Comments
 (0)