0% found this document useful (0 votes)
18 views

Week 3

The document discusses different programming languages and paradigms. It introduces procedural languages like FORTRAN and C which use predefined procedures and functions. Functional programming is also covered, noting its use of pure mathematical functions without side effects. Key differences are outlined between procedural and non-procedural languages, as well as features of functional programming like pure functions and recursion. Discussion questions prompt understanding of these programming concepts.

Uploaded by

Jeric Avengoza
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Week 3

The document discusses different programming languages and paradigms. It introduces procedural languages like FORTRAN and C which use predefined procedures and functions. Functional programming is also covered, noting its use of pure mathematical functions without side effects. Key differences are outlined between procedural and non-procedural languages, as well as features of functional programming like pure functions and recursion. Discussion questions prompt understanding of these programming concepts.

Uploaded by

Jeric Avengoza
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Lesson 2.

Comparison of Programming Languages


INTRODUCTION

Choosing the best language that would satisfy all requirements for the given problem domain
can be a difficult task. Some languages are better suited for specific applications than
others. In order to select the proper one for the specific problem domain, one has to know
what features it provides to support the requirements. Different languages support different
paradigms, provide different abstractions, and have different levels of expressive power.
Some are better suited to express algorithms and others are targeting the non-technical
users. The question is then what is the best tool for a particular problem. Aspects, like
security and language safety, UI prototyping capabilities, language support for building
distributed systems, and support for automating existing processes, and portability are also
important issues to consider when choosing the programming language. In our analysis we
discussed the suitability of the selected languages for the specified criteria.

II. PRE-COMPETENCY CHECKLIST

If you have questions, don’t hesitate to ask for assistance.

This are the pre-competency checklist required for this module


Understand the Comparison of Programming Languages

III. LEARNING RESOURCES

Necessary details for discussion were included in the hand-outs. Following are supplementary
resources available to access having this purpose of further understanding of the unit.

LR1 Online Resources Access Link:


[1]
https://teachcomputerscience.com/proce
dural-languages/
Procedural Programming Language
https://www.techopedia.com/definition/89
82/procedural-language
[2]
https://www.guru99.com/functional-
programming-tutorial.html
Functional Programming
https://hackr.io/blog/programming-
paradigms
[3]
https://www.techtarget.com/searchappar
Object Oriented Programming Language chitecture/definition/object-oriented-
programming-OOP
[4]
https://www.codesdope.com/blog/article/
Scripting Programming Language
scripting-language/
[5]
https://www.encyclopedia.com/computin
g/dictionaries-thesauruses-pictures-and-
press-releases/logic-programming-
languages
Logic Programming Language https://www.geeksforgeeks.org/differenc
e-between-functional-and-logical-
programming/
https://courses.cs.vt.edu/~cs3304/Spring
02/lectures/lect08.pdf

Integrative Programming and Technologies 1 1


IV EXPLORE
This module contains offline/module and online learning activities for the students to
complete. You must be going over the resources, read, study, and understand to
understand the unit.

Note:
▪ LR1 are the resources accessible online for further understanding of the unit and
support discussion found in your hands-out.

V. DISCUSSION BOARD

Programming Languages LESSON DISCUSSION


What Does Procedural Language Mean?
A procedural language is a type of computer programming language that specifies a series
of well-structured steps and procedures within its programming context to compose a
program. It contains a systematic order of statements, functions and commands to complete
a computational task or program. Procedural language is also known as imperative
language.

What is Procedural Languages:


A procedural language, as the name implies, relies on predefined and well-organized
procedures, functions or sub-routines in a program’s architecture by specifying all the steps
that the computer must take to reach a desired state or output.

The procedural language segregates a program within variables, functions, statements and
conditional operators. Procedures or functions are implemented on the data and variables to
perform a task. These procedures can be called/invoked anywhere between the program
hierarchy, and by other procedures as well. A program written in procedural language
contains one or more procedures.

Features of Procedural Code

• Procedural Programming is excellent for general-purpose programming


• The coded simplicity along with ease of implementation of compilers and interpreters
• A large variety of books and online course material available on tested algorithms,
making it easier to learn.
• The source code is portable
• The code can be reused in different parts of the program, without the need to copy it.
• The program flow can be tracked easily as it has a top-down approach.

Types of Procedural Languages:


• FORTRAN
• ALGOL
• COBOL
• BASIC
• Pascal
• C
• Ada

Integrative Programming and Technologies 1 2


Procedural languages Non-Procedural Language

It is an order driven language. It is a capacity driven language

It works through the condition of the


It works through the numerical capacities.
machine.

Its semantics are very intense. Its semantics are basic.

It returns just confined information types


It can restore any datatype or worth
and permitted values.

By and large effectiveness is low when


Generally proficiency is high.
contrasted with Procedural Language.

Size of the program written in Procedural Size of the Non-Procedural language


language is enormous. programs are little.

It isn’t appropriate for time basic


It is suitable for time primary applications.
applications.

Iterative circles and Recursive calls both Recursive calls are utilized in Non-
are utilized in the Procedural dialects. Procedural dialects.

What is Functional Programming?


Functional programming is a programming paradigm where you have a style of building the
structure and elements of computer programs. Here you treat computation as an evaluation
of mathematical functions and you avoid changing-state and mutable data.
Functional programming consists only of PURE functions. So, what do you understand by
Pure functions?
Pure functions are those which take an argument list as an input and whose output is a return
value. Now you may feel that all functions are pure as any function takes in values and returns
a value.
For example, if a function relies on the global variable or class member’s data, then it is not
pure. And in such cases, the return value of that function is not entirely dependent on the list
of arguments received as input and can also have side effects. So, what do you understand
by the term side effect? A side effect is a change in the state of an application that is
observable outside the called function other than its return value. For example: Modifying any
external variable or object property such as a global variable, or a variable in the parent
function scope chain.

Features of Functional Paradigm

• Pure functions – As seen above, if the input is an array, the output will be a new
array and the input array will not be modified. So in case of pure functions, the output
depends only on the input.

Integrative Programming and Technologies 1 3


Here’s a function in the language Scala that takes values and returns their sum.

scala> def add(a:Int,b:Int) = a + b


add: (a: Int, b: Int)Int

The add function caused no side-effects. It did not alter the input values provided, it used
another pure function, the + operator, and returned the sum of the values as the result of the
call. The add function is a pure function.

• Recursion- A recursive function is a function that calls itself during its execution.
This enables the function to repeat itself several times, the result being outputted at
the end of each iteration. Below is an example of a recursive function.

Function Count (integer N)


if (N <= 0) return "Must be a Positive Integer";
if (N > 9) return "Counting Completed";
else return Count (N+1);
end function

The function Count() above uses recursion to count from any number between 1 and 9, to the
number 10. For example, Count(1) would return 2,3,4,5,6,7,8,9,10. Count(7) would return
8,9,10.
You will note that recursive functions are common in computer science because they allow
you to write efficient programs using a minimal amount of code. The downside is that they can
cause infinite loops and other unexpected results if not written properly. For example, in the
example above, the function is terminated if the number is 0 or less or greater than 9. If proper
cases are not included in the function to stop the execution, the recursion will repeat forever,
causing the program to crash, or worse yet, hang the entire computer system.

• Referential transparency- An expression is said to be referentially transparent if it


can be replaced with its corresponding value without changing the program's
behavior. As a result, evaluating a referentially transparent function gives the same
value for fixed arguments. In functional programming, only referentially transparent
functions are considered. They are a lot easier to read and understand.

int add(int a, int b)


{
return a + b
}
int mult(int a, int b)
{
return a * b;
}
int x = add(2, mult(3, 4));

Integrative Programming and Technologies 1 4


In this example, the mult method is referentially transparent because any call to it may be
replaced with the corresponding return value. This may be observed by replacing mult(3, 4)
with 12:

int x = add(2, 12)

In the same way, add(2, 12) may be replaced with the corresponding return value, 14:

int x = 14;

• Functions are First-Class and can be Higher-Order- A programming


language is said to have First-class functions when functions in that language are
treated like any other variable. For example, in such a language, a function can be
passed as an argument to other functions, can be returned by another function
and can be assigned as a value to a variable. Higher-order functions are functions
that take at least one first-class function as a parameter.
• Variables are Immutable- In functional programming you cannot modify a variable
after it has been initialized. You can create new variables and this helps to maintain
state throughout the runtime of a program.

Strings are immutable objects.

var name = “Susie”


var uppd = name.toUpperCase()

*name will have the value – Susie


*uppd will have the value - SUSIE
Lisp is the second-oldest high-level programming language after Fortran but still in use. Lisp
is a functional programming language; that is, functions are first-class objects in Lisp.
However, it is not a pure-functional language such as Haskell, because operations in Lisp can
have side-effects. Lisp continues to be popular in the field of artificial intelligence down to the
present day.
Characteristics of Functional Programming

• Functional programming method focuses on results, not the process


• Emphasis is on what is to be computed
• Data is immutable
• Functional programming Decompose the problem into ‘functions
• It is built on the concept of mathematical functions which uses conditional
expressions and recursion to do perform the calculation
• It does not support iteration like loop statements and conditional statements like If-
Else

Functional Programming Languages


The objective of any FP language is to mimic the mathematical functions. However, the
basic process of computation is different in functional programming.

Integrative Programming and Technologies 1 5


Here, are some most prominent Functional programming languages:

• Haskell
• SML
• Clojure
• Scala
• Erlang
• Clean
• F#
• ML/OCaml Lisp / Scheme
• XSLT
• SQL
• Mathematica

Basic Functional Programming Terminology and Concepts

Immutable Data
Immutable Data means that you should easily able to create data structures instead of
modifying ones which is already exist.

Referential transparency
Functional programs should perform operations just like as if it is for the first time. So, you
will know what may or may not have happened during the program’s execution, and its side
effects. In FP term it is called Referential transparency.

Integrative Programming and Technologies 1 6


Modularity
Modular design increases productivity. Small modules can be coded quickly and have a
greater chance of re-use which surely leads to faster development of programs. Apart from
it, the modules can be tested separately which helps you to reduce the time spent on unit
testing and debugging.

Maintainability
Maintainability is a simple term which means FP programming is easier to maintain as you
don’t need to worry about accidentally changing anything outside the given function.

First-class function

‘First-class function’ is a definition, attributed to programming language entities that have no


restriction on their use. Therefore, first-class functions can appear anywhere in the program.

Closure
The closure is an inner function which can access variables of parent function’s, even after
the parent function has executed.

Higher-order functions
Higher-order functions either take other functions as arguments or return them as results.

Higher-order functions allow partial applications or currying. This technique applies a


function to its arguments one at a time, as each application returning a new function which
accepts the next argument.

Pure function
A ‘Pure function’ is a function whose inputs are declared as inputs and none of them should
be hidden. The outputs are also declared as outputs.

Pure functions act on their parameters. It is not efficient if not returning anything. Moreover, it
offers the same output for the given parameters

Impure functions
Impure functions exactly in the opposite of pure. They have hidden inputs or output; it is
called impure. Impure functions cannot be used or tested in isolation as they have
dependencies.

Integrative Programming and Technologies 1 7


Function Composition
Function composition is combining 2 or more functions to make a new one.

Shared States
Shared states is an importance concept in OOP programming. Basically, It’s adding
properties to objects. For example, if a HardDisk is an Object, Storage Capacity and Disk
Size can be added as properties.

Side Effects

Side effects are any state changes which occur outside of a called function. The biggest goal
of any FP programming language is to minimize side effects, by separating them from the
rest of the software code. In FP programming It is vital to take away side effects from the
rest of your programming logic.

The benefits of functional programming

• Allows you to avoid confusing problems and errors in the code


• Easier to test and execute Unit testing and debug FP Code.
• Parallel processing and concurrency
• Hot code deployment and fault tolerance
• Offers better modularity with a shorter code
• Increased productivity of the developer
• Supports Nested Functions
• Functional Constructs like Lazy Map & Lists, etc.
• Allows effective use of Lambda Calculus

Limitations of Functional Programming

• Functional programming paradigm is not easy, so it is difficult to understand for the


beginner
• Hard to maintain as many objects evolve during the coding
• Needs lots of mocking and extensive environmental setup
• Re-use is very complicated and needs constantly refactoring
• Objects may not represent the problem correctly

What is object-oriented programming?


Object-oriented programming (OOP) is a computer programming model that organizes
software design around data, or objects, rather than functions and logic. An object can be
defined as a data field that has unique attributes and behavior.

Integrative Programming and Technologies 1 8


OOP focuses on the objects that developers want to manipulate rather than the logic
required to manipulate them. This approach to programming is well-suited for programs that
are large, complex and actively updated or maintained. This includes programs for
manufacturing and design, as well as mobile applications; for example, OOP can be used for
manufacturing system simulation software.

The organization of an object-oriented program also makes the method beneficial to


collaborative development, where projects are divided into groups. Additional benefits of
OOP include code reusability, scalability and efficiency.

The first step in OOP is to collect all of the objects a programmer wants to manipulate and
identify how they relate to each other -- an exercise known as data modeling.

Examples of an object can range from physical entities, such as a human being who is
described by properties like name and address, to small computer programs, such
as widgets.

Once an object is known, it is labeled with a class of objects that defines the kind of data it
contains and any logic sequences that can manipulate it. Each distinct logic sequence is
known as a method. Objects can communicate with well-defined interfaces called messages.

What is the structure of object-oriented programming?


The structure, or building blocks, of object-oriented programming include the following:

• Classes are user-defined data types that act as the blueprint for individual
objects, attributes and methods.
• Objects are instances of a class created with specifically defined data. Objects
can correspond to real-world objects or an abstract entity. When class is defined
initially, the description is the only object that is defined.
• Methods are functions that are defined inside a class that describe the behaviors
of an object. Each method contained in class definitions starts with a reference to
an instance object. Additionally, the subroutines contained in an object are called
instance methods. Programmers use methods for reusability or keeping
functionality encapsulated inside one object at a time.
• Attributes are defined in the class template and represent the state of an object.
Objects will have data stored in the attributes field. Class attributes belong to the
class itself.

Integrative Programming and Technologies 1 9


Features of OO:

• Encapsulation – This is a fundamental feature of Object-Oriented Programming.


Here you hide unnecessary details in classes and deliver a simple and clear interface
for working. It describes the idea of bundling data and methods that work on that data
within one unit. This concept is also often used to hide the internal representation, or
state, of an object from the outside
• Inheritance - Inheritance is one of the core concepts of object-oriented programming
(OOP) languages. It is a mechanism where you can derive a class from another
class for a hierarchy of classes that share a set of attributes and methods. It explains
how the class hierarchies develop code readability and support to the reuse of
functionality.
• Data Abstraction - to Data abstraction is the reduction of a particular body of data to
a simplified representation of the whole. Data abstraction is usually the first step in
database design.
• Polymorphism - Polymorphism is an object-oriented programming concept that
refers to the ability of a variable, function or object to take on multiple forms.

Programming languages that have implemented the OO paradigm are: Ruby, Java, C++,
Python, Simula(the first OOP language)
Programming languages designed primarily for OOP include:

• Java
• Python
• C++
Other programming languages that pair with OOP include:

• Visual Basic .NET


• PHP
• JavaScript

What are the benefits of OOP?


Benefits of OOP include:
• Modularity. Encapsulation enables objects to be self-contained, making
troubleshooting and collaborative development easier.
• Reusability. Code can be reused through inheritance, meaning a team does not
have to write the same code multiple times.
• Productivity. Programmers can construct new programs quicker through the use
of multiple libraries and reusable code.
• Easily upgradable and scalable. Programmers can implement system
functionalities independently.
• Interface descriptions. Descriptions of external systems are simple, due to
message passing techniques that are used for objects communication.
• Security. Using encapsulation and abstraction, complex code is hidden, software
maintenance is easier and internet protocols are protected.
• Flexibility. Polymorphism enables a single function to adapt to the class it is
placed in. Different objects can also pass through the same interface.

Integrative Programming and Technologies 1 10


Criticism of OOP
The object-oriented programming model has been criticized by developers for multiple
reasons. The largest concern is that OOP overemphasizes the data component of software
development and does not focus enough on computation or algorithms. Additionally, OOP
code may be more complicated to write and take longer to compile.

Alternative methods to OOP include:

• Functional programming. This includes languages such as Erlang and Scala,


which are used for telecommunications and fault tolerant systems.
• Structured or modular programming. This includes languages such as PHP
and C#.
• Imperative programming. This alternative to OOP focuses on function rather
than models and includes C++ and Java.
• Declarative programming. This programming method involves statements on
what the task or desired outcome is but not how to achieve it. Languages include
Prolog and Lisp.
• Logical programming. This method, which is based mostly in formal logic and
uses languages such as Prolog, contains a set of sentences that express facts or
rules about a problem domain. It focuses on tasks that can benefit from rule-
based logical queries.

What is a scripting language?

A scripting language, or a script language, is used for a specific run time environment, and
they automate some of the tasks. In a scripting language, the code gets executed without
having any need for compilation, i.e., they are interpreted. To understand this clearly, let’s
see what the difference between a compiler and an interpreter is. A compiler is a computer
program that converts the complete source code written in a high-level language that is
understandable by humans, into machine code that is understandable by computers, before
the execution of a program. However, an interpreter is a program that converts each
statement into machine code, while a program is running. The compiler takes a lot of time
while analyzing the program. Therefore, if there is any error, then the compiler throws it, and
the compilation fails. The program will not execute at all. If you have worked with any
scripting language, for example, JavaScript or Python, you might have noticed that if your
code contains an error in a line, then before that line, all the statements get executed.
However, in a compiling language, like C or Java, none of the statements run.

Integrative Programming and Technologies 1 11


Types of scripting language
There are two types of scripting languages.

Server-side scripting language


A scripting language that runs on a web server is a server-side scripting language. It is used
at the back end, and the script is not visible to the user. Therefore, it is secure. It is generally
used to create dynamic websites, send responses to user queries, or provide data, etc.

Examples of server-side languages include Python, PHP, Perl, Ruby, etc.

Client-side scripting language


A scripting language that runs on the user’s web browser is a client-side scripting language.
It is used at the front end, and thus, the script is visible to the user, which makes it less
secure. It is used to create a user interface and related functionality. Client-side scripting is
faster because it does not require interaction with the web server.

Examples of client-side languages include HTML, CSS, and JavaScript.

Advantages of Scripting Languages


• There are many advantages of using a scripting language. First, they are open
source. Therefore, anyone around the world can use it and contribute to it.
• Second, if you are a beginner, they are a great way to start with programming
languages, as they are quite easy to learn and code.
• As we know that most scripting languages use an interpreter, and unlike compilers,
no executable file is stored, and hence, they require less memory.
• They are portable, i.e., can run on different operating systems.
• Scripts are also used as a prototype before building an actual program.

Disadvantages of Scripting languages


• The interpreter is slower than the compiler because it converts each statement to the
machine code during execution. However, the compiling languages get converted
into machine code beforehand.

Integrative Programming and Technologies 1 12


• In the scripting languages, the interpreter analyzes each statement line by line during
execution, therefore don’t perform many optimizations to execute the code faster.

Application of Scripting languages


Scripting languages are vastly used in web development. It helps to make complex web
pages and applications with simplicity. As explained above, both the server and client sides
of a web application are coded using scripting languages. They are used in system
administration, for example, shells for operating systems. They are also used in embedded
systems, in the making of extensions, plugins, and games, etc.

Logical Programming
Logical programming is a computer programming paradigm that has its foundations in
mathematical logic in which program statements express facts and rules about problems
within a system. Rules are written as logical clauses with a head and a body. They also follow
a declarative rather than an imperative approach. However, what does that mean?
To understand how a problem can be solved in logical programming, you need to know about
the building blocks − Facts and Rules −
Let us understand the difference between Imperative and declarative programming.
Imagine you walk into your favorite coffee place and you would like to order some coffee.
The imperative approach will be:

• Enter the coffee shop


• Queue in the line and wait for the barista asking you for your order
• Order
• Yes, for takeaway, please
• Pay
• Present your loyalty card to collect points
• Take your order and walk away

The declarative approach:

• A large latte for takeaway, please

So rather than providing a step by step instruction (imperative), you tell the system what you
need and let it try to come up with a solution (declarative).
Prolog follows the Logical paradigm and is probably the most famous language in the logical
programming family.
Prolog has been enormously influential in the domains of theorem proving, expert systems,
natural language processing and in the field of artificial intelligence (notably IBM’s Watson2)
in general
Prolog, like SQL, has two main aspects, one to express the data and another to query it. The
basic constructs of logical programming, terms, and statements, are inherited from logic.
There are three basic statements:

• Facts are fundamental assertions about the problem domain (e.g. "Socrates is a
man")
• Rules are inferences about facts in the domain (e.g. "All men are mortal.")
• Queries are questions about that domain (e.g. "Is Socrates mortal?")

Integrative Programming and Technologies 1 13


Features of Logical Programming

• Logical programming can be used to express knowledge in a way that does not
depend on the implementation, making programs more flexible, compressed and
understandable.
• It enables knowledge to be separated from use, i.e. the machine architecture can be
changed without changing programs or their underlying code.
• It can be altered and extended in natural ways to support special forms of
knowledge, such as meta-level of higher-order knowledge.
• It can be used in non-computational disciplines relying on reasoning and precise
means of expression.

VI. POST COMPETENCY


Evaluation 2: Please answer your evaluation 2 in the vlp. You have 10 mins to answer the
questions 1-10. Choose the correct answer on the given choices.

Integrative Programming and Technologies 1 14

You might also like