Wednesday, 31 March 2021

Primitive Data Types | PPL | Sebesta | Elementary Data Types in Programming Language

                 In this post, we will see Primitive Data Types | PPL | Sebesta | Elementary Data Types in Programming Language | primitive data types, data types in ppl, data types ppl, elementary data types in programming language, ppl, sebesta, introduction 


2. Primitive data Types

              Data types that are not defined in terms of other types are called primitive data types.

               Also called as Built-in data types.

 

Examples:

a. Numeric Data Types (Integer, Floating-Point, Complex, Decimal etc.)

b. Boolean Data Types

C. Character Data Types

 

 

a. Numeric Types

       i. Integer

              For example, Java includes four signed integer sizes: byte , short , int , and long .

 

              Some languages, for example, C++ and C#, include unsigned integer types, which are simply types for integer values without signs.

 

              A signed integer value is represented in a computer by a string of bits, with one of the bits (typically the leftmost) representing the sign.

 

              Most computers now use a notation called twos complement to store negative integers.

              In twos-complement notation, the representation of

a negative integer is formed by taking the logical complement of the positive version of the number and adding one.

              Ones-complement notation is still used

by some computers. In ones-complement notation, the negative of an integer is stored as the logical complement of its absolute value.

 

       ii. Floating-Point

              Floating-point data types model real numbers.

              Most languages include two floating-point types, often called float and double.

 

              The collection of values that can be represented by a floating-point type is defined in terms of precision and range.

              Precision is the accuracy of the fractional part of a value, measured as the number of bits.

              Range is a combination of the range of fractions and, more important, the range of exponents.

 

              IEEE floating-point formats:

(a) single precision,

(b) double precision




iii. Complex

              Some programming languages support a complex data type. For example, Fortran and Python.

 

              In Python, the imaginary part of a complex literal is specified by following it with a j or J —for example,

(7 + 3j).

 

              Languages that support a complex type include operations for arithmetic on complex values.

 

       iv. Decimal

              Most larger computers that are designed to support business systems applications have hardware support for decimal data types.

              Decimal data types store a fixed number of decimal digits, with the decimal point at a fixed position in the value.

              COBOL, C# and F# languages have decimal data types.

              Decimal types are stored very much like character strings, using binary codes for the decimal digits. These representations are called binary coded decimal (BCD).

 

b. Boolean Types

              Their range of values has only two elements: one for true and one for false.

              They were introduced in ALGOL 60 and have been included in most general-purpose languages designed since 1960.

 

 

c. Character Types

              Character data are stored in computers as numeric codings. Traditionally, the most commonly used coding was the 8-bit code ASCII (American Standard Code for Information Interchange), which uses the values 0 to 127 to code 128 different characters.

 

              Because of the globalization of business and the need for computers to communicate with other computers around the world, the ASCII character set became inadequate. In response, in 1991, the Unicode Consortium published the UCS-2 standard, a 16-bit character set. This character code is often called Unicode.

              Unicode includes the characters from most of the world’s natural languages.

              For example, Unicode includes the Cyrillic alphabet, as used in Serbia, and the Thai digits.

              After 1991, the Unicode Consortium, in cooperation with the International Standards Organization (ISO), developed a 4-byte character code named UCS-4, or UTF-32, which is described in the ISO/IEC 10646 Standard, published in 2000.

 

              The first 128 characters of Unicode are identical to those of ASCII.

 

              Java was the first widely used language to use the Unicode character set. Since then, it has found its way into JavaScript, Python, Perl, C#, and F#.


Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=kvwL0FdDnYA

Sunday, 28 March 2021

Data Types in PPL | Introduction | PPL | Sebesta | Elementary Data Types in Programming Language

                   In this post, we will see Data Types in PPL | Introduction | PPL | Sebesta | Elementary Data Types in Programming Language | data types in ppl, data types ppl, elementary data types in programming language, ppl, sebesta, introduction  


Data Types :


1. Introduction

 

              A data type defines a collection of data values and a set of predefined operations on those values.

 

Descriptor:

              A descriptor is the collection of the attributes of a variable.

 

Object:

              The word object is often associated with the value of a variable and the space it occupies.

 

Types of Data Types:

i. Primitive Data Types

ii. Structured Data Types

 

Uses of the type system of a programming language:

 

i. Error detection

ii. Program modularization

iii. Documentation


Watch following video: 

Watch on YouTube: https://www.youtube.com/watch?v=jP3g2U94hC4 

Mixed Mode Assignment | PPL | Sebesta | Expressions and Assignment Statements

                   In this post, we will see Mixed Mode Assignment | PPL | Sebesta | Expressions and Assignment Statements | mixed mode assignment, ppl, sebesta, expressions and assignment statements  


7. Mixed mode Assignment

              One of the design decisions concerning arithmetic expressions is whether an operator can have operands of different types.

              Languages that allow such expressions, which are called mixed-mode expressions, must define conventions for implicit operand type conversions because computers do not have binary operations that take operands of different types.

 

e.g.

int a=4;

float b=3.14;

 

float c;

 

c= a+b;


Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=mAmBML45600

Assignment Statements | PPL | Sebesta | Expressions and Assignment Statements

                   In this post, we will see Assignment Statements | PPL | Sebesta | Expressions and Assignment Statements | assignment statements, ppl, sebesta, expressions and assignment statements  


6. Assignment Statements

 

Simple Assignments

 

i. Nearly all programming languages currently being used use the equal sign for the assignment operator.

 

ii. ALGOL 60 and Ada makes use of := as the assignment operator.

 

iii. In some languages, such as Fortran and Ada, an assignment can appear only as a stand-alone statement, and the destination is restricted to a single variable.

 

Conditional Targets

 

       Perl allows conditional targets on assignment statements.

       For example, consider

 

($flag ? $count1 : $count2) = 0;

 

       which is equivalent to

if ($flag) {

$count1 = 0;

}

else {

$count2 = 0;

}

 

 

Compound Assignment Operators

 

              The form of assignment that can be abbreviated with this technique has the destination variable also appearing as the first operand in the expression on the right side, as in

 

a = a + b

 

              By Compound Assignment Operator, above statement is written as follows:

 

a+=b

 

              It is provided by ALGOL 68, C-based languages, Perl, JavaScript, Python, and Ruby.

 

Unary Assignment Operators

 

              The C-based languages, Perl, and JavaScript include two special unary arithmetic operators that are actually abbreviated assignments. They combine increment and decrement operations with assignment.

 

              In the assignment statement

sum = ++ count;

 

              It is similar to

count = count + 1;

sum = count;

 

              If the same operator is used as a postfix operator, as in

sum = count ++;

 

              It is similar to

sum = count;

count = count + 1;

 

count ++

 

              It is similar to

count=count+1

 

              When two unary operators apply to the same operand, the association is right to left. For example, in

- count ++

              count is first incremented and then negated. So, it is equivalent to

- (count ++)

 

Assignment as an Expression

 

              Expression is evaluated and then it is assigned.

e.g.

1. while ((ch = getchar()) != EOF) { ... }

 

2. a = b + (c = d / b) - 1

 

 

 

Multiple Assignments

 

              Some programming languages like Perl, Ruby, and Lua supports multiple-target, multiple-source assignment statements.

 

For example, in Perl one can write

($first, $second, $third) = (20, 40, 60);

 

Here, $first is assigned 20, $second is assigned 40 and $third is assigned 60.


Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=KnLgp8fHR9k


Short Circuit Evaluation | PPL | Sebesta | Expressions and Assignment Statements

                    In this post, we will see Short Circuit Evaluation | PPL | Sebesta | Expressions and Assignment Statements | short circuit evaluation, ppl, sebesta, expressions and assignment statements  


5. Short Circuit Evaluation

              A short-circuit evaluation of an expression is one in which the result is determined without evaluating all of the operands and/or operators.

              For example, the value of the arithmetic expression

(13 * a) * (b / 13 - 1)

is independent of the value of (b / 13 - 1) if a is 0 , because 0 * x = 0 for any x . So, when a is 0 , there is no need to evaluate (b / 13 - 1) or perform the second multiplication. However, in arithmetic expressions, this shortcut is not easily detected during execution, so it is never taken.

 

 

              The value of the Boolean expression

(a >= 0) && (b < 10)

is independent of the second relational expression if a < 0 , because the expression ( FALSE && ( b < 10 )) is FALSE for all values of b .

 

              A language that provides short-circuit evaluations of Boolean expressions and also has side effects in expressions allows subtle errors to occur. Suppose that short-circuit evaluation is used on an expression and part of the expression that contains a side effect is not evaluated; then the side effect will occur only in complete evaluations of the whole expression. If program correctness depends on the side effect, short-circuit evaluation can result in a serious error.

 

 

              For example, consider the Java expression

(a > b) || ((b++) / 3)

              In this expression, b is changed (in the second arithmetic expression) only when a <= b . If the programmer assumed b would be changed every time this expression is evaluated during execution (and the program’s correctness depends on it), the program will fail.

 

              In the C-based languages, the usual AND and OR operators, && and || , respectively, are short-circuit.

 

              Ada allows the programmer to specify short-circuit evaluation of the Boolean operators AND and OR by using the two-word operators and then and or else . Ada also has non–short-circuit operators, and and or .


Watch following video: 

Watch on YouTube: https://www.youtube.com/watch?v=jOWQ4X4b9oQ

Relational and Boolean Expressions | PPL | Sebesta | Expressions and Assignment Statements

                      In this post, we will see Relational and Boolean Expressions | PPL | Sebesta | Expressions and Assignment Statements | relational and boolean expressions, ppl, sebesta, expressions and assignment statements  


4. Relational and Boolean Expressions

              A relational operator is an operator that compares the values of its two operands. A relational expression has two operands and one relational operator.

The value of a relational expression is Boolean.

 

              The syntax of the relational operators for equality and inequality differs among some programming languages. For example, for inequality, the C-based languages use != , Ada uses /= , Lua uses ~= , Fortran 95+ uses .NE. or <> , and ML and F# use <> .

 

              JavaScript and PHP have two additional relational operators, === and !== . These are similar to their relatives, == and != , but prevent their operands from being coerced. For example, the expression

 

"7" == 7

is true in JavaScript, because when a string and a number are the operands of a relational operator, the string is coerced to a number. However,

"7" === 7

is false, because no coercion is done on the operands of this operator.

 

              The relational operators always have lower precedence than the arithmetic operators, so that in expressions such as

a + 1 > 2 * b

the arithmetic expressions are evaluated first.

 

              Boolean expressions consist of Boolean variables, Boolean constants, relational expressions, and Boolean operators. The operators usually include those for the AND, OR, and NOT operations, and sometimes for exclusive OR and equivalence. Boolean operators usually take only Boolean operands (Boolean variables, Boolean literals, or relational expressions) and produce Boolean values.

 

              The precedence of the arithmetic, relational, and Boolean operators in the C-based languages is as follows:





Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=0eCfY9JgX1I

Type Conversions | PPL | Sebesta | Expressions and Assignment Statements

                    In this post, we will see Type Conversions | PPL | Sebesta | Expressions and Assignment Statements | type conversions, ppl, sebesta, expressions and assignment statements  


3. Type conversions

 

narrowing conversion

e.g. float to int

 

widening conversion

e.g. int to float


Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=AD8J7IVTXa0

Monday, 22 March 2021

Overloaded Operators | PPL | Sebesta | Expressions and Assignment Statements

                      In this post, we will see Overloaded Operators | PPL | Sebesta | Expressions and Assignment Statements | overloaded operators, ppl, sebesta, expressions and assignment statements  


2. Overloaded Operators

e.g.

+

&

-

All these operators are used for multiple purpose.


Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=WveSp2SPiB0

Arithmetic Expressions | PPL | Sebesta | Expressions and Assignment Statements

                      In this post, we will see Arithmetic Expressions | PPL | Sebesta | Expressions and Assignment Statements | arithmetic expressions, ppl, sebesta, expressions and assignment statements  


1. Arithmetic expression

              In programming languages, arithmetic expressions

consist of operators, operands, parentheses, and function calls.

              An operator can be unary, meaning it has a single operand, binary, meaning it has two operands, or ternary, meaning it has three operands.

              In most programming languages, binary operators are infix, which means they appear between their operands, while in Lisp, it it prefix.     

              Following are the primary design issues for arithmetic expressions:

 

What are the operator precedence rules?

              The precedences of the arithmetic operators of Ruby and the C-based languages are as follows:



 

** stands for exponentiation operator.

 

What are the operator associativity rules?

              When an expression contains two adjacent 2 occurrences of operators with the same level of precedence, the question of which operator is evaluated first is answered by the associativity rules of the language.

              Associativity in common languages is left to right, except that the exponentiation operator (when provided) sometimes associates right to left.

              The associativity rules for a few common languages are given here:


 


Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=ZM_jGRm9i48

Naming Encapsulations | PPL | Sebesta | Abstract Data Types and Encapsulation Constructs

                  In this video, we will see Naming Encapsulations | PPL | Sebesta | Abstract Data Types and Encapsulation Constructs | naming encapsulations, ppl, sebesta, abstract data types and encapsulation constructs 


5. Naming Encapsulations

 

              How to avoid naming conflicts...

 

i. Namespaces in C++

 

ii. Packages in Java


Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=o5Vt_9C1ln0

Thursday, 18 March 2021

Encapsulation Constructs | PPL | Sebesta | Abstract Data Types and Encapsulation Constructs

                       In this post, we will see Encapsulation Constructs | PPL | Sebesta | Abstract Data Types and Encapsulation Constructs | encapsulation constructs, ppl, sebesta, abstract data types and encapsulation constructs 


4. Encapsulation Constructs

 

i. Encapsulation in C language using Header Files

 

ii. Encapsulation in C++

a. Header Files

b. Classes


How To Create Header File in C or C++ Language With Example | How To Create Header File in CPP

https://www.youtube.com/watch?v=Wou821q0NqY 


Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=ap5fGzdWFuI

Wednesday, 17 March 2021

Parameterized Abstract Data Types | PPL | Sebesta | Abstract Data Types and Encapsulation Constructs

                      In this post, we will see Parameterized Abstract Data Types | PPL | Sebesta | Abstract Data Types and Encapsulation Constructs | parameterized abstract data types, ppl, sebesta, abstract data types and encapsulation constructs  


3. Parameterized Abstract Data types

              To pass the parameters to the Abstract Data Types.

              To generalize the types of parameters passed to the Abstract Data Types, following features are provided:

 

i. Templates in C++

 

ii. Generic Classes in Java


Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=JcUNStvZ8x0

Tuesday, 16 March 2021

Design Issues for Abstract Data Types | PPL | Sebesta | Abstract Data Types Encapsulation Constructs

                     In this post, we will see Design Issues for Abstract Data Types | PPL | Sebesta | Abstract Data Types Encapsulation Constructs | design issues for abstract data types, ppl, sebesta, abstract data types and encapsulation constructs   


2. Design issues for Abstraction

 

1. The form of the container for the interface to the type.

2. Whether abstract data types can be parameterized.

3. What access controls are provided and how such controls are specified.

4. Whether the specification of the type is physically separate from its implementation (or whether that is a developer choice).


Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=wK0njNMompo

Monday, 15 March 2021

Introduction To Data Abstraction | PPL | Sebesta | Abstract Data Types and Encapsulation Constructs

                   In this post, we will see Introduction To Data Abstraction | PPL | Sebesta | Abstract Data Types and Encapsulation Constructs | introduction to data abstraction, ppl, sebesta, abstract aata types, abstract data types and encapsulation constructs  


1. Introduction to Abstract Data Types

 

Abstraction

 

Process Abstraction

 

Data Abstraction

              It is also known as Information Hiding. It allows users to create data objects (variables) of Abstract Data Types and also allows users to perform some operations on those data objects but implementation of these types are hidden from the users.

 

Data Abstraction for Built-in Data Types (e.g. floating-point type)

 

User-Defined Abstract Data Types

 

Benefits of Abstract Data Types:

i. Increased Reliability

ii. It reduces the range of code and number of variables of which a programmer must be aware when writing or reading a part of the program.

iii. Makes name conflicts less likely, because the scope

of variables is smaller


Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=lKKO_CmvOKs


Parameter Passing Methods in PPL or Programming Language | Subprograms | PPL | Sebesta

                     In this post, we will see Parameter Passing Methods in PPL or Programming Language | Subprograms |  PPL | Sebesta | parameter passing methods, subprograms, ppl, sebesta, parameter passing methods, parameter passing methods in programming language, parameter passing mechanism, parameter passing methods in ppl, explain various parameter passing methods   


4. Parameter passing methods.


 

i. Pass By Value / Call By Value

              When a parameter is passed by value, the value of the actual parameter is used to initialize the corresponding formal parameter, which then acts as a local variable in the subprogram, thus implementing in-mode semantics.

 

ii. Pass By Result

              Pass-by-result is an implementation model for out-mode parameters.

 

e.g. C# code

 

void Fixer(out int x, out int y) {

x = 17;

y = 35;

}

. . .

f.Fixer(out a, out a);

 

iii. Pass By Value-Result

              Pass-by-value-result is an implementation model for inout-mode parameters in which actual values are copied.

 

iv. Pass By Reference

              Pass-by-reference is a second implementation model for inout-mode parameters.

 

v. Pass By Name

              Pass-by-name is an inout-mode parameter transmission method.

              When parameters are passed by name, the actual parameter is, in effect, textually substituted for the corresponding formal parameter in all its occurrences in the subprogram.

 


Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=etW6Gfu_e30

Saturday, 13 March 2021

Local Referencing Environments | Subprograms | PPL | Sebesta

                        In this post, we will see Local Referencing Environments | Subprograms | PPL | Sebesta | local referencing environments, subprograms, ppl, sebesta   


3. Local Referencing Environments

 

a. Nested Subprogram

    e.g. Javascript

 

b. External / Global Variable

 

c. Local Variable

 

- Stack Dynamic Local Variable

Advantages:

i. Flexibility

ii. Supports Recursion

iii. Shared Memory

 

Disadvantages:

i. Time to allocate and deallocate

ii. Indirect Access

 

 

- Static Local Variable

 

Advantages:

i. No time wastage for allocation and deallocation

ii. Direct Access

 

Disadvantages:

i. Do not support recursion

ii. Storage can not be shared


Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=uSnmT80-TgM


Design Issues for Subprograms | PPL | Sebesta

                       In this post, we will see Design Issues for Subprograms | PPL | Sebesta | design issues for subprograms, ppl, sebesta   


2. Design Issues for Subprograms

 

       Following are the Design Issues for Subprograms:


1. Are local variables statically or dynamically allocated?

 

2. Can subprogram definitions appear in other subprogram definitions?

 

3. What parameter-passing method or methods are used?

 

4. Are the types of the actual parameters checked against the types of the formal parameters?

 

5. If subprograms can be passed as parameters and subprograms can be nested, what is the referencing environment of a passed subprogram?

 

6. Can subprograms be overloaded?

 

7. Can subprograms be generic?

 

8. If the language allows nested subprograms, are closures supported?

             

              A closure is a nested subprogram and its referencing environment, which together allow the subprogram to be called from anywhere in a program.

 

Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=JxkYyMqfhmY

Fundamentals of Subprograms | PPL | Sebesta

                      In this post, we will see Fundamentals of Subprograms | PPL | Sebesta | fundamentals of subprograms, ppl, sebesta, fundamentals of subprograms 


1. Fundamentals of Subprograms

 

Characteristics of Subprograms:

a. Each subprogram has a single entry point.

b. The calling program unit is suspended during the execution of the called subprogram, which implies that there is only one subprogram in execution at any given time.

c. Control always returns to the caller when the subprogram execution terminates.

 

Terminologies:

 

1. Subprogram Call

              A subprogram call is the explicit request that a specific subprogram be executed.

 

 

2. Active Subprogram

              A subprogram is said to be active if, after having been called, it has begun execution but has not yet completed that execution.

 

3. Subprogram Header

              A subprogram header, which is the first part of the definition, serves several purposes.

 

e.g.

              def adder parameters :

       This is the header of a Python subprogram named adder .

       Ruby subprogram headers also begin with def .

       The header of a JavaScript subprogram begins with function.

       In C, the header of a function named adder might be as follows:

              void adder ( parameters )

 

4. Body of Subprogram

              The body of subprograms defines its actions.

              In the C-based languages (and some others—for example, JavaScript) the body of a subprogram is delimited by braces.

              In Ruby, an end statement terminates the body of a subprogram.

              As with compound statements, the statements in the body of a Python function must be indented and the end of the body is indicated by the first statement that is not indented.

 

 

5. Parameter Profile

              The parameter profile of a subprogram contains the number, order, and types of its formal parameters.

 

6. Protocol

              The protocol of a subprogram is its parameter

profile plus, if it is a function, its return type.

 

7. Subprogram Declaration

              Subprogram declarations provide the subprogram’s protocol but do not include their bodies. Function declarations are common in C and C++ programs, where they are called prototypes. In most other languages (other than C and C++), subprograms do not need declarations, because there is no requirement that subprograms be defined before they are called.

 

8. Formal Parameters

              The parameters in the subprogram header are called formal parameters.

 

9. Actual Parameters

              Subprogram call statements must include the name of the subprogram and a list of parameters to be bound to the formal parameters of the subprogram. These parameters are called actual parameters.

 

10. Positional Parameters

              The correspondence between actual and formal parameters or the binding of actual parameters to formal

parameters is done by position. Such parameters are called positional parameters.

 

11. Keyword Parameters

              When lists are long, however, it is easy for a programmer to make mistakes in the order of actual parameters in the list. One solution to this problem is to provide keyword parameters, in which the name of the formal parameter to which an actual parameter is to be bound is specified with the actual parameter in a call.

 

e.g. Python functions can be called using this technique, as in

sumer(length = my_length, list = my_array, sum = my_sum)

       where the definition of sumer has the formal parameters length, list, and sum.

 

              Some authors call actual parameters arguments and formal parameters just parameters.


Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=BHQ8Hi96Ih0

Subprograms Introduction | PPL | Sebesta | Subprograms in PPL | Subprograms in Programming Language

                       In this post, we will see Subprograms Introduction | PPL | Sebesta | Subprograms in PPL | Subprograms in Programming Language | subprograms introduction,ppl,sebesta,subprograms in ppl,subprograms,subprograms in programming language,function,procedure   


Subprograms:

Definition:

              A collection of statements which can be reused to save memory space and coding time is known as a subprogram.

 

Difference Between Function and Procedure.

 

Advantages of Subprograms:

a. Readability

b. Abstraction

c. Code reusability


Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=88PGeOtka58


Wednesday, 3 March 2021

Von Neumann Architecture in Computer Organization | Von Neumann Model in Computer Architecture

                    In this post, we will see Von Neumann Architecture in Computer Organization | Von Neumann Model in Computer Architecture | von neumann architecture,von neumann,von neumann model in computer architecture,von neumann architecture in computer organization,von neumann model,von neumann machine,von neumann architecture in english,von neumann computer architecture 


Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=ssT8PCbOnQc