GSLC Programming Language Concept 01

GSLC PLC 01

Name                   : Vincensius Adriel
NIM                     : 2101642301
Class number     : 44
Class                    : LH-01

  1. What are the advantages and disadvantages of decimal data types?

Decimal data types store a fixed number of decimal digits, with the decimal point at a fixed position in the value.  Decimal types have the advantage of being able to precisely store decimal values, at least those within a restricted range, which cannot be done with floating-point.

 

The disadvantages of decimal types are that the range of values is restricted because no exponents are allowed

For example, A 16-bit integer would only allow 65536 different numbers. If you use one bit as indication of positive or negative, you would only be able to have 32768 positive and negative numbers. (Actually, you would end up with a positive zero and negative zero too, which are both equal, so that’s fixed by subtracting one from all negative values. The range then becomes all from -32768 to +32767. (Because you also have to count the 0.), and their representation in memory is mildly wasteful.

  1. How does a decimal value waste memory space?

Decimal types are stored very much like character strings, using binary codes for the decimal digits. These representations are called binary coded decimal (BCD). In some cases, they are stored one digit per byte, but in others, they are packed two digits per byte. Either way, they take more storage than binary representations. It takes at least four bits to code a decimal digit.
Therefore, to store a six-digit coded decimal number requires 24 bits of memory.
However, it takes only 20 bits to store the same number in binary.

Decimal values store numeric information as digits encoded using the four bit binary equivalents: 0 (0000) to 9 (1001). That means a single byte can hold values between 0 and 99. But simply using the same byte to hold a binary value will yield values between 0 and 255 (or –128 and +127).

  1. In what way is static type checking better than dynamic type checking?

The big benefit of static type checking is that it allows many type errors to be caught early in the development cycle. Static typing usually results in compiled code that executes more quickly because when the compiler knows the exact data types that are in use, it can produce optimized machine code (i.e. faster and/or using less memory). Static type checkers evaluate only the type information that can be determined at compile time, but are able to verify that the checked conditions hold for all possible executions of the program, which eliminates the need to repeat type checks every time the program is executed.

A static type-checker will quickly detect type errors in rarely used code paths. Without static type checking, even code coverage tests with 100% coverage may be unable to find such type errors. However, a detriment to this is that static type-checkers make it nearly impossible to manually raise a type error in your code because even if that code block hardly gets called – the type-checker would almost always find a situation to raise that type error and thus would prevent you from executing your program (because a type error was raised).

  1. What is coercion in programming languages?

Many programming languages support the conversion of a value into another of a different data type. This kind of type conversions can be implicitly or explicitly made. Implicit conversion, which is also called coercion, is automatically done. Explicit conversion, which is also called casting, is performed by code instructions. This code treats a variable of one data type as if it belongs to a different data type. The languages that support implicit conversion define the rules that will be automatically applied when primitive compatible values are involved.

  1. Explain how coercion rules can weaken the beneficial effect of strong typing?

Coercion is implicit type conversions. So if we implicitly change the types of somevariables/values then we are subverting the typing rules of the language.

Compilers for strong typing languages usually can detect more typing related errors during the compile time. Compared to that, coercion rules
make the language less compile time reliable. In addition, it is considered easier for people to understand codes written in strong typing languages since coercion rules usually adds some logic implicitly behind the code itself.

Posted in Uncategorized | Leave a comment

Session 3

Names, Bindings, and Scopes

October  7th, 2017

In this session we will going to discuss about Names, Bindings, and Scopes in programming language.

before we start to our topics, lets discuss about imperative programming, so what is imperative programming and what is it relation to our topic in this session (names, bindings, and scopes) ? well as you can see from our previous session,

“imperative, imperative programming is a programming paradigm that uses statements that change a program’s state. In much the same way that the imperative mood in natural languages expresses commands, an imperative program consists of commands for the computer to perform.”

Imperative programming languages are abstractions of the von Neumann Computer architecture.  The architecture’s two primary components are its memory and its processor.

  • Memory: stores both instructions and data
  • Processor: provides operations for modifying the contents of

The abstractions in a language for the memory cells of the machine are variables.

Variables characterized by attributes
– Type: to design, must consider scope, lifetime, type checking,
initialization, and type compatibility

so by that we could conclude that , in other the computer to run as our intended to, we must put a command, like names, binding , and scopes. Names, binding , and scopes helps the user and the computer when perform programming, it helps the users to perform a calculation , write an algorithm, and understand the basic form of computer programming. In the other side, the computer, could manipulate the data that was sended by the user(in the form of variables, function, and etc), so that the output that  computer send, is similar to what the user ordered.

first thing first, lets talk about Names.

Names

Design issues for names:
• Maximum length?
• Are connector characters allowed?
• Are names case sensitive?
• Are special words reserved words or keywords?

Name Forms
ƒ A name is a string of characters used to identify some entity in a program.

ƒ If too short, they cannot be connotative

ƒ Language examples:

• FORTRAN I: maximum 6
• COBOL: maximum 30
• FORTRAN 90 and ANSI C: maximum 31
• Ada and Java: no limit, and all are significant
• C++: no limit, but implementers often impose a length limitationbecause they do not want the symbol table in which identifiers are
stored during compilation to be too large and also to simplify the
maintenance of that table.

ƒ Names in most programming languages have the same form: a letter
followed by a string consisting of letters, digits, and (_).

ƒ Although the use of the _ was widely used in the 70s and 80s, that
practice is far less popular.

ƒ C-based languages (C, C++, Java, and C#), replaced the _ by the “camel”
notation, as in myStack.

ƒ Prior to Fortran 90, the following two names are equivalent:
Sum Of Salaries // names could have embedded spaces
SumOfSalaries // which were ignored

• Case sensitivity
– Disadvantage: readability (names that look alike are different)

• worse in C++ and Java because predefined names are
mixed case (e.g. IndexOutOfBoundsException)

• In C, however, exclusive use of lowercase for names.
– C, C++, and Java names are case sensitive Î rose, Rose, ROSE
are distinct names “What about Readability”

Special words
• An aid to readability; used to delimit or separate statement clauses
• A keyword is a word that is special only in certain contexts.
• Ex: Fortran
Real Apple // Real is a data type followed with a
name, therefore Real is a keyword
Real = 3.4 // Real is a variable name
• Disadvantage: poor readability. Compilers and users must recognize the
difference.
• A reserved word is a special word that cannot be used as a user-defined
name.
• As a language design choice, reserved words are better than keywords.
• Ex: In Fortran, one could have the statements
Integer Real // keyword “Integer” and variable “Real”
Real Integer // keyword “Real” and variable “Integer”

Variables
• A variable is an abstraction of a memory cell(s).
• Variables can be characterized as a sextuple of attributes:
• Name
• Address
• Value
• Type
• Lifetime
• Scope

Name
– Not all variables have names: Anonymous, heap-dynamic variables
Address

• The memory address with which it is associated
• A variable name may have different addresses at different places and at
different times during execution.
// sum in sub1 and sub2
• A variable may have different addresses at different times during
execution. If a subprogram has a local var that is allocated from the run
time stack when the subprogram is called, different calls may result in that
var having different addresses.
// sum in sub1
• The address of a variable is sometimes called its l-value because that is
what is required when a variable appears in the left side of an assignment
statement.

Aliases
• If two variable names can be used to access the same memory
location, they are called aliases
• Aliases are created via pointers, reference variables, C and C++
unions.
• Aliases are harmful to readability (program readers must remember all of
them)

Type
• Determines the range of values of variables and the set of operations
that are defined for values of that type; in the case of floating point, type
also determines the precision.
• For example, the int type in Java specifies a value range of -2147483648
to 2147483647, and arithmetic operations for addition, subtraction,
multiplication, division, and modulus.

Value
• The value of a variable is the contents of the memory cell or cells
associated with the variable.
• Abstract memory cell – the physical cell or collection of cells associated
with a variable.
• A variable’s value is sometimes called its r-value because that is what is
required when a variable appears in the right side of an assignment
statement.

Bindings

A binding is an association between an entity and an attribute, such as between a variable and its type or value, or between an operation and a symbol

  • Binding time is the time at which a binding takes place.

Static Bindings : 

It first occurs before run time and remains unchanged throughout program execution.

  • Advantage : efficiency
  • Disadvantage : Lack of Flexibility

Ex :

  • int x;
  • int data type range from negative 2,147,483,648 to positive 2,147,483,647

Time during operation :

  • Language design time — bind operator symbols to operations
    For example, the asterisk symbol (*) is bound to the multiplication operation.
  • Language implementation time– bind floating point type to a representation
  • Compile time — bind a variable to a type in C or Java

Dynamic Bindings :

first occurs during execution or can change during execution of the program.

  • Advantage: flexibility (generic program units)
  • Disadvantages:

1.High cost (dynamic type checking and interpretation)
• Dynamic type bindings must be implemented using pure interpreter not compilers.
• Pure interpretation typically takes at least ten times as long as to execute equivalent machine code.

2.Type error detection by the compiler is difficult because any variable can be assigned a value of any type.

  • Load time — bind a C or C++ static variable to a memory cell)
  • Runtime — bind a nonstatic local variable to a memory cell

Ex :

  • Long double pi = 3,14159265358979323846;
  • int assignment = 95;
    int mid  = 80;
    int final  = 100;

float score;

score = (0.2*assginment)+(0.3*mid)+(0.5*final);

In general, early binding times are associated with greater efficiency Later binding times are associated with greater flexibility

Scopes

Variable Attributes: Scope

  • The scope of a variable is the range of statements over which it is visible
  • The local variables of a program unit are those that are declared in that unit
  • The nonlocal variables of a program unit are those that are visible in the unit but not declared there
  • Global variables are a special category of nonlocal variables
  • The scope rules of a language determine how references to names are associated with variables

Static Scope

  • Based on program text
  • To connect a name reference to a variable, you (or the compiler) must find the declaration
  • Search process: search declarations, first locally, then in increasingly larger enclosing scopes, until one is found for the given name
  • Enclosing static scopes (to a specific scope) are called its static ancestors; the nearest static ancestor is called a static parent
  • Some languages allow nested subprogram definitions, which create nested static scopes (e.g., Ada, JavaScript, Common LISP, Scheme, Fortran 2003+, F#, and Python)
  • Variables can be hidden from a unit by having a “closer” variable with the same name
  • Ada allows access to these “hidden” variables

–E.g.,  unit.name

Global Scope

  • C, C++, PHP, and Python support a program structure that consists of a sequence of function definitions in a file

These languages allow variable declarations to appear outside function definitions

  • C and C++have both declarations (just attributes) and definitions (attributes and storage)

A declaration outside a function definition specifies that it is defined in another file

  • PHP

–Programs are embedded in HTML markup documents, in any number of fragments, some statements and some function definitions

–The scope of a variable (implicitly) declared in a function is local to the function

–The scope of a variable implicitly declared outside functions is from the declaration to the end of the program, but skips over any intervening functions (Global variables can be accessed in a function through the $GLOBALS array or by declaring it global)

  • Python

–A global variable can be referenced in functions, but can be assigned in a function only if it has been declared to be global in the function

Evaluation of Static Scoping

  • Works well in many situations
  • Problems:

–In most cases, too much access is possible

–As a program evolves, the initial structure is destroyed and local variables often become global; subprograms also gravitate toward become global, rather than nested

Dynamic Scope

  • Based on calling sequences of program units, not their textual layout (temporal versus spatial)
  • References to variables are connected to declarations by searching back through the chain of subprogram calls that forced execution to this point

thats all about this session today, Thank you for your attention.

Sources :

https://www2.southeastern.edu/Academics/Faculty/kyang/2014/Fall/CMPS401/ClassNotes/CMPS401ClassNotesChap05.pdf CMPS401ClassNotesChap05.doc

https://web.cs.dal.ca/~nzeh/Teaching/3136/

http://www3.cs.stonybrook.edu/~pfodor/courses/CSE307/L03_names.pdf

http://cms.binus.ac.id/Backend2/ContentCoNEW//T0152/CO/T01520030220134031Pertemuan%203%20-%20Names,%20Bindings,%20and%20Scopes.ppt

 

Posted in Session Summary | Leave a comment

Session 2

Programming Language Concept

September 30th, 2017

in that day’s session we discuss about the sub-chapter of the programming language concept and what we gonna learn in programming language concept course.

as you can see in the picture there about 6 branches (sub-chapter) that links to the introduction of Programming Language concept, and each branch has their own branches that links to the detail of each sub-chapter, so lets get started.

first of all is Why, Why should we learn Programming Language Concept ? as we know in the last session we discuss last week, Programming language is important because it defines the relationship, semantics and grammar which allows the programmers to effectively communicate with the machines that they program. A programming language serves several purposes: You can instruct the computer what
to do in a human-readable form.

by knowing the basic concept of programming language, we could learn a new programming language to communicate and compute with computers, find a new way to express our ideas with an advance system in a advance programming language and then we could implement it in the world that we live in to create a better world.

the second branch is about Programming domain, A programming domain defines a specific kind of use for a programming language. as we look in the branches we could programming language for a specific kind of use, such as :

the third branch is about the evaluation of language criteria, about its writeability(is it easy to create), about its reliability (does it perfoms well), and finally, its cost (the expenses that the creator uses to build the project).

the forth branch is about influences on programming design, in here we will learn about computer architecture(computer architecture is a set of rules and methods that describe the functionality, organization, and implementation ofcomputer systems. Some definitions of architecture define it as describing the capabilities and programming model of a computer but not a particular implementation.), and Programming design and methodologist(the way of solving the problems with computer and how to design the good algorithms so that the computer can solve the problem accurately and efficiently).

the fifth branch we talk about Language Categories, and these are :

  • imperative, imperative programming is a programming paradigm that uses statements that change a program’s state. In much the same way that the imperative mood in natural languages expresses commands, an imperative program consists of commands for the computer to perform.
  • object-oriented programming, Objectoriented programming (OOP) is aprogramming language model organized aroundobjects rather than “actions” and data rather than logic. Historically, a program has been viewed as a logical procedure that takes input data, processes it, and produces output data.
  • logic, Logic programming is a type of programming paradigm which is largely based on formal logic. Any program written in a logic programming language is a set of sentences in logical form, expressing facts and rules about some problem domain.
  • scripting language, A scripting or script language is a programming language that supports scripts: programs written for a special run-time environment that automate the execution of tasks that could alternatively be executed one-by-one by a human operator.Scripting languages are often interpreted (rather than compiled).

and the last branch, the sixth branch we will talk about Implementation, programming language implementation is a system for executing computer programs.There are two general approaches to programming language implementation:

  • Compilation: A compiler takes as input a program in some language, and translates that program into some other language, which may serve as input to another interpreter or another compiler.
  • Pure – Interpretation: An interpreter takes as input a program in some language, and performs the actions written in that language on some machine.
  • Hybrid Implementation System: The implementation of a hierarchical, process-oriented programming language for simulation (HSL) is described. It features a hybrid approach, involving the front end of a compiler and the back end of an interpreter. An HSL program is dichotomous in structure.

thats it about the summary of session 2, i hope you guys enjoy reading it, Thank you.

Sources :

https://en.wikipedia.org/wiki/

 

Posted in Session Summary | Leave a comment

Session 1

Introduction

September 23rd, 2017

In that day’s session, we (LH01 class participant & Lecturer , Ms. Yanfi) discuss about “What is Programming Language Concept” and “What are the Rules Applied in the Class while the lecturer is teaching”,  at that session we discuss more about what are the assignment and what its format, the learning outcomes.

First thing first, What is Programming Language Concept ? A programming language is a formal language that specifies a set of instructions that can be used to produce various kinds of output. Programming languages generally consist of instructions for a computer. Programming languages can be used to create programs that implement specific algorithms.
And therefore, Why should we learn Programming Language ? Programming language is important because it defines the relationship, semantics and grammar which allows the programmers to effectively communicate with the machines that they program. A programming language serves several purposes: You can instruct the computer what
to do in a human-readable form.

And the second thing that we discuss that day is, What are the rules applied in the Class when the lecturer is teaching ? the rules are as follows :

  • Dont be late for class,10 minutes late after the class begun could lead you to reducement of your points (our lecturer has a point for good doings and bad doings while in session, this points is a compensation for our scores if its below requirement, a bonus score as i preffer).
  • Dont eat while lecturing activity is in progress without any permission from the lecturer.
  • the lack of lazyness and tardyness while doing an asssignment could lead you to the decreasing of your score.
  • Sleeping or any undiscipline action is prohibited during class.

And the third thing is, Assignment. every lecturer has their own way to how to submit an assignment and its requirment. for our Programming Language Concept lecturer (Ms. Yanfi) is as follows :

  • Assignment should be submitted in the form of a blog
  • the blog should consist of session 1 to 13’s summary, and for every session’s summary must have at least 300 words for each summary
  • 1 person should have 1 blog
  • sometimes in GLSC, there is a GLSC content that consist of Question/Quiz, the answer for the question should be submitted in the Blog.
  • the submission for the Quiz should be submit no later than 1 week after upload, so keep updated and keep checking the forum for assignment.
  • and for Session 7 and Session 13, there will be a review for personal assignment, so please keep in touch for you blog assignment.

thats all for the assignment, and for the last thing that we discuss that day is about Programming Language Concept’s learning outcome.

For the learning outcome, Programming language concept’s score will be taken 20% from your assignment, 30% from your mid-term test, and 50% from your final test.

Thats all for summaries of the first session . Thank you 🙂

 

Posted in Session Summary | Tagged | Leave a comment