-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsec-pro-language.ptx
263 lines (221 loc) · 8.26 KB
/
sec-pro-language.ptx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?xml version="1.0" encoding="UTF-8"?>
<!--*****************************************
This is part of Basic Programming
Copyright (C) 2024
Phạm Công Vinh
See the file COPYING for copying conditions.
******************************************-->
<section xml:id="sec-pro-language" xmlns:xi="http://www.w3.org/2001/XInclude">
<title>Programming Languages</title>
<objectives>
<ul>
<li>See some examples of different programming languages.</li>
<li>Learn about <term>high-level</term> and <term>low-level</term> languages.</li>
</ul>
</objectives>
<definition xml:id="def-">
<idx><h>Definitions</h><h>of programming languages</h></idx>
<statement>
<p>
<term>A programming language</term> is a system of notation that helps humans create computer programs.
</p>
<p>
Each programming language has its own set of <term>syntax</term>.
</p>
<p>
<term>Syntax</term> is simply the <q>grammar</q> of a programming language, which is crucial for the computer to understand and execute code.
</p>
</statement>
</definition>
<p>
The code cell below is written in <term>Python</term><mdash></mdash>one of the most popular programming languages in recent years. You can run the code and see the results.
</p>
<sage language="python">
<input>
print("Hello World!")
</input>
</sage>
<problem>
<pre>
Hello World!
</pre>
</problem>
<investigation>
<idx><h>Code examples</h><h>high-level</h></idx>
<idx><h>Functions</h><h>print()</h></idx>
<p></p>
<p>
The command <c>print()</c> simply puts data into the terminal. In this case, it's the words <q>Hello World!</q>.
</p>
</investigation>
<p>
<idx><h>Code examples</h><h>high-level</h></idx>
Here is another code block written in Python. (You don't have to understand what the code is doing, though it's easy to guess.)
</p>
<aside>
<title>Try It Out</title>
<p>
Copy and paste the code into a code cell and run it.
</p>
</aside>
<program language="python">
<input>
a = 0
while a < 10:
print(a, end=" ")
if a % 2 == 0:
print("is even")
else:
print("is odd")
a += 1
</input>
</program>
<p>
You can easily see that there are <term>keywords</term> such as <c>while</c>, <c>print</c> <c>end</c>, <c>if</c>, and <c>else</c>. Besides those, Python's syntax includes many keywords and features that closely resemble the English language.
</p>
<definition xml:id="def-prolang-high-level">
<idx><h>Definitions</h><h>of high-level languages</h></idx>
<statement>
<p>
Python is considered a <term>high-level</term> programming language because its <term>syntax</term> closely resembles English.
</p>
</statement>
</definition>
<p>
Therefore, Python is usually recommended to beginners, which is also why it is one of the most well-known programming languages.
</p>
<p>
<idx><h>Code examples</h><h>low-level</h></idx>
The following example is written in <term>Assembly</term>. When compiled it also outputs the words <q>Hello World!</q>. (Again, don't try to understand the code. This one is beyond even me.)
</p>
<aside>
<title>Try It Out</title>
<p>
Here's an <url href="https://onecompiler.com/assembly" visual="onecompiler.com/assembly">Assembly compiler</url> if you want to see it run.
</p>
</aside>
<program language="assy">
<input>
section .data
hello: db 'Hello World!',10
helloLen: equ $-hello
section .text
global _start
_start:
mov eax,4
mov ebx,1
mov ecx,hello
mov edx,helloLen
int 80h
mov eax,1
mov ebx,0
int 80h;
</input>
</program>
<p>
As you can see, this is very close to computer language. And Assembly needs 14 lines of code to do what Python can do with one.
</p>
<definition xml:id="def-prolang-low-level">
<idx><h>Definitions</h><h>of low-level languages</h></idx>
<statement>
<p>
Assembly is considered a <term>low-level</term> programming language since its syntax is closer to machine code.
</p>
</statement>
</definition>
<p>
In conclusion, the syntax of high-level languages is easier to understand than that of low-level ones. Maybe you'd ask <q>Then why should we use low-level languages?</q>
</p>
<p>
There're many reasons for that, and among them, speed is the most obvious. Basically, code written in high-level languages has to go through more intermediate steps to be translated into machine code (binary) than low-level ones, thus it's obvious that the latter often have a speed advantage.
</p>
<p>
Some other reasons are specialization, precise data manipulation, legacy systems, <etc />
</p>
<insight>
<idx><h>Insights</h><h>high- vs low-level</h></idx>
<p>
You can imagine a high-level programming language as a 4-seat family car, which is user-friendly and can be driven by most people. Then, a low-level one would be an F1 racing car that only the most skillful professionals can drive.
</p>
<p>
And in return, the <q>low-level</q> F1 racing car will be significantly faster than the <q>high-level</q> family car.
</p>
</insight>
<p>
However, for <term>beginner-level</term> usage, this speed advantage doesn't really matter. So, for you, high-level languages are definitely the way to go.
</p>
<note>
<idx><h>Notes</h><h>on code examples</h></idx>
<p>
In this article, code examples are written in <term>Python</term>, making it easier for you to follow and experiment.
</p>
<p>
But you can also play with other programming languages in the <xref ref="appendix-playground" text="title"></xref>.
</p>
</note>
<aside>
<title>Topic(s) you might be interested in:</title>
<p>
<ul>
<li>
<p>
<idx><h>Links</h><h>2023 survey on popular languages</h></idx>
<url href="https://survey.stackoverflow.co/2023/#section-most-popular-technologies-programming-scripting-and-markup-languages" visual="survey.stackoverflow.co/2023/#section-most-popular-technologies-programming-scripting-and-markup-languages">stackoverflow's 2023 survey on the most popular languages</url>
</p>
</li>
</ul>
</p>
</aside>
<p>
A language's syntax is developed in consideration of its <term>purpose(s)</term>. For instance, Guido van Rossum greatly prioritized readability and ease of use when he created Python. Therefore, its syntax aims to enable developers to write clear and expressive code.
</p>
<insight xml:id="insight-choose-pro-language">
<title>Choosing A Programming Language</title>
<idx><h>Insights</h><h>choosing a language</h></idx>
<p>
When getting started with programming, a beginner often comes across certain topics on the Internet:
<ul>
<li>
<q>Which programming language should I start with?</q>
</li>
<li>
<q>Which programming language should I learn in 2024?</q>
</li>
<li>
<q>Which programming language to learn for high-paying jobs?</q>
</li>
<li>
<etc></etc>
</li>
</ul>
I think these are impractical questions, and I would advise you against that mindset. Instead, you should ask questions such as:
<ul>
<li>
<q>What is my purpose in learning a new programming language?</q>
</li>
<li>
<q>For that purpose, which programming language is suitable?</q>
</li>
<li>
<q>For that purpose and considering my current level, do I want to learn a high-level or low-level language?</q>
</li>
<li>
<etc></etc>
</li>
</ul>
There's an ever-growing number of programming languages, and each of them has its own <em>purposes, pros, and cons</em>.
</p>
</insight>
<p>
<cd>
</cd>
</p>
<exploration>
<title>Basic Programming <mdash /> Part 3: Programming Languages</title>
<idx><h>Videos</h><h>part 03</h></idx>
<p>
Coming soon.
</p>
<video youtube="LQVPF1Smd_M" />
</exploration>
</section>