Introduction to Programming

Share this post:

Basics

  • A computer handles data i.e it operates as a data handler.
  • Computer hardware needs to be instructed on how to operate. This set of instructions is called a program. This means that a program controls the hardware of the computer. This program is also called software.
  • The art of writing a program is called programming or coding, and what is written is called the code. Thus, the code is the basic unprocessed program that cannot execute any task unless it undergoes conversion, either through a process of compilation or code interpretation.
  • In the program, the instructions command the computer on how to perform a task. This creates an ordered set of sequential tasks that the hardware must perform in order to complete a job.

Phases of Software Development

  • There are four phases of software development.
  • These phases can be structured using the waterfall model, iterative model, or the agile model.
  • The 4 phases are:
    • Analysis – The developer decides what the program can do, its functions, and its capabilities.
    • Design and Plan – The focus here is on the decision of how the program is to be created and operated by the end user. It requires the developer to choose a programming language, sketch an interface, and design its database.
    • Build – The software is created and its user documentation is written.
    • Test – Software is run to check its operations and debug its code. There are 4 types of tests:
      • Unit Test – It checks individual functions.
      • Function Test – It checks individual components.
      • Integration Test – It checks whether the components work together as expected.
      • System Test – It checks the entire software in a working environment or system.
Final software product ready for use by the end user. PHOTO CREDIT.

What is a Programming Language?

  • The set of words, numbers/numerals, and symbols used to write a program constitute the programming language.
  • If the language requires the person writing the program (the programmer) to have a deep understanding of computer knowledge, and the program is optimized to work on only specific computer hardware, then this language is defined as a low-level language. The program created usually has direct control of the hardware and its functionalities.
  • If the language allows the programmer who has little understanding of computer hardware to write a program that can be run on almost any computer hardware, then this language is called a high-level language. It can be written quickly and is easy to understand.
  • The low-level language is used to create a low-level code that the microprocessor can understand as a set of instructions, and this code is called the machine code.
  • The machine code is usually a collection of bits – sets of 1 and 0 – that the processor can read, interpret, execute, and process to generate an output. This code is comprised of two parts:
    • Opcode – This is the set of instructions.
    • Operand – This specifies the data to be used by the processor.
  • A program written in a high-level language needs to be translated into machine code for it to be executed by the processor. When the program is running, the interpreter performs this translation and execution. The compiler translates the program before it is run. This is the principal functional difference between a compiler and an interpreter.
  • A program is written in a code editor, which can have productivity features such as color coding and autocomplete for instructions.
  • If this code editor is combined with a debugger, compiler, and interpreter into a single set of tools for creating, testing, and running programs; then this set (of tools) is called the integrated development environment (IDE).

Classification of Programming Languages

  • Programming languages can be classified into the following types:
    • Imperative Programming – It requires the program to provide detailed step-by-step instructions on how the program is to be run by the processor so as to complete a task. Examples of imperative programming languages are Java, C, and C++.
    • Declarative Programming – The programmer instructs the program on what output to provide without instructing the program on what to do to achieve this output. Two examples of declarative programming languages are Structured Query Language (SQL) and Wolfram Language.
    • Event-driven Programming – The program waits for an event (such as user action or sensor input) to happen, and then executes a specific program sequence. Examples of event-driven programming languages are Scratch and JavaScript.
    • Procedural Programming – The program has distinct functions, with each function reusing chunks of instruction sets. A function can start another function, and even restart itself. Examples of procedural programming languages are Python and Java.
    • Object-Oriented Programming – In this program, the data and instructions related to its (data) processing are bundled together into objects, and each object can interact with other objects. As expected, the objects contain the data, related instruction sets, and interfaces for communicating with other objects. Examples of object-oriented programming languages are Python, C++, and Javascript.
    • Visual Programming – The programming language uses a drag-and-drop interface to create software. An example of this language is Visual Basic.

Conceptual Categorization of Programming Languages

  • Programming is guided by 2 related precepts:
    • There is always an easier way to solve a problem. This means that the procedure of solving a problem so be simple and straightforward.
    • Keep it (the program) simple. The program should be able to execute its functions using the minimal computing resources possible.
  • Programming languages can be categorized conceptually into 3 groups:
    • Multipurpose Language versus Domain-Specific Language: A multipurpose programming language – e.g C – can be used to create different types of programs e.g desktop programs, mobile applications, and web applications; while a domain-specific language e.g CSS, XML, SQL, and HTML e.t.c is only used to for one specific purpose e.g CSS for styling HTML webpages.
    • Single-Paradigm Language versus Multiparadigm Language: A paradigm is the philosophy, method, or approach to solving a problem. Each paradigm has its own mode of thinking and way of expression. A programming language can be created to solve problems using a specific paradigm, but still allow other paradigms to be used to execute its algorithm, and this is called a multiparadigm language. The single-paradigm programming language is created to solve problems using a specific paradigm and only this paradigm can be used during the development and execution of the program.
    • Strongly-typed Language versus Weakly-typed Language: A strongly-typed language requires the type to be declared before it is run e.g C# and C++. It is also described as a Staticallytyped language. A weakly-typed, or dynamically-typed language, does not require the data type to be declared e.g JavaScript and Python.
  • The programming language used to write the source code is called the source code language.
  • The source code is converted into machine code using a translator. Because the source code is written in a specific programming language, its translator is called a language translator.
  • There are 3 types of translators which give rise to 3 types of programming languages:
    • Interpreted Language: The translator converts the code line-by-line with the computer executing the program in this manner. PHP and JavaScript are interpreted languages.
    • Compiled Language: The entire source code is converted into machine language at once through a process called compilation. C++ and C are compiled languages.
    • Mixed Language: The source code is compiled into an intermediate language, and this compiled code is then converted into machine code. Java and C# are mixed languages.

Process of Program Development

  • The process of creating a program consists of the following steps:
    1. Elaboration of the problem.
    2. Creation of an algorithm in pseudo-code. The algorithm is the sequential process that the program is to use to solve a problem.
    3. Editing the program in the code editor.
    4. Program compilation.
    5. Linkage of the compiled program with external files and/or modules depending on references made in the program source code.
    6. Creation of an executable file that is the final program.
      • Program execution enables one to determine if the program is working correctly. It also allows for the revelation of runtime errors or improper functionality.
      • Debugging allows for the correction of runtime errors and improper functionality, with this correction done by re-editing the source code in the code editor. After debugging, the program is executed again, and if everything is fine, the program goes to the next step.
    7. Exploitation Phase: The program is tested by executing it in a real environment that mimics how the user will use the program.
    8. Program release for real-world usage.
    9. Program Maintenance: In this maintenance phase, the functionality of the program is improved and optimized for the end users.

Components of a Program

  • The main parts of a program are:
    • Comments.
    • Preprocessing directive.
    • Main functions. In the C programming language, the function in the program is enclosed/wrapped by curly brackets/braces {}.
    • Keywords.
    • External functions.
    • Control characters.

What is a Variable?

  • A variable is a memory area in a program that can be referenced in this program. Each variable is given a name that serves as its identity. This name must start with a lowercase letter, and can be a combination of letters and numbers. Each named variable can store a value that can be referenced to in the program.
  • There are different types of variables:
    • Whole variable INT – This is used to store whole numbers.
    • Real variable FLOAT – Used to store a decimal number.
    • Character variable CHAR – Used to store only a single character.
  • A variable is assigned a value using the EQUALS TO operator (=) in the following manner:

Variable = value;

  • The semicolon (;) is a control character that indicates an end to a statement or command.
  • The variable type can be converted to another type e.g convert an INT variable to a FLOAT variable. This is called type conversion.
  • There are two forms of this type conversion:
    • Implicit Conversion: It is normally done by the compiler. This form of type conversion is described as coercion or automatic type conversion.
    • Explicit Conversion: The programmer defines how the data type is to be converted and is thus described as type casting. Type casting allows for bidirectional conversion between lower data types and higher data types.
  • A special type of variable is the pointer which is a variable that stores the physical address of another variable, thus allowing the stored variable to be accessed indirectly.

Logical Comparisons, Relational Operators, and Logical Operators

  • Logical comparisons allow for one option to be selected from multiple options for execution. This selection is dependent on input (data) fed into the program.
  • In C programming Language, the main statements used for logical comparisons are:
    • IF Statement: It evaluates if an expression satisfies a condition, and then executes a predefined instruction. The expression is enclosed or wrapped in brackets ().
    • IF-ELSE Statement: It has 2 sets of pre-defined instructions to be executed, generically described as the IF instruction and the ELSE instruction. It evaluates if an expression satisfies a condition and then executes the predefined IF instruction, but if the condition is not satisfied, then the ELSE instruction is executed.
  • Relational operators are used to evaluate a value in a logical expression.
  • The main types of relational operators are:
    • == which means is equal to e.g 1=1. The values in this expression are 1 and 1.
    • > which means is greater than e.g 1>0. The values in this expression are 1 and 0.
    • >= which means is greater than or equal to.
    • < which means is lesser than e.g 0<1.
    • =< which means is lesser than or equal to.
    • != which means is NOT equal to. e.g 1 != 2.
  • Logical expressions can be combined together using logical operators.
  • The main types of logical operators are &&, !, and ||.
  • An alternative to the IF-ELSE statement is the SWITCH statement.

Loop

  • An action may need to be repeated till a condition is satisfied, and this process of repetition is called a loop.
  • The main types of loops are:
    • Loop FOR – It is used to repeat the instruction execution for a specific number of times.
    • WHILE Loop – It is used to repeat the instruction execution that has satisfied a condition.

Static Memory and Dynamic Memory

  • A fixed quantity of elements belonging to a particular data type form an array.
  • A sequence of characters is called a string. The process of joining characters together to create a string is referred to as character concatenation. String concatenation is the joining together of two or more strings, usually with a space character or an underscore separating individual strings. Another way to join strings together is to use camelCasing as shown in this post.
  • There are 2 types of memory allocated to a program: static and dynamic memory.
  • The memory that is managed by the source code compiler is called static memory.
  • The memory space that the programmer allocates to the program is called dynamic memory.
  • Dynamic memory is allocated at run-time with its size predetermined by the malloc function set by the programmer.

Structured Programming, Function, and Module

  • In C programming, each functionality of the program is controlled by a block of code called a function.
  • A set of functions form a module.
  • In structured programming, the code is divided into functions and modules, which simplifies the process of code maintenance and modification.
  • Regarding variables in structured programming, each variable has a scope.
  • The scope of a variable describes its range of visibility within the program.
  • If the variable is defined in a function, it can only be used inside this function. Thus, its visibility is described as being limited within the function, and the scope of this variable makes it a static variable.
  • If the variable is defined in a module, then its scope and range of visibility make it a global variable. As expected, the global variable is visible to all functions in the module.
  • In a function, the static variable is referenced using a local variable call. It is the compiler that makes this call.
  • The function is identified by a (function) name.
  • A parameter can be passed to a function.
  • A parameter is described as a list of variables separated from each other by a comma, which (this list) can be passed to a function.
  • The parameter can be passed to the function in 2 ways:
    • Parameter by Value – It is used to pass variables and constants. The constant is a variable whose value does not change during the execution of the function.
    • Parameter by Reference – It is used to change or modify the parameter in the function. Normally, this parameter is passed as a pointer. It is usually used to return 2 or more values in the function.
  • A value that confirms that a function has been executed is called the return.

Leave a Reply

Discover more from Kagirison

Subscribe now to keep reading and get access to the full archive.

Continue reading