Week 3
Week 3
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.
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.
Note:
▪ LR1 are the resources accessible online for further understanding of the unit and
support discussion found in your hands-out.
V. DISCUSSION BOARD
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.
Iterative circles and Recursive calls both Recursive calls are utilized in Non-
are utilized in the Procedural dialects. Procedural dialects.
• 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.
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.
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.
In the same way, add(2, 12) may be replaced with the corresponding return value, 14:
int x = 14;
• Haskell
• SML
• Clojure
• Scala
• Erlang
• Clean
• F#
• ML/OCaml Lisp / Scheme
• XSLT
• SQL
• Mathematica
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.
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
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.
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.
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 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.
• 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.
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:
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.
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:
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?")
• 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.