Skip to content

Commit 3eacef0

Browse files
authored
Merge pull request #85 from esw0624/Issue31#2
Merging Chapter 1 and 2 into an Overview
2 parents 1324a5f + 85ed8f3 commit 3eacef0

File tree

2 files changed

+187
-4
lines changed

2 files changed

+187
-4
lines changed

source/ch_1_introduction.ptx renamed to source/ch_1_overview.ptx

Lines changed: 186 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0"?>
22

33
<!-- Generated by Docutils 0.19 -->
4-
<chapter xml:id="introduction">
5-
<title>Introduction</title>
4+
<chapter xml:id="overview">
5+
<title>Overview</title>
66

77

88
<section xml:id="sec-introduction">
@@ -306,5 +306,189 @@
306306
</subsection>
307307
</section>
308308

309+
<section xml:id="why-learn-another-programming-language">
310+
<title>Why Learn another programming Language?</title>
311+
312+
<p>
313+
Python is a nice language for beginning programming for several reasons.
314+
First the syntax is sparse, and clear.
315+
Second, the underlying model of how objects and variables work is very consistent.
316+
Third, you can write powerful and interesting programs without a lot of work.
317+
However, Python is representative of one kind of language, called a dynamic language.
318+
You might think of Python as being fairly informal.
319+
There are other languages, like Java and C++ that are more formal.
320+
</p>
321+
322+
<p>
323+
These languages have some advantages of their own.
324+
First, is speed: Java and C++ code will generally give better performance than Python code. (See <xref ref="note-python-performance"/>.)
325+
Second is their maintainability.
326+
A lot of what makes Python easy to use is that you must remember certain things.
327+
For example if you set variable <c>x</c> to reference a turtle, and forget later that <c>x</c> is a turtle but try to invoke a string method on it, you will get an error.
328+
Java and C++ protect you by forcing you to be upfront and formal about the kind of object each variable is going to refer to.
329+
</p>
330+
331+
<p>
332+
In one sense Python is representative of a whole class of languages, sometimes referred to as &#x201C;scripting languages.&#x201D; Other languages in the same category as Python are Ruby and Perl.
333+
Java is representative of what I will call industrial strength languages.
334+
Industrial strength languages are good for projects with several people working on the project where being formal and careful about what you do may impact lots of other people.
335+
Languages in this category include Rust, C++, C#, and Ada.
336+
</p>
337+
338+
<p>
339+
Programming languages will always change.
340+
As the field of computer science advances there will be new programming languages and you will need to learn them.
341+
It is important to learn several programming languages so that you know what to expect.
342+
There are certain features that most programming languages have in common; variables, loops, conditionals, functions.
343+
And there are some features that are unique.
344+
If you know what is common in languages that is a good place to start.
345+
</p>
346+
<note xml:id="note-python-performance">
347+
<title>A Note about Python Performance</title>
348+
349+
350+
<p>
351+
352+
Although Python code is generally slower than Java and C++ code, in practice Python programs can achieve equivalent performance.
353+
This can be done by compiling Python code to C code (see: <url href="https://cython.org" visual="https://cython.org">Cython</url>) or by calling high-performance libraries from Python (e.g., <url href="https://numpy.org" visual="https://numpy.org">NumPy</url>, <url href="https://scikit-learn.org/stable/" visual="https://scikit-learn.org/stable/">scikit-learn</url>, etc.).
354+
So native language performance is just one criteria to consider when deciding which language to use for a program.
355+
</p>
356+
</note>
357+
358+
</section>
359+
360+
<section xml:id="why-learn-java-why-not-c-or-c">
361+
<title>Why Learn Java? Why not C or C++?</title>
362+
363+
<p>
364+
It is easier to learn to create interesting programs in Java than in C or C++, for several reasons:
365+
</p>
366+
367+
<p>
368+
<ul>
369+
<li>
370+
<p>
371+
Java includes a larger standard library than C or C++, which means that sophisticated programs can be created in Java without including external dependencies.
372+
Java has over 4,000 different classes included in the Java 14 Standard Edition.
373+
We could not begin to scratch the surface of these classes even if we devoted all of class time! However, we will cover many useful and powerful features of the Java standard library this semester.
374+
</p>
375+
</li>
376+
377+
<li>
378+
<p>
379+
Java incorporates automatic garbage collection of memory, whereas C and C++ programs typically include some degree of manual memory management.
380+
This makes programming in those languages more challenging.
381+
</p>
382+
</li>
383+
384+
<li>
385+
<p>
386+
C++&#x2019;s syntax is more complicated than Java&#x2019;s, making it more difficult to learn.
387+
For example, C++ supports a feature called operator overloading, which makes it possible to change the behavior of operators like <c>+</c>.
388+
This can make it more difficult to understand what a C++ program is doing.
389+
</p>
390+
</li>
391+
</ul>
392+
</p>
393+
394+
<p>
395+
Certainly, C and C++ are important languages, and are worth learning.
396+
But for these and other reasons, we&#x2019;ve decided to use Java for this course.
397+
Learning Java will be a good preparation for learning these and other languages!
398+
</p>
399+
400+
401+
</section>
402+
<section xml:id="learn_languages_summary">
403+
<title>Summary &amp; Reading Questions</title>
404+
<p><ol label="1">
405+
<li>
406+
<p>Learning multiple programming languages helps programmers adapt to different styles and environments.</p>
407+
</li>
408+
<li>
409+
<p>Python is a dynamic scripting language that is beginner-friendly, but it is less strict with types and generally slower than compiled languages.</p>
410+
</li>
411+
<li>
412+
<p>Languages like Java and C++ are statically typed and offer better performance and maintainability for large-scale projects.</p>
413+
</li>
414+
<li>
415+
<p>Java has a simpler syntax than C++ and includes automatic garbage collection, which reduces the complexity of memory management.</p>
416+
</li>
417+
<li>
418+
<p>Java’s extensive standard library enables the development of sophisticated programs without relying on external dependencies.</p>
419+
</li>
420+
</ol></p>
421+
<reading-questions xml:id="rqs-learnlang2">
422+
<exercise label="summary-lang-1">
423+
<statement>
424+
<p>Which of the following best describes Python as a programming language?</p>
425+
</statement>
426+
<choices>
427+
<choice>
428+
<statement><p>Statically typed and high-performance</p></statement>
429+
<feedback><p>No. This better describes languages like Java or C++.</p></feedback>
430+
</choice>
431+
<choice correct="yes">
432+
<statement><p>Dynamically typed and beginner-friendly</p></statement>
433+
<feedback><p>That’s right! Python is dynamically typed and easy for beginners.</p></feedback>
434+
</choice>
435+
<choice>
436+
<statement><p>Industrial strength and verbose</p></statement>
437+
<feedback><p>No. Python is more informal and concise.</p></feedback>
438+
</choice>
439+
<choice>
440+
<statement><p>Memory-managed and pointer-based</p></statement>
441+
<feedback><p>No. That describes lower-level languages like C or C++.</p></feedback>
442+
</choice>
443+
</choices>
444+
</exercise>
445+
<exercise label="summary-lang-2">
446+
<statement>
447+
<p>Why is Java a better language for beginners compared to C++?</p>
448+
</statement>
449+
<choices>
450+
<choice>
451+
<statement><p>It requires more manual memory management</p></statement>
452+
<feedback><p>No. Java manages memory automatically.</p></feedback>
453+
</choice>
454+
<choice>
455+
<statement><p>It has a smaller standard library</p></statement>
456+
<feedback><p>No. Java has a very large standard library.</p></feedback>
457+
</choice>
458+
<choice correct="yes">
459+
<statement><p>It avoids complex syntax and has automatic garbage collection</p></statement>
460+
<feedback><p>Correct! These features make Java easier for beginners.</p></feedback>
461+
</choice>
462+
<choice>
463+
<statement><p>It supports operator overloading</p></statement>
464+
<feedback><p>No. That's a C++ feature and it adds complexity.</p></feedback>
465+
</choice>
466+
</choices>
467+
</exercise>
468+
<exercise label="summary-lang-3">
469+
<statement>
470+
<p>What is a major benefit of learning multiple programming languages?</p>
471+
</statement>
472+
<choices>
473+
<choice>
474+
<statement><p>You can standardize all projects using one universal syntax</p></statement>
475+
<feedback><p>No. Each language has its own syntax and is suited for different tasks.</p></feedback>
476+
</choice>
477+
<choice>
478+
<statement><p>You will minimize runtime errors across all platforms</p></statement>
479+
<feedback><p>No. Runtime errors depend more on logic and environment than the number of languages you know.</p></feedback>
480+
</choice>
481+
<choice correct="yes">
482+
<statement><p>You gain exposure to different language features and paradigms</p></statement>
483+
<feedback><p>Great choice! This helps you become a more adaptable and well-rounded programmer.</p></feedback>
484+
</choice>
485+
<choice>
486+
<statement><p>You can bypass the need for understanding compilation and interpretation</p></statement>
487+
<feedback><p>No. Understanding how code is executed remains essential regardless of how many languages you know.</p></feedback>
488+
</choice>
489+
</choices>
490+
</exercise>
491+
</reading-questions>
492+
</section>
309493

310494
</chapter>

source/main.ptx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
<subtitle>The PreTeXt Interactive Edition</subtitle>
99
<xi:include href="meta_frontmatter.ptx" />
10-
<xi:include href="ch_1_introduction.ptx" />
11-
<xi:include href="ch_2_whylearnjava.ptx" />
10+
<xi:include href="ch_1_overview.ptx" />
1211
<xi:include href="ch_3_firstjavaprogram.ptx" />
1312
<xi:include href="ch_4_javadatatypes.ptx" />
1413
<xi:include href="ch_5_conditionals.ptx" />

0 commit comments

Comments
 (0)