Unit 4 - Programming
Unit 4 - Programming
"A language that doesn't affect the way you think about programming, is not worth knowing".
Alan Perlis
Overview
Estos son los objetivos y contenidos de esta unidad
OBJETIVOS
Entender diversos textos escritos sobre lenguajes de programación, programación y bases de datos
Usar la voz pasiva
Diferenciar la voz activa de la pasiva
Utilizar verbos seguidos de preposición
Usar las oraciones condicionales
Usar conectores y conjunciones que indican condición
Traducir frases sencillas sobre lo estudiado en la unidad
Entender vídeos sencillos sobre las bases de datos y programación
CONTENIDOS
Gramática Vocabulario
Introduction
Unit 4 - Programming 18/04/2018 Página 1 de 34
Which ones?
What language do you think is best for making Web pages? Games? Text processing?
Did you know that the earliest programming languages predate the invention of the computer and were used to
direct the behavior of machines?
There are thousands of different programming languages in use today. How can you know which ones are
worth learning?
How do you know which ones are the best for your IT field of choice?
Let's start by learning facts about what a programming language is and some basic information about the most
important ones.
Photo:adapted from:wikipedia commons
When we use a natural language to communicate with each other, speakers can be ambiguous and sometimes make errors,
and still expect to be understood. However, figuratively speaking, computers "do exactly what they are told to do",
and
cannot "understand" what code the programmer intended to write. The
combination of the language definition, a program,
and the program's inputs must fully specify the external behavior that occurs when the program is executed, within the
domain of control of that program.
The description of a programming language is usually split into the two components of syntax (form: how the various
symbols of the language may be combined) and semantics (providing meaning to programs: the meaning that the language
constructs).
Most programming languages are purely textual; they use sequences of text including words, numbers, and punctuation,
Unit 4 - Programming 18/04/2018 Página 2 de 34
much like written natural languages. On the other hand, there are some programming languages which are more graphical in
nature, using visual relationships
between symbols to specify a program.
Not all syntactically correct programs are semantically correct. Many syntactically correct programs are ill-formed; and may
result in an error on translation or execution.
The term computer language is sometimes used interchangeably with programming language.
However, the usage of
both terms varies among authors. One usage describes programming languages as a subset of computer languages. In this
way, languages used in computing that have a different goal than expressing computer programs are generically designated
computer languages. For instance, *markup languages are sometimes referred to as computer languages to emphasize that
they are not meant to be used for programming.
There are plenty of technical characteristics with which to compare programming languages:
how many key words,
maximum length of identifier, type-checking facilities, polymorphism, prevalence, and so on. It is almost infinitely
complex. But
the following comparison criteria, which are centered on outcomes, can be very interesting to take into account:
• Ease of learning
• Ease of understanding
• Speed of development
• Help with enforcement of correct code
• Performance of compiled code
• Supported platform environments
• Portability
• Fit-for-purpose
*markup:The collection of tags that describe the specifications of an electronic document, as for formatting.
Adapted from:http://msdn.microsoft.com/en-us/library/cc168615.aspx
http:http://en.wikipedia.org/wiki/Programming_language
algorithm A description in precise but natural and mathematical language of how a problem is solved
ASCII The original common character code for computers using 8 bits
binding A relationship between two things, typically an identifier and some one of its properties or attributes
"Beginners
All-purpose Symbolic Insctruction Code", a family of languages developed for teaching
BASIC
programming and given away with early IBM PCs
binary Pertaining to 2. Binary operators have two operands. Binary numbers have base 2 and use 2 symbols (*)
Binary
digit. A bit has one of two values traditionally named 0 and 1. Eight bits make a byte. and four bits a
bit
nibble. So 2 nibbles = 1 byte
C++ Hybrid child of C with object oriented features and generic functions and classes
A term used for both the statements written in any programming language -the source code , and a term
code for the source code after it has been processed by a compiler and made ready to run in the computer: the
object code-
A program that translates another program written in a high-level language into machine language so that
compiler
it can be executed
lexeme A string of characters in a language that is treated as a single unit in the syntax and semantics
parameter Something that is used in a subprogram that can be changed when the subprogram is called
To convert a sequence of tokens into data structures that can be used to interpret or translate the
parse
sequence
PL Programming Language
A piece of code that has been named and can be referred to by that name (called) as many times as is
subprogram
needed
The
basic component of source code. Character's are categorized as one of five classes of tokens that
token
describe their functions (constants, identifiers, operators, reserved words, and separators)
BINARY DECIMAL
0 1
1 1
10 2
11 3
100 4
101 5
...
Self-assessment
Now, it is your turn. Find a correct match of the expressions and phrases related to programming in column A
within column B. If you have any problems, or you want to find out what they are referred to, you can look them up
here.
a. Object-oriented
01. Generation
b. Data
02. Polymorphism
c. Software
03. Detection
d. Code
04. Semantics
e. Dataflow
05. Algorithm
f. Real Time
06. Abstraction
h. High Level
08. Paradigm
i. Embedded
09. Analysis
j. Parametric
10. Solving
k. Communication
11. Flow
l. High-order
12. Debugging
m. Levels of
13. System
n. Parallel
14. Engineering
ñ. Problem
15. Optimization
o. Programming Language
16. Language
p. Program
17. Systems
q. Error
18. Error
r. Compilation
19. Protocol
s. Compiler
20. Functions
Submit
The task is further complicated by the fact that languages can be classified along multiple lines.
For example, Java is
both an object-oriented language (because it encourages object-oriented organization) and a concurrent language (because
it contains built-in constructs for running multiple threads in
parallel). Python is an object-oriented scripting language.
Dozens of categories exist according to different criteria; some languages are named problem oriented, while others are
classified according to their level of abstraction: low level or high level.
One of the most fundamental ways programming languages are characterized is by programming paradigm. A
programming paradigm provides the programmer's view of code execution.
Adapted from:http://www.giac.org/cissp-papers/97.pdf / http://en.wikipedia.org/wiki/Programming_language
Problem oriented languages are designed to solve a narrow class of problems. A user of such a language need
not express in detail the procedure used to solve a problem. Readymade procedures are pre-programmed. The
user merely presents the data in a flexible ‘language'.
Language-Oriented Programming considers the creation of special-purpose languages for expressing problems
a standard part of the problem solving process.
Language oriented programming (LOP) is a style of computer programming in which, rather than solving problems
in general-purpose programming languages, the programmer creates one or more domain-specific languages
(DSLs) for the problem first, and solves the problem in those languages. Examples of DSLs include spreadsheet
macros, YACC for parsing and compilers, Csound, a language used to create audio files, and GraphViz, a
language used to define directed graphs, and create a visual representation of that graph.
DSLs focus on doing one sort of task well. For instance, GraphViz is
designed to create images of graphs in a
variety of formats, but GraphViz lacks the capability to perform some basic tasks, e.g. accessing a network socket,
receiving additional user input, or manipulating strings
Adapted from:http://www.giac.org/cissp-papers/97.pdf
A step ahead
According to their level of abstraction, there are two major types of programming languages. These are Low
Level Languages and High Level Languages.
Low Level languages are further divided in to Machine language and Assembly language.
Machine Language
It is the only language that is directly understood by the computer. It does not need any translator program. We
also call it machine code and it is written as strings of 1′s (one) and 0's (zero).
When this sequence of codes is
fed to the computer, it recognizes the codes and converts it in to electrical signals needed to run it. For example, a
program instruction may look like this:
1011000111101
It is not an easy language to learn because it's difficult to understand. It is efficient for the computer but very
inefficient for programmers. It is considered to be a first generation language.
Assembly Language
It is the first step to improve the programming structure. Assembly languages are similar to machine languages,
but they are much easier to program in because they allow a programmer to substitute names for numbers.
The set of symbols and letters forms the Assembly Language and a translator program is required to translate the
Assembly Language to machine language. This translator program is called `Assembler'. It is considered to be a
second-generation language.
♦
In comparison to low-level programming languages, high-level languages
are simple languages that use
English and mathematical symbols like +, -, %, / etc. for their program construction. They are easier to use and
may automate significant areas of computing systems, making the process of developing a program not so
complicated and more understandable than a
lower level language. The amount of abstraction provided defines
how "high level" a programming language is. Programs written in a high-level language must be translated into
machine language by a compiler or interpreter. Java, C, C++ or Perl are examples of high-level
languages.
Adapted from:http://en.wikipedia.org/wiki/High-level_programming_language
Photo:freedigitalphotos.net
Self-assessment
Read the texts above and decide if these statements are TRUE or FALSE
1. It is not an easy task to classify programming languages
True. False.
2. DSL are general purpose programming languages
True. False.
3. When a programming language has very little or no abstraction from the details of the computer is called high-
level language
True. False.
4. The only language which does not require a translator program is machine language
True. False.
5. In assembly languages symbols and letters are used
True. False.
A programming paradigm is a general approach, orientation, or philosophy of programming that can be used when a
program is carried out. One paradigm may be generally better for certain kinds of problems than other paradigms are for
those problems, and a paradigm may be better for certain kinds of problems than for other kinds of problems.
If a programming language is adequate (or at least designed to be adequate) for a particular paradigm, the language is said
to be a language of that paradigm. For example, C is considered to be an imperative language, Java is an object-oriented
language, and Prolog is considered to be a logic programming language.
There are four main paradigms: object-oriented, imperative, functional and logic programming.
A programming language can support multiple paradigms. For example, programs written in C++ or Object Pascal
can be
purely procedural, or purely object-oriented, or contain elements of both paradigms. Software designers and programmers
decide how to use those paradigm elements.
In object-oriented programming, programmers can think of a program as a collection of interacting objects, while in functional
programming a program can be thought of as a sequence of stateless function evaluations.
OBJECT-ORIENTED PROGRAMMING (OOP) tries to make programs in a similar way to how people think about and deal
with the world.
We have seen that in other styles of programming, a programmer faced with some problem must identify a computing task
that needs to be performed in order to solve the problem. Programming then consists of finding a sequence of instructions
that will accomplish that task. But at the heart of object-oriented programming, instead of tasks we find objects that have
behaviors, that hold information, and that can interact with one another. Programming consists of designing a set of objects
that model the problem at hand.
Languages designed mainly for OOP, but with some procedural elements: C++, Java, C#, VB.NET, Python.
Adapted from:http://math.hws.edu/eck/cs124/downloads/OOP2_from_Univ_KwaZulu-Natal.pdf
- http://en.wikipedia.org/wiki/Object-oriented_programming
Imperative programming is a programming paradigm that describes computation in terms of statements that change a
Unit 4 - Programming 18/04/2018 Página 8 de 34
program state. In much the same way that imperative mood in natural languages expresses commands to take action,
imperative programs define sequences of commands for the computer to perform. An imperative program is a list, or
sequence, of commands or instructions.
The term is used in opposition to declarative programming, which expresses what the program should accomplish without
prescribing how to do it in terms of sequences of actions to be taken.
The 'first do this, next do that' is a short phrase which really describes the spirit of the imperative paradigm. The basic idea is
the command, which has a measurable effect on the program state. The phrase also reflects that the order to the
commands is important. 'First do that, then do this' would be different from 'first do this, then do that'.
When imperative programming is combined with subprograms it is called procedural programming. In either case the
implication is clear. Programs are directions or orders for performing an action.
Keywords and phrases: Assignment, goto, structured programming, command, statement, procedure, control-flow,
imperative language, assertions, axiomatic semantics. state, variables, instructions, control structures.
http://blog.jessitron.com/2012/08/brains-computers-and-problem-solutions.html
This style of programming is directly inspired by assembly programming. It can be found in the earliest general-purpose
programming languages (Fortran, C, Pascal, Basic, Cobol).
Adapted from:http://en.wikipedia.org/wiki/Imperative_programming - http://people.cs.aau.dk/~normark/prog3-03/html/notes/paradigms
Vocabulary exercise
Interact
Functional
Behavior
Perform
Accomplish
Information
Procedural
Declarative
Particular
Support
Submit
Declarative programming is a programming paradigm that expresses the logic of a computation without describing its control
flow. Many languages applying this style attempt to minimize or eliminate side effects by describing what the program should
accomplish, rather than describing how to go about accomplishing it (the how is left up to the language's implementation).
This is in contrast with imperative programming, in which algorithms are implemented in terms of explicit steps.
→ Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions
and avoids state changes as much as possible and
works with data flowing between functions. It emphasizes the application
of functions, in contrast to the imperative programming style, which emphasizes changes in state. Functional programming
wants to avoid state.
In functional programming, programs are executed by evaluating expressions, in contrast with imperative programming where
programs are composed of statements which change global state when executed.
Functional programming decomposes a problem into a set of functions. Ideally, functions only take inputs and
produce outputs, and don't have any internal state that affects the output produced for a given input. Well-known functional
languages include the ML family (Standard ML, OCaml, and other variants) and Haskell.
One of the advantages of functional languages is that testing and debugging a functional-style program is easier.
→ Logic programming languages, of which PROLOG (programming in logic) is the best known, state a program as a set of
logical relations. Such languages are similar to the SQL database language*.
A program is executed by an "inference engine"
that answers a question by searching these relations systematically to make inferences that will
answer a question.
PROLOG has been used extensively in natural language processing and other AI** programs.
* Structured Query Language, a special-purpose programming language designed for managing data in relational database
management systems (RDBMS).
** Artificial Intelligence: John McCarthy, who coined the term in 1955, defines the term as "the science and engineering of
making intelligent machines."
Adapted from:http://docs.python.org/2/howto/functional.html - http://www.britannica.com/EBchecked/topic/346284/logic-programming-language
-
http://en.wikipedia.org/wiki/Declarative_programming
Exercise
Read the texts about programming paradigms and find words or expressions for these synonyms or definitions:
Example, model
Method, orientation
To be made of or composed
Show Feedback
In the previous texts, there were some words (mainly verbs) and the prepositions that normally follow them; based on, or
think of, for example.
Revise this list of common verbs and the prepositions that normally follow them
ACCUSE OF LISTEN TO
BELONG TO RELY ON
CONSIST OF SUCCEED IN
INSIST ON WRITE TO
Vocabulary exercise
Find these combinations of verb + preposition and write the sentence where these verbs are used.
be based on
be composed of
be faced with
consist of
deal with
Unit 4 - Programming 18/04/2018 Página 12 de 34
decompose into
focus on
operate on
split into
think about
think of
translate into
Show Feedback
There are only 2 months left before TIOBE will announce the programming language of the year 2012. Objective-C crossed
the 10% border for the first time this month and continues to rise. Other mobile phone application languages such as C, C++
and Java are not rising fast enough
to compete seriously with Objective-C. Another possible competitor for the award, C#,
shows a strong dip this year for some unknown reason. So nothing seems to stop Objective-C to win 2 consecutive years in a
row.
The TIOBE Programming Community index is an indicator of the popularity of programming languages. The index is updated
once a month. The ratings
are based on the number of skilled engineers world-wide, courses
and third party vendors. The
popular search engines Google, Bing, Yahoo!, Wikipedia, Amazon, YouTube and Baidu are used to calculate the ratings.
Observe that the TIOBE index is not about the best programming language or the language in which most lines of code have
been written.
The index can be used to check whether your programming skills are still up to date or to make a strategic decision about
what programming language should be adopted when starting to build a new software system. The definition of the TIOBE
index can be found here:
1 2 C 19.224% +1.90% A
6 4 C# 5.591% -1.73% A
7 7 (Visual)
Basic 5.032% -0.01% A
12 16 Delphi/Object
Pascal 0.995% +0.12% A
15 23 Visual
Basic .NET 0.769% +0.24% A-
Exercise
Read the text above and answer the questions about it:
1. What program will probably be the programming language of the year 2012?
6. What does the text suggest you should do if you want to start a new software system?
Show Feedback
Listening practice
http://www.softwarecareerlaunch.com
Self-assessment
4.-
The sooner you choose a language to start up, the better. It doesn't matter which one, what matters is how
quickly you do it.
a. This statement is false
b. This statement is true
11.- According to the speaker the most popular language today is ...
a. Object C
b. C#
A step ahead
1. C
2. Java 8. Python
C is a general-purpose
Java is a programming language Python is a general-purpose,
programming language which
originally developed by James Gosling interpreted high-level programming
was initially developed by
at Sun Microsystems and released in language. It supports multiple
Dennis Ritchie between 1969
1995. Java is a general-purpose, object- programming paradigms, primarily
and 1973 for use in the UNIX
oriented language that is specifically but not limited to object-oriented,
operating system. C is an
designed to have as few imperative and, to functional
imperative (procedural)
implementation dependencies as programming styles. It was written
language. It was designed to
possible. It is intended to let application by Guido van Rossum in the late
be compiled using a
developers "write once, run anywhere" 1980's and was intended for
relatively straightforward
(WORA), meaning that code that runs general programming purposes.
compiler. C was useful for
on one platform does not need to be Python was not named after the
many applications that had
recompiled
to run on another. Java is snake but actually after the Monty
formerly been coded in
one of the most popular programming Python comedy group. Python is
assembly language, such as
languages in use. Programs written in characterized
by its use of
in system programming.
Java can run on many different indentation for readability, and its
Although C is a relatively old
computer architectures and operating encouragement for elegant code by
language, it is still widely
systems because of the use of the JVM making developers do similar things
used for system
(Java virtual machine). Java is the in similar ways. Python is used as
programming, writing other
language most likely to be taught in the main programming choice of
programming languages, and
university computer science classes. both Google and Ubuntu.
in embedded systems.
Read the texts above and then, choose the best alternative for each question.
WHICH ONE ...?
a. C
b. Java
c. Python
3. Programs written in this language can run on many different computer architectures and operating systems.
a. C
b. Java
c. Python
We can develop a new procedural language A new procedural language can be developed
In the current article I want to ... The current article is intended to convey ...
The conclusions regard these data are ... These data are regarded to be ...
REMEMBER:
→
the correct form of the verb 'to be' + the past participle of the verb in question:
We can use the passive in any tense. To make different tenses we change the verb to be.
REMEMBER:
The passive is used more often in English than in Spanish, where we use other structures.
For example: "All the files can be viewed but they cannot be modified" → Se pueden ver todos los ficheros pero no se
pueden modificar
"The solution must be converted into the proper syntax of a programming language" → Se debe
convertir la solución en una adecuada sintáxis de un lenguaje de programación
Review
Self-assessment
Practice
Exercise
4. The syntax is one of the two components of any programming language. (It / can /specify using a Type-2
grammar)
5. There are many programming languages, and (many / design / from the very beginning)
6. Everyone believes that the course will be very useful for students. (It / teach / Professor Daniels)
7. There are two major types of programming languages: Low Level Languages and High Level Languages. (Low
Level languages / divided / into Machine language and Assembly language)
8. I can't print the document, there's something wrong with the printer. How often (it / clean?)
9. In case you have a problem, (the Internet Service provider / must / contact)
Show Feedback
Self-assessment
Read the text below and fill in the missing words. Choose from the list below
The term low level means closeness to the way in which the machine has been
. Low level languages
are machine oriented and require extensive knowledge of computer hardware and its configuration.
Machine Language
program is
. It is also
machine code and it is
as strings of 1's (one)
and 0's (zero). When this sequence of codes is fed to the computer, the codes are
and
into electrical signals needed to run it. For example, a program instruction may look like this:
1011000111101
It is not an easy language to be
because it is difficult to be
. It is efficient
Advantage
The only advantage is that programs of machine language run very fast because no translation program is
for the CPU.
Disadvantages
1. It is very difficult to program in machine language. The programmer has to know details of hardware to write
a program.
2. A lot of codes have to be
to write a program which results in program errors.
3. The program is difficult to be
Adapted from:http://www.itsavvy.in/programming-languages
Get score
Show/Clear Answers
Practice
Translation
1. PHP is the Web's most common programming language and it has been proved to be powerful and robust.
2. Code for the emulation programm should be written in open source, in a standard programming language with
good prospects for longevity and future compatibility
3. Reducativa (Educatenet) has been developed entirely in Java, a programming language oriented towards
objects, robust, portable y
versatile, which has become the new Standard worldwide-
5. Like the BASIC programming language, Visual Basic was designed to be easily learned and used
by
beginner programmers. The language not only allows programmers to create simple GUI applications, but to also
develop complex applications.
6. The Java language project was initiated by James Gosling, Mike Sheridan, and Patrick Naughton in June
1991. Java was originally designed for interactive television, but it was too advanced for the digital cable
television industry at the time. The language was initially called Oak after an oak tree that stood outside Gosling's
office; it went by the name Green later, and was later renamed Java, from Java coffee, said to be consumed in
large quantities by the language's creators.
8. All these languages follow the procedural paradigm. That is, they describe, step by step, exactly the procedure
that should, according to the particular programmer at least, be followed
to solve a specific problem. The efficacy
and efficiency of any such solution are both therefore entirely subjective and highly dependent on that
programmer's experience, inventiveness and ability.
9. Haskell is a standardized, general-purpose purely functional programming language, with non-strict semantics
and strong static typing. It is named after the American logician Haskell Curry. In Haskell, "a function is a first-
class citizen" of the programming language. As a functional programming language, the primary control construct
is the function.
10. Following the release of Miranda in 1985, interest in functional languages grew: by 1987, more than a dozen
non-strict, purely
functional programming languages existed. Of these, Miranda was the most widely used,
but
was not in the public domain. At the conference on Functional Programming Languages and Computer
Architecture (FPCA '87) in Portland, Oregon, a meeting was held during which participants formed a strong
consensus that a committee should be formed
to define an open standard for such languages. The committee's
purpose was to consolidate the existing functional languages into a common one that would serve as a basis for
future research in functional-language design.
Show Feedback
Rephrasing
e.g.: Somebody asked me how to debug the program → I was asked how to debug the program
Show Feedback
Defining the problem; take into account what the future users will need it for.
Designing the solution to the problem above. Troubleshooting is essential.
Coding the program, choosing the most suitable programming language.
Checking and debugging the program: this means you have to run your
program to see if it makes the computer do
what you wanted it to. If not, fix the program and compile and run it again.
Adapted from:http://www.ehow.com/how-does_4866883_writing-simple-computer-programs.htm
Self-assessment
WORD DEFINITIONS
1. upgrade a. to look for and remove mistakes from a computer program so that it works correctly
5. implement
e. Convert a program into a lower-level form in which the program can be executed
6. debug
f. In the established way of doing it
Submit
Computer programming is a huge field with hundreds of languages and millions of applications, and so is the range for
making programming errors of various kinds!
Logic Errors. These errors are related to the program execution: When a program written in any language compiles
and runs properly but it provides incorrect output. This is primarily due to a poor understanding of a problem, to
inaccurate translation of the algorithms into the program and lack of hierarchy of operation.This may be the most
serious of all errors.
Syntax Errors. Every programming language has a specific syntax in which code needs to be written. Any violation of
rules of the language result comes under syntax error. The compiler can detect and isolate these types of errors. If
syntax errors are present in the program, then compilation fails.
Compilation Errors. They are errors that prevent your program from running. They often occur because of syntax
errors. These errors are rectifiable in the development phase.
Run-Time Errors. Run-time errors occur while your program runs. These typically occur when your program attempts
an operation that
is impossible to carry out.The program code has compiled successfully and an executable file has
been created. But when the program is run to be tested, you find an error. This is a 'Run Time Error'. If you want these
to be rectified, then go back to the coding phase.
Finding and fixing bugs, or "debugging", has always been a major part of computer programming. As computer programs
grow more complex, bugs become more common and difficult to fix. Often programmers spend more time and effort finding
and fixing bugs than writing new code. Software testers are professionals whose primary task is to find bugs, or write code to
support testing. On some projects, more resources can be spent on testing than in developing the program.
Adapted from:http://en.wikipedia.org/wiki/Software_bug - http://www.buzzle.com/articles/computer-programming
Photo:freedigitalphotos.net
Revision exercise
2. A time clause
3. An imperative
4. A conditional sentence
7. An example of premodification
Show Feedback
A step ahead
Structured programming is a programming paradigm aimed on improving the clarity, quality, and development
time of a computer program.
At a low level, structured programs are often composed of simple, hierarchical program flow structures. These are
sequence, selection, and
repetition:
Selection refers to one of a number of instructions executed depending on the state of the program;
conditional instructions are used: if one condition is true, then process such instruction (if X, then Y). To
indicate the way a conditional structure is going to process data, we use decision tables.
Repetition refers to a statement executed until the program reaches a certain state, or operations have
been applied to every element of a collection. Loop instructions are used: instructions are processed
again and again until or while a particular condition is true or false. Flowcharts are broadly used here.
Adapted from:http://en.wikipedia.org/wiki/Structured_programming
REVISE: IF-SENTENCES
Conditional Sentences are used to express that the action in the main clause (without if) can only take place if a certain
condition (in the
clause with if) is fulfilled. There are four types of Conditional Sentences.
If + simple present
simple present
First Conditional
In first conditional sentences, the tense in the 'if' clause is the simple present, and the tense in the main clause is the
simple future
If + simple present
simple future
In these sentences, the time is the present or future and the situation is real.
They refer to a possible condition and its
probable result. They are
based on facts, and they are used to make statements about the real
world, and about particular
Unit 4 - Programming 18/04/2018 Página 26 de 34
situations. When we use this type of
conditional we mean that what we say will probably happen
Condition: present - Main clause: may, can or imperative instead of WILL: "Don't go out this evening if you have an exam
tomorrow" / "He may stay overnight if he doesn't have to work" tomorrow
Second Conditional
In second conditional sentences, the tense in the 'if' clause is the simple past, and in the main clause we use: would /
could / might + infinitive
If + simple past
would / could / might + infinitive
In these sentences, the time is present or any time, but the situation is unreal.
They are not based on facts, and they refer
to an unlikely or
hypothetical condition and its probable result. We use this conditional
to speak about very unlikely or
improbable situations
Third Conditional
The tense in the 'if' clause is the past perfect, and the tense in the main clause is the perfect conditional (would /could /
might + have + past participle)
If + past perfect
perfect conditional
If you had studied harder you would have passed the exam
If I had had a better computer I could have run the program
In these sentences, the time is past, and the situation is contrary to reality.
The facts they are based on are the opposite
of what is expressed.
Things cannot be changed because they happened in the past. This can
also be used to express regret
about something or to reproach somebody
for something.
Practice
Self-assessment
Write the right tense of the verb in brackets to make conditional sentences
1. If the network is down, we (access)
our files
3. If she (have)
enough money, she would have bought the computer.
4. If he (not start)
at once, he'll be late for the meeting.
7. He (not make)
so many mistakes if he worked more slowly.
9. If I (go)
to university, I would enroll in computer science.
15. If I (know)
you were a slow worker, I wouldn't have worked with you.
Submit
Self-assessment
2. If I had installed a suitable anti virus, my computer wouldn't have been infected with a virus
a. I didn't install a suitable anti virus, so my computer was infected with a virus
b. I installed a suitable anti virus but my computer was infected with a virus
5. If the student hadn't designed a Web page for his project, he wouldn't have got such good marks
a. He didn't get good marks
b. He got good marks
A decision table
A step ahead
A decision
table represents all possible conditions and actions. The table is divided into
columns which contain
the conditions, actions and rules. Rules may be
represented with ticks and crosses or with YES/NO
words/symbols. To see which action
to take, the user locates a tick or YES (true) in a row corresponding to a
condition. If we read the column down to the lower section, which lists action,
a tick / Yes in the row corresponding
to
a particular action indicates the action to be carried out:
Printer troubleshooter
Rules
Unit 4 - Programming 18/04/2018 Página 28 de 34
Printer does not print Y Y Y Y N N N N
Conditions
A red light is flashing Y Y N N Y Y N N
Printer is unrecognized Y N Y N Y N Y N
Actions
Ensure printer software is installed X X X X
Check/replace ink X X X X
Examples: if the printer doesn't print, then (you'll have to) check the
printer-computer cable
if a red light is flashing, then (you will have to) check ink.
Adapted from:http://en.wikipedia.org/wiki/Decision_table
Contents 3. Database
Database
freedigitalphotos.net
A way to classify databases involves the type of their contents, for example: bibliographic, document-text, statistical, or
multimedia objects. Another way is by their application area, for example: accounting, music compositions, movies, banking,
manufacturing, or insurance.
Unit 4 - Programming 18/04/2018 Página 29 de 34
An alternative concept in database design is known as Hypertext. In a Hypertext database, any object, whether it be a piece
of text, a picture, or a film, can be linked to any other object. Hypertext databases are particularly useful for organizing large
amounts of disparate information, but they are not designed for numerical analysis.
To access information from a database, you need a database management system (DBMS). This is a collection of
programs that enables you to enter, organize, and select data in a database.
Well known DBMSs include Oracle, FoxPro, IBM DB2, Linter, Microsoft Access, Microsoft SQL Server, MySQL, PostgreSQL
and SQLite. A database is not generally portable across different DBMS, but different DBMSs
can inter-operate to some
degree by using standards like SQL and ODBC together to support a single application built over more than one database. A
DBMS also needs to provide effective run-time execution to properly support (e.g., in terms of performance, availability, and
security) as many database end-users as needed.
Increasingly, the term database is used as shorthand for database management system.
Adapted from:
Adapted from:http://en.wikipedia.org/wiki/Database#Database_languages - http://www.webopedia.com/TERM/D/database.html
Exercise
Show Feedback
Reading activity
Database languages
Database languages are dedicated programming languages, shaped and used to:
define a database (i.e., its specific data types and the relationships among them),
manipulate its content (e.g., insert new data occurrences, and update or delete existing ones), and
query it (i.e., request information: compute and retrieve any information based on its data).
Database languages are data-model-specific, i.e., each language assumes and is based on a certain structure
of the data (which typically
differs among different data models). They typically have commands to instruct
execution of the desired operations in the database. Each such command is equivalent to a complex expression
(program) in a regular programming language, and thus programming in dedicated (database) languages
simplifies the task of handling databases considerably. An expression in a database language is automatically
transformed (by a compiler or interpreter) to a proper computer program that runs while accessing the database
and providing the needed results. The following are notable examples:
A major Relational model language supported by all the relational DBMSs and a standard. SQL
was one of the
first commercial languages for the relational model. It has become the most widely used database language.
Though often described as, and to a great extent is a declarative language, SQL also includes procedural
elements. SQL
became a standard of the American National Standards Institute (ANSI) in 1986, and of the
International Organization for Standards (ISO)
in 1987. Since then the standard has been improved several times
with added features. However, issues of SQL code portability between major RDBMS products still exist due to
lack of full compliance with, or different interpretations of the standard. Among the reasons mentioned are the
large size, and incomplete specification of the standard, as well as vendor lock-in.
An object model language standard (by the Object Data Management Group) that has influenced the design of
some of the newer query languages, though they cannot be considered really different from OQL.
XQuery is an XML based database language. SQL/XML combines XQuery and XML with SQL.
Adapted from:http://en.wikipedia.org/wiki/Database#Database_languages
After reading the text, decide if the statements are TRUE or FALSE
1. Databases use specifically designed programming languages
True. False.
2. Database languages use a set of instructions to execute the operations in the databalse
True. False.
3. Database languages do not need compilers to supply the final result
True. False.
4. OQL is the most commonly used language in databases
True. False.
Listening practice
Watch this video about Databases
Self-assessment
After watching the video, do this exercise: choose the best answer:
1. A Database is a ...
a. collection of information stored on a computer, which allows you to enter, access and analyze it.
b. collection of lists on a computer, which you can organize and analyze.
2. A database ...
a. works from the simplest to the most complicated things
b. only works for simple things
4. What other important information does the baker have in his database?
a. who has an egg allergy
b. who has a nut allergy
A step ahead
Whatever the approach to software development may be, the final program must satisfy some fundamental
properties. The following properties are among the most relevant:
Robustness: how well a program anticipates problems not due to programmer error. This includes
situations such as incorrect, inappropriate or corrupt data, unavailability of needed resources such as
memory, operating system services and network connections, and user error.
Portability: the range of computer hardware and operating system platforms on which the source code of a
program can be compiled/interpreted and run. This depends on differences in the programming facilities
provided by the different platforms, including hardware and operating system resources, expected
behaviour of the hardware and operating system, and availability of platform specific compilers (and
sometimes libraries) for the language of the source code.
Maintainability: the ease with which a program can be modified by its present or future developers in order
to make improvements or customizations, fix bugs and security holes, or adapt it
to new environments.
Good practices during initial development make the
difference in this regard. This quality may not be
directly apparent to
the end user but it can significantly affect the fate of a program over
the long term.
Efficiency/performance: the amount of system resources a program consumes (processor time, memory
space, slow devices such as disks, network bandwidth and to some extent even user interaction): the less,
the better. This also includes correct disposal of some resources,
such as cleaning up temporary files and
lack of memory leaks.
Adapted from:http://en.wikipedia.org/wiki/Computer_programming
Translate
Show Feedback