Final Assignment CSE 425 Concept of Programming Language Section 7 Spring 2020 North South University Submitted To: Prof. Md. Ezharul Islam (Ezm)
Final Assignment CSE 425 Concept of Programming Language Section 7 Spring 2020 North South University Submitted To: Prof. Md. Ezharul Islam (Ezm)
CSE 425
Concept of Programming Language
Section 7
Spring 2020
North South University
Type: OOP.
1. statically-typed
2. purely object-oriented
3. garbage-collection so that we don’t have to worry about memory
management
4. based on C-style syntax
Application Domains:
1. Scientific applications
– typically require simple data structures but a large number of floating-point
operations.
– typical data structures: arrays and matrices.
– typical control constructs: selection and loop.
2. Business applications
– requires preparation of detailed, complex reports and precise ways of handling
decimal numbers and character data.
3. Systems programming applications
– systems software is used almost continuously and so a language for systems
programming must have fast execution.
SLIDE (1-9)
Design Issues:
Design issues of names:
1. Are names case sensitive?
Answer: Yes.
Answer: Yes. There are so many special word and keywords reserved in F##
programming language. I design it with Java. Some are similar to Java &
some are different. Given below:
• double: The double keyword is used to declare a variable that can hold a
64-bit double precision IEEE 754 floating-point number.
• else: The else keyword is used in conjunction with if to create an if-else
statement, which tests a boolean expression; if the expression evaluates
to true, the block of statements associated with the if are evaluated; if it
evaluates to false, the block of statements associated with the else are
evaluated.
• reach: Used in a class declaration to specify the superclass; used in an
interface declaration to specify one or more superinterfaces. Class X
reach class Y to add functionality, either by adding fields or methods to
class Y, or by overriding methods of class Y. An interface Z reach one or
more interfaces by adding methods. Class X is said to be a subclass of
class Y; Interface Z is said to be a subinterface of the interfaces it reach.
• ending: Define an entity once that cannot be changed nor derived from
later. More specifically: an ending class cannot be subclassed, an ending
method cannot be overridden, and an ending variable can occur at most
once as a left-hand expression on an executed command. All methods in
an ending class are implicitly ending.
• finally: Used to define a block of statements for a block defined
previously by the try keyword. The finally block is executed after
execution exits the try block and any associated arrest clauses
regardless of whether an exception was thrown or caught, or execution
left method in the middle of the try or arrest blocks using the return
keyword.
• float: The float keyword is used to declare a variable that can hold a 32-
bit single precision IEEE 754 floating-point number.
• for: The for keyword is used to create a for loop, which specifies a
variable initialization, a boolean expression, and an incrementation.
• if: The if keyword is used to create an if statement, which tests a
boolean expression; if the expression evaluates to true, the block of
statements associated with the if statement is executed. This keyword
can also be used to create an if-else statement.
Special character:
\\ Backslash
\t Tab
\b Backspace
\r Carriage return
// comment
class Dog{
personal void eat(){
Print.this.line("cat is eating.");
}
public fixed void main( ){
Cat c1=new Cat();
c1.eat();
}
}
class Animal{
void eat(){
Print.this.line("animal is eating...");
}
}
class Cat reach Animal{
void eat(){
Print.this.line ("dog is eating...");
}
public fixed void main( ){
Animal a=new Cat();
a.eat();
}
}
The scope of a variable x is the region of the program in which uses of x refers to
its declaration. One of the basic reasons of scoping is to keep variables in different
parts of program distinct from one another. Since there are only a small number
of short variable names, and programmers share habits about naming of variables
(e.g., i for an array index), in any program of moderate size the same variable
name will be used in multiple different scopes.
Scoping is generally divided into two classes:
1. Static Scoping
2. Dynamic Scoping
{ //block start
int var = 20;
var++;
} //block end
class RectangleDemo
{
public fixed void main( )
{
Rectangle r1 = new Rectangle();
Rectangle r2 = r1;
r1.length = 10;
r2.length = 20;
}
}
Design issue:
– What is the form and type of the control expression?
Expressions are the core components of statements; statements may be grouped
into blocks.
An expression is a construct made up of variables, operators, and method
invocations, which are constructed according to the syntax of the language, that
evaluates to a single value. Code:
int cadence = 0;
anArray[0] = 100;
Print.this.line("Element 1 at index 0: " + anArray[0]);
int result = 1 + 2;
if (value1 == value2)
Print.this.line("value1 == value2");
F## example:
if (sum == 0)
if (count == 0)
result = 0;
else result = 1;
Design issue:
What are the type and scope of the loop variable?
Often the variable that controls a for loop is only needed for the purposes of the
loop and is not used elsewhere. When this is the case, it is possible to declare the
variable inside the initialization portion of the for. For example, here is the
preceding program recoded so that the loop control variable n is declared as an
int inside the for
Class ForTick {
Public fixed void main ( ) {
for ( int n=10; n>0; n--)
Print.this.line(“tick “ + n);
}
}
When you declare a variable inside a for loop, there is one important point to
remember: the scope of that variable ends when the for statement does. (That is,
the scope of the variable is limited to the for loop.) Outside the for loop, the
variable will cease to exist. If you need to use the loop control variable elsewhere
in your program, you will not be able to declare it inside the for loop.
When the loop control variable will not be needed elsewhere, most Java
programmers declare it inside the for. For example, here is a simple program that
tests for prime numbers. Notice that the loop control variable, i is declared inside
the for since it is not needed elsewhere.
Design issues:
Pretest or posttest?
Answer: Both. Pretest and posttest forms, in which the control expression can be
arithmetic.
Should the logically controlled loop be a special case of the counting loop
statement or a separate statement?
Answer: F## is like C and C++, except the control expression must be Boolean
(and the body can only be entered at the beginning – F## has no goto.
Answer: I design F## is similar to Java. What’s why Java and F## have
unconditional labeled exits.
SLIDE-11
Design Issues:
Physical access control limits access to campuses, buildings, rooms and physical IT
assets. Logical access control limits connections to computer networks, system
files and data.
SLIDE-12
Nested Classes
Answer: In F##, just like methods, variables of a class too can have another class
as its member. Writing a class within another is allowed in F##. The class written
within is called the nested class, and the class that holds the inner class is called
the outer class. Code:
class Outer_Demo {
class Inner_Demo {
}
}
Initialization of Objects
Answer: How are parent class members initialized when a subclass object is
created?
Ans: example by using F## code is given below:
class Person
{
private String name;
private int age;
Print.this.line(person);
}
}
SLIDE 13
– All methods are defined in Object, which is the root class in F##, so all
objects inherit them.
Competition synchronization is required between two tasks when both require
the use of the same resource that cannot be simultaneously used. Expression is
given below:
synchronized statement
synchronized (expression)
statement
F##.util.TimerTask
F##.util.concurrent.ScheduledExecutorService
Quartz Scheduler
org.springframework.scheduling.TaskScheduler
time is still in the future of this period obtain the status "Waiting for start time".
The start of these tasks will be initiated at the scheduled time.
Evaluation Criteria
1. Readability
The first and most obvious of these criteria is certainly readability. Today we can
see the effort in obtaining efficiency, looking at the names of some libraries or
functions of the C language; names like “stdio” or “strcmp” are common. Although
the meaning is easily identifiable, today we would not see the reason for its use. A
language is easily usable when applied to contexts for which it was designed; using
a language designed for data analysis to create a DBMS, will surely make the code
difficult to read.
Simplicity
count = count + 1
count += 1
count++
++count
Orthogonality
Data Types
The presence of adequate ways to define data types and data structures is also
important for readability.
Imagine not having the Boolean type; you would be forced to use numeric values
that take the logical value of True and False.
This approach creates confusion in the reader, as he does not know what value to
attribute to the number ‘1’, whether logical or numerical. It should rely on a good
practice of naming variables, which does not always belong to all programmers.
Syntax considerations
Readability is influenced by the syntax of the elements of a language, that is, by
how the elements of a language appear; for example, how the special words of
the language appear (while, class, for, …).
2. Writability
Writability is a measure of how easily a language can be used to create
programs for a chosen problem domain.
As for orthogonality and simplicity, the same considerations made for readability
have to be done.
Too many constructs and too many ways of combining the constructs of a
language, can lead to writing errors, ignored by both the programmer and the
compiler; furthermore, too much freedom of use, especially with complex
constructs, can lead to difficulties in use; this often support poor elegantness and
difficult to modify implemented solutions.
Briefly, abstraction means the ability to define and then use complicated
structures or operations in ways that allow many of the details to be ignored.
Abstraction is a key concept in contemporary programming language design.
This is a reflection of the central role that abstraction plays in modern program
design methodologies. The degree of abstraction allowed by a programming
language and the naturalness of its expression are therefore important to
its writability.
Expressivity
Expressivity in a language can refer to several different characteristics. In a
language F## it means that there are very
3. Reliability
A program is said to be reliable if it performs to its specifications under all
conditions. Let's describe several language features that have a significant effect
on the reliability of programs in a given language.
Type Checking
Type checking is simply testing for type errors in a given program, either by the
compiler or during program execution.
Type checking is an important factor in language reliability. Because run-time type
checking is expensive, compile-time type checking is more desirable.
Exception handling
The ability of a program to intercept run-time errors (as well as other unusual
conditions detectable by the program), take corrective measures, and then
continue is an obvious aid to reliability.
This language facility is called exception handling. Let’s see an example in F##:
class ThrowsExecp{
Output:
Exception in thread "main" f##.lang.NullPointerException
at ThrowsExecp.main
Let us see an example in F## that illustrate how run-time system searches
appropriate exception handling code on the call stack:
class ExceptionThrown
{
fixedint divideByZero(int a, int b){
int i = a/b;
return i;
}
fixedint computeDivision(int a, int b) {
int res =0;
try
{
res = divideByZero(a,b);
}
arrest(NumberFormatException ex)//in Java arrest is calledcatch
{
Print.this.line("NumberFormatException is occured");
}
return res;
}
public fixed void main(){
int a = 1;
int b = 0;
try
{
int i = computeDivision(a,b);
}
arrest(ArithmeticException ex)
{
Print.this.line(ex.getMessage());
}
}
}
Aliasing
Loosely defined, aliasing is having two or more distinct names that can be
used to access the same memory cell. It is now widely accepted that aliasing is a
dangerous feature in a programming language.
4. Cost
The cost of a language depends on many factors. Let’s see a short list.
First of all, instruct programmers to use a certain language. This cost is a function
of simplicity and orthogonality. Generally, the more powerful a language is, the
more complex it is.
Secondly, there is a cost linked both to the difficulty of writing a program in a
certain language (which can lead to long development times, therefore higher
costs) and to the costs for preparation and use of the right development
environment.
Historically speaking, these costs have led to the birth of very high-level languages
and functional languages.
Linked to the cost of the development environment, there is the “cost of
compilation”; some compilers have usage costs and, in some cases, require a
certain type of hardware. Moreover, almost all the compilers carry out various
kinds of optimizations, which certainly can lead to longer compilation times,
different occupied memory space from the original one, execution times and
costs different from the original code.
5. Others
- Portability
The ease with which programs can be moved from one implementation to
another.
- Generality
The applicability to a wide range of applications.
- Well-definedness
The completeness and precision of the language’s official definition.
References:
✓ https://www.quora.com/What-type-of-language-is-Java
✓ https://en.wikipedia.org/wiki/Java_(programming_language)
✓ https://en.wikipedia.org/wiki/List_of_Java_keywords
✓ https://www.geeksforgeeks.org/static-and-dynamic-scoping/
✓ https://study.com/academy/lesson/java-enumerated-type.html
✓ https://www.ibm.com/support/knowledgecenter/SSLTBW_2.3.0/com.ibm.
zos.v2r3.ieab600/iea3b6_THEN_and_ELSE_clauses.htm
✓ https://www.quora.com/What-are-the-type-and-scope-of-the-loop-
variable
✓ https://searchsecurity.techtarget.com/definition/access-control
✓ https://docs.automic.com/documentation/webhelp/english/AWA/11.2/AE/
11.2/All%20Guides/Content/ucaaoe.htm
✓ https://medium.com/@thisisfordeveloper/programming-language-
evaluation-criteria-part-2-writability-reliability-cost-6c3029c9d957
✓ https://progr-harrykar.blogspot.com/2018/11/language-evaluation-
criteria.html