SYNTAX: To achieve the term “language” for Programming.
Recognizing my distance from being a linguist, I find myself seeking guidance in the endeavor of designing a programming language for robotics education, centered on a small embedded system. This quest compels me to consult experts for insight. A “language,” by definition, must possess essential components. These include precise rules, principles, and unique conventions that are rigorous and well-defined. I surmise that the inherent complexity of such a language must be manageable, prompting me to humbly seek enlightenment rather than undertaking a formal training regimen with a structured curriculum.
The questions that arise in this pursuit span multiple topics and aspects, demanding comprehensive explanations from knowledgeable experts. Their insights and guidance ensure that the seemingly insurmountable challenges do not become insurmountable obstacles.
Following the question, “What defines a language?” the expert provided this explanation:
The term “language” refers to a system or method used by humans to communicate, which can take the form of speech, writing, or symbols. Language serves to exchange information, ideas, emotions, and meanings. It comprises several core components, such as grammar, morphology, phonetics, or agreed-upon symbols. Additionally, languages are often categorized by grammatical or phonetic structure, for example, Thai, English, and Japanese.
Languages are not limited to human communication; they also include forms used in technology, such as computer languages. These consist of sets of rules for writing programs and issuing commands to computers.
Languages can be broadly categorized into types, such as:
Human Languages: Used for general communication, such as Thai, English, or Chinese.
Technical Languages: Used in specialized fields, such as programming languages (e.g., Python, JavaScript) or symbolic languages in mathematics.
It seemed as though the wise one had foreseen the inevitable question that would follow — one about languages meant for beings other than humans. This clairvoyance, perhaps, stemmed from the prolonged exchange of dialogue that had unfolded over time.
“One who is known too well by another — could they still conceal what they wish to keep hidden?” the sage asked, their gaze piercing yet calm. “Tell me, does such a notion bring you joy or unease?”
“Not joy,” came the resolute reply. “Not at all!”
The next request for guidance turned to the subject of technical languages. After many successive discussions, it was concluded that computer languages, or programming languages, must adhere to strict and well-defined rules and structures. A crucial requirement is syntax, which linguistic experts refer to as syntactic structure. Clearly established rules leave no room for ambiguity, ensuring that both machines and humans can understand the intent and execute instructions accurately and correctly.
Thus, today’s discourse focuses solely on the details of syntax. The key components are:
◙ Order of Commands : In programming, commands must be written in a proper sequence to ensure the program operates as intended. An incorrect order can result in malfunctioning or errors. Python, for instance, follows a line-by-line execution model, where commands are read from top to bottom. It is not only crucial to choose the correct commands but also to arrange them in the right order for the program to function correctly.
◙ Operators and Symbols : Technical languages utilize operators and symbols, such as +
, -
, =
, {}
, []
, and ()
, each with specific meanings. Commands involving these symbols must be written correctly according to the rules to avoid repetitive mistakes.
For example, in Python, assignment and comparison use similar-looking operators: =
for assignment and ==
for comparison.
- The statement
a = 10
assigns the value10
toa
. Regardless of whethera
existed previously or what its previous value was, this command setsa
to10
. - In contrast,
a == 10
compares the current value ofa
to determine if it is equal to10
.
If a = 10
is executed, a
will hold the value 10
. However, the comparison a == 10
does not change the value of a
; it simply checks if the value of a
is 10
and evaluates to True
if it is, or False
otherwise. If a
has not been defined beforehand, the comparison will result in an error.
◙ Variables and Naming Conventions : Variables and naming conventions are fundamental to technical languages, particularly in programming. A program requires storage spaces for data, and interacting with these spaces is done through references to their names. When these names are associated with entities that can change their values, they are called variables, reflecting their inherent characteristic of not being constant.
Good naming conventions greatly influence the readability and comprehension of code. A well-thought-out naming approach makes code intuitive and self-explanatory, reducing errors, particularly in complex codebases, and minimizing confusion for others who may need to review or modify the code in the future.
A variable acts as a named container for data, providing programmers with three key capabilities:
- Storing Data: Variables can hold various types of information needed by the program, such as numbers, text, or logical values.
- Accessing Data: They allow for easy retrieval and reuse of stored data across multiple parts of the code without the need to recreate it.
- Modifying Data: Variables enable easy updates or changes to the stored values whenever necessary.
In this way, variables serve as essential tools for organizing and managing data efficiently in a program.
“A programmer of such skill, one might liken them to a deity, once made me realize that the way one names their variables can subtly reveal fragments of their character.”
◙ Data Types
Data types refer to the categories of data used in programming, defining the nature and structure of the information that variables or values in a program store and process. Data types play a crucial role in how code functions and processes information, as each type has unique uses and limitations. Understanding data types allows programmers to choose appropriate data, reduce errors, and optimize the efficiency of their code. Common fundamental data types include:
♦ Numbers : Numerical data can be represented in several forms, such as:
- Integer: Whole numbers without decimal points, such as
-3
,0
, or3
. Integers are used for counting, addition, subtraction, multiplication, division, or other operations that do not require decimal precision. - Floating Point: Numbers with decimals, such as
3.14
,-2.718
, or0.0001
. Floating-point numbers are useful for applications that require a higher level of precision than integers, such as scientific calculations, mathematical operations, financial computations, or fractional measurements. - Complex Numbers: Numbers comprising two main parts — a real part and an imaginary part — expressed as
a + bi
, wherea
is the real part andb
is the imaginary part. The imaginary uniti
is defined by i×i=−1i \times i = -1i×i=−1. Complex numbers are widely used in scientific fields, especially in physics and engineering, where they are essential for analyzing waves, electrical circuits, and signal processing. Their representation of magnitude and phase simplifies calculations in these domains. - Strings : Strings are sequences of characters arranged in a continuous order. In most programming languages, such as Python, C, Java, or JavaScript, strings are enclosed in quotation marks, which can be single (
' '
) or double (" "
). Each character in a string can include letters, numbers, and symbols, such as commas, periods, or underscores. Strings are used to store textual data, words, and special characters. Examples of strings include'Hello'
,'12345'
, and"Temperature: 25°C"
.
♦ Boolean: Boolean data types represent values with only two possible outcomes: True or False. These values are fundamental in logic, condition checking, and program control. In computing, Booleans are a basic data type with significant importance, often used in decision-making and comparisons.
- True indicates that a value or condition is true.
- False indicates that a value or condition is false.
Boolean values can be combined with various operators to check conditions or perform logical computations:
- AND: Returns
True
if both values areTrue
. - OR: Returns
True
if at least one value isTrue
. - NOT: Returns the opposite of the given value.
These operators and Boolean logic are widely used to control program flow and implement decision-making processes.
Boolean values are often used to compare data in various forms, such as checking if values are equal, greater than, or less than using comparison operators. For example:
- Equal to: The
==
operator checks if the two values on the left and right of==
are equal. - Not equal to: The
!=
operator checks if the two values on the left and right of!=
are not equal. - Less than: The
<
operator checks if the value on the left is less than the value on the right.
Boolean values are used in program control to decide whether a command or block of code will be executed based on whether the condition is true or false. These values can be used in commands such as if
, while
, and for
to determine the sequence of operations in a program. For example, the if
statement checks whether a condition (which will later be referred to as a Boolean expression) evaluates to true. If the condition is true, the program will proceed to execute the statements within the block of the if
statement. If the condition is false, the program will skip the block and may execute an alternative block of code, indicated by the else
statement, which provides the alternative action when the if
condition is not met.
- Sequence: A sequence is a data structure used to store a collection of items arranged in a specific order. This allows for accessing each item based on its position or index. A sequence can consist of items of the same type, such as a set of numbers or strings, which is called Homogeneous, or it can contain a mix of different types, such as some items being numbers and others being strings, which is called Heterogeneous. Storing data in a sequence is particularly useful when processing multiple items at once, such as using a loop (for loop) to iterate through all the data in the sequence or using commands to calculate sums, products, or sort the data.
In modern technical language, additional data types have been introduced, such as Set, which is used when there is a need to store unique data. This means that if an attempt is made to insert duplicate data into a set, it will be ignored and not added again. Data in a set is unordered, meaning it cannot be accessed using an index, and the data will be automatically sorted when added. The sorting order of a set does not depend on the order in which the data is inserted, so it is not possible to reference data in a set by index or specific position. This feature improves the efficiency of checking whether a certain piece of data exists in a set. In some languages, such as Python, there is a data type called None, which represents the absence of data, meaning “empty” or “null,” and is used to indicate that a variable does not hold any meaningful value.
Moreover, data can also exist in the form of Compound Data Types, which combine multiple basic data types or data collections into a single structure. Basic data types include Number, String, Sequence (which may exist in various forms), Boolean, Set, and None, allowing for the easier storage of complex and multi-dimensional data. These compound data types are often used in programs that handle multiple types of data or when data needs to be stored in a more organized format.
Although compound data structures may seem complex and not straightforward, with each piece of data having a different format, they provide flexibility in storing related multi-dimensional data. For example, they allow for easy storage of information about multiple users in a system, making it simple to read and access the data as needed, without the need to create a new structure.
◙ Code Structure and Blocks : Refers to the organization of instructions and the structure of code in a logical sequence, making it easier to read and understand the program’s functionality. This helps readers or those wishing to modify the code to better comprehend the sequence of operations. Organizing code in a clear and systematic way reduces errors in programming and makes the debugging process easier.
The organization of code structure and blocks includes:
- Blocks refer to groups of instructions that work together to produce the desired result. For example, an
if
block for conditional operations,for
andwhile
loops for iterative operations, or function blocks for specific tasks. In many programming languages, block boundaries are defined by indentation (as in Python) or curly braces{}
(as in C, C++, or Java). - Indentation is used to indicate the boundaries of a block of code, especially in languages like Python, where indentation is not only for readability but also for defining the formal scope of a block. Consistent indentation improves code clarity and organization.
- Functions are used to define specific actions or tasks, which help break down the code into smaller, understandable sections. Functions also reduce code repetition by allowing the reuse of code in multiple parts of the program, making the code more concise.
- Modularization involves breaking down code into modules or smaller units that can operate independently. For example, code related to calculations, database management, or user interface handling can be separated into distinct modules. Each module can operate independently and be reused in other programs. Modularization makes the code more readable and understandable, as each module has a clear purpose. Additionally, modules can be independently tested, which simplifies debugging and program maintenance. The ability to modify or add features to a specific module without affecting the rest of the program improves flexibility.
In a program that handles user data, there might be separate modules responsible for various tasks, such as:
- Database Module: Responsible for connecting to a database, retrieving, and sending data. Functions in this module could include connecting to the database and adding new records.
- Validation Module: Validates data before sending it to the database, such as checking if the data format is correct (e.g., verifying email addresses or password complexity).
- Display Module: Displays information to the user, such as showing user details retrieved from the database.
- Comments are used to explain the functionality of various parts of the code. They help readers and the original coder understand the purpose of the code more easily in the future. Comments do not affect the program’s operation. Comments should be concise, clear, and directly related to the functionality being described.
- Control Structures refer to mechanisms in programming languages that control the flow of the program according to specific conditions or repetitive tasks. Control structures help programs respond flexibly to different conditions, making the code more systematic. Control structures are generally categorized into three main types:
- Selection Structures: Used to control the flow based on conditions (e.g.,
if
,else
statements) to make decisions in the program. - Loop Structures: Control repetitive tasks based on conditions or a specific number of iterations (e.g.,
for
,while
loops). - Jump Statements: Allow the program to skip or exit certain parts of the structure immediately without completing all instructions. Examples include
break
(to stop a loop or condition and exit immediately),continue
(to skip the current iteration and move to the next one), andreturn
(to return a value from a function and stop its execution).
These rules, principles, and guidelines ensure that technical languages are clear, helping machines interpret and understand the code as intended by the programmer. They also make it easier for the code’s writer and readers to write, read, and understand the code, facilitating efficient development and maintenance of software.
===============================================================
“Domus leges domus habet, civitas leges civitatis habet, et lingua programmatis similiter.”
“Every house has its own rules, every city has its own laws, and programming languages are no different.”
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Naturvirtus
XX Novembris MMXXIV