0% found this document useful (0 votes)
203 views

Lab 01 - Characteristics of Programming Languages (Answers) PDF

This document discusses an introduction to ITECH5403 - Lab 1 on the characteristics of programming languages. The course will involve a mix of lab questions and hands-on programming experiments with different languages. The exam will consist of questions from each lab (80%) and questions tying concepts together (20%). Students are encouraged to thoroughly research questions rather than guess answers. The lab then provides 10 review questions on topics like language design, common domains of languages, language features, control structures, abstraction, aliasing, language criteria, implementation methods, and the role of a linker. It concludes with 3 problem set questions on arguments for and against a single language, type declarations, and detrimental statements.

Uploaded by

li
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
203 views

Lab 01 - Characteristics of Programming Languages (Answers) PDF

This document discusses an introduction to ITECH5403 - Lab 1 on the characteristics of programming languages. The course will involve a mix of lab questions and hands-on programming experiments with different languages. The exam will consist of questions from each lab (80%) and questions tying concepts together (20%). Students are encouraged to thoroughly research questions rather than guess answers. The lab then provides 10 review questions on topics like language design, common domains of languages, language features, control structures, abstraction, aliasing, language criteria, implementation methods, and the role of a linker. It concludes with 3 problem set questions on arguments for and against a single language, type declarations, and detrimental statements.

Uploaded by

li
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

ITECH5403 Comparative Programming Languages

School of Science, Engineering and Information Technology

ITECH5403 - Lab 1 – Characteristics of Programming Languages

Introduction

In ITECH5403 we will use a mix of different lab types, in that some weeks there will be some questions to answer and the
rest of the lab will be hands-on programming / experimenting with various programming languages, and in other labs we'll
concentrate on strengthening our understanding of programming language design and construction issues via working
out problems.

As we're only just starting off and haven't looked at any specific languages just yet, in this lab your job is to make sure
you understand the fundamentals of how different programming languages are designed and implemented.

The exam for this course will consist of a selection of questions from each week's lab (80%) and related questions which
help to tie different areas of programming languages together (20%). If you can answer these questions in the lab – you
can answer them in the exam! Remember – in these labs you aren't expected to know every single answer from memory
– sometimes it's best to do a little research / reading / re-reading of materials and come up with a great, and correct,
answer rather than just 'taking a stab' at the question and hoping you're right!

Review Questions

1. Why is it useful for a programmer to have some background in language design, even though he or
she may never actually design a programming language? [Q1]

To have an increased capacity to express ideas.


To have the ability to make a better choice of languages for any given job.
To have an increased ability to learn new languages.
To have a better understanding of the significance of implementation.

2. What programming language has dominated the following problem domains over the last 50 years:
a. Scientific computing,
b. Business applications,
c. Artificial Intelligence.
[Q3,4,5]

Scientific: FORTRAN is the language used in past 50 years for scientific applications. FORTRAN is a general
purpose and imperative programming language that is suited for numeric computing and scientific computing.
It was originally developed by IBM in their campus in 1950s. FORTRAN is also one of most popular languages
in area of high performance computing and is used for programs that benchmark and rank the world’s fastest
supercomputers.

Business: COBOL is the language used in past 50 years for business applications. COBOL is the second oldest
high level programming language (after FORTRAN). COBOL is a language that uses english-like statements in
the code. COBOL was created by comittee of private industries, universities, and government during second
half of 1959.

CRICOS Provider No. 00103D Insert file name here Page 1 of 5


Artificial Intelligence: LISP is a family of computer programming languages with polish prefix notation. LISP
is the second oldest high level programming language. It was specified by John McCarthy originally created as
a practical mathematical notation for computer programs in 1958. The interchangeability of code and data
also gives Lisp its instantly recognizable syntax. All program code is written as s-expressions, or parenthesized
lists.

3. What is the disadvantage of having too many features in a language? [Q7]

Too many features means that not all programmers will know all features of a language. The language will be
harder to learn (as there's more to learn) – and there will be multiple ways of doing the same thing, some of
which will be more efficient than others. This increased complexity will result in decreased writability (which
directly affects simplicity) – which in turn results in increased cost in terms of development and maintenance!

4. What primitive control statement is used to build more complicated control statements in languages
that lack them? [Q11]

The selection statement plus GOTO is used to build more complicated control statements such as the FOR loop
statement.

5. What construct of a programming language provides process abstraction? [Q12]

The use of a subprogram to implement a sort algorithm that is required several times in a program. Without the
subprogram, the algorithm would need to be copy-pasted at all places it need to be and thus making the code longer and
harder to understand and read.

6. What is aliasing? [Q15]

Aliasing is having two or more distinct name to access the same memory cell. It is considered dangerous feature. For
example, assigning two pointers with different names to the same variable. In some languages, aliasing is used to
overcome deficiencies in the language’s data abstraction facilities.

7. Give an example of two language design criteria that are in direct conflict with each other. [Q24]

The two criteria that conflict are reliability and cost of execution. For example, the Java language definition demand that
all references to array elements be checked to ensure that the index or indices are in their legal ranges. This step adds a
great deal to the cost of execution of Java programs that contain large numbers of references to array elements. C does
not require index range checking, so C programs execute faster than semantically equivalent Java programs, although
Java programs are more reliable.

8. What are the three general methods of implementing a programming language? [Q25]

– Compilation is the method of implementation that translate programs into machine language that can be executed
directly on the computer. Compilation has the advantage of very fast program execution once the translation is complete.

CRICOS Provider No. 00103D Page 2 of 5


— Pure Interpretation is method of implementation by using another program called interpreter to interpret a program
with no translation whatsoever. The interpreter program acts as a software simulation of a machine whose fetch-execute
cycle deals with high-level language program statements rather than machine instructions

— Hybrid Implementation system is a method to implement a program by translating highlevel language programs into
an intermediate language designed to allow easy interpretation. This method is faster than pure interpretation because
the source language statements are decoded only once.

9. What does a linker do? [Q28]

A linker is a computer program that takes one or more object files generated by a compiler and combines them into a
single executable file, library file, or another object file. In essence, the linker substitutes the address of a function in a
library with the call to that function so that control can 'jump' to the function when required.

10. Why is the von Neumann bottleneck important? [Q29]

The von Neumann bottleneck is important because it limits the amount of work that can be performed by a processor due
to the time required to transfer instructions and data to the processor, which is typically longer than the time required by
the processor to perform the instructions on the data. When data is transferred to a processor slowly, the CPU is
effectively 'starved' of work, and must idle until new instructions/data become available. This is inefficient because
without data and instructions to work on, the processor is not working at full capacity.

Problem Set

1. What arguments can you make FOR and AGAINST the idea of using a single programming language
for all problem domains? Try for at least 3 of each! [PS3]

Some arguments for having a single language for all programming domains are: It would dramatically cut the
costs of programming training and compiler purchase and maintenance; it would simplify programmer
recruiting and justify the development of numerous language dependent software development aids.

2. How do type declaration statements for simple variables affect the readability of a language,
considering that languages do not require them? [PS15]

The use of type declaration statements for simple scalar variables may have very little effect on the readability
of programs. If a language has no type declarations at all, it may be an aid to readability, because regardless
of where a variable is seen in the program text, its type can be determined without looking elsewhere.
Unfortunately, most languages that allow implicitly declared variables also include explicit declarations. In a
program in such a language, the declaration of a variable must be found before the reader can determine the
type of that variable when it is used in the program

CRICOS Provider No. 00103D Page 3 of 5


3. What common programming language statement, in your opinion, is most detrimental to readability?
[PS6]

Example only: The go to statement in my opinion can be the most detrimental to program readability, because
it makes it difficult to keep track of where the program has been and will go during debugging. Extensive use
of go to statements make it difficult to impossible to keep the program code in a top down format.

4. Explain the different aspects of the cost of a programming language. [PS9]

The cost of training programmers to use a language - which is a function of the simplicity and orthogonality of
the language.

The cost of writing programs in a language - which is a function of the writability of a language, and how close
the application matches the language's problem domain.

The cost of compiling programs in a language - for large projects, even on fast computers this can be many
hours per compilation.

The cost of executing programs in a language - which often relates to how many run-time type checks etc. that
are performed during execution. If a language performs a large number of run-time checks, it will never be
fast. If it performs very few, it is likely to be unreliable! Catch 22! =(

The cost of the language platform and tools - to develop in Java, for example, you don't need expensive
hardware, and the compiler and all tools are completely free. The tools for most all modern programming
languages are free to use, although you may still need some expensive hardware to do anything useful with it.

The cost of poor reliability - if software written in a given programming language fails with the result in loss of
expensive equipment (satellite, airplane etc.), or worse, loss of lives (nuclear reactor, x-ray machine,
autonomous vehicle etc.) then it will result in significant financial costs also.

The cost of maintaining programs - which includes both corrections to existing functionality and additions of
new functionality. Because software maintenance is generally performed by developers who were not the
original authors of the software, poor readability can make this task extremely challenging!

5. Describe some trade-offs between efficiency and safety in some programming language you know.
[PS11]

Example only: In the C programming language, efficiency (i.e. speed of execution) has been traded off with safety in a
number of ways, for example:

- Bounds checking is not performed on arrays, and attempting to read/write beyond the end of an array can cause
data corruption and crashes (segfaults) – but it's very fast!

- C does not provide objects / inheritance / polymorphism so the data structures are relatively 'clean' and a
minimum of overhead is required to manage them behind the scenes. The downside of this is that modern OO
principles of data encapsulation / polymorphism cannot be used, and we must instead work harder as
programmers to create the same functionality (but again, it's very fast!)

CRICOS Provider No. 00103D Page 4 of 5


6. Discuss in detail what features a useful, high quality (i.e. 'good') programming language should have?
(please keep in mind trade-offs that exist in the real world, this isn't a 'fantasy' language – it's YOUR
ideal set of trade-offs!) [PS12-Mod]

Several characteristics believed to be important to the usefulness and quality of programming language:

 Simplicity : A good programming language must be simple and easy to learn and use. It should provide
a programmer with a clear, simple and unified set of concepts, which can be easily grasped. The overall
simplicity of a programming language strongly affects the readability of the programs written in that
language, and programs, which are easier to read and understand, are also easier to maintain. It is
also easy to develop and implement a compiler or an interpreter for a programming language, which is
simple. However, the power needed for the language should not be sacrificed for simplicity.

 Naturalness:- A good language should be natural for the application area, for which it has been
designed. That is, it should provide appropriate operators, data structures, control structures, and a
natural syntax to facilitate the users to code their problem easily and efficiently.

 Abstraction:- Abstraction means the ability to define and then use complicated structures or operations
in ways that allow many of the details to be ignored. The degree of abstraction allowed by a
programming language directly effects its writ ability. Object oriented language support high degree of
abstraction. Hence, writing programs in object oriented language is much easier. Object oriented
language also support re usability of program segments due to this features.

 Efficiency :- Programs written in a good programming language are efficiently translated into
machine code, are efficiently executed, and acquire as little space in the memory as possible. That is a
good programming language is supported with a good language translator which gives due
consideration to space and time efficiency.

 Structured:- Structured means that the language should have necessary features to allow its users to
write their programs based on the concepts of structured programming. This property of a moreover, it
forces a programmer to look at a problem in a logical way, so that fewer errors are created while
writing a program for the problem.

 Compactness :- In a good programming language, programmers should be able to express intended


operations concisely. A verbose language is generally not liked by programmers, because they need to
write too much.

 Locality :- A good programming language should be such that while writing a programmer concentrate
almost solely on the part of the program around the statement currently being worked with.

Any valid answers accepted.

7. Write an evaluation of a programming language you know, using the nine criteria discussed in this
week's class (Simplicity, Orthogonality, Data types, Syntax design, Expressivity, Type checking,
Exception handling, Restricted aliasing). [PS16]

Any valid answers accepted.

CRICOS Provider No. 00103D Page 5 of 5

You might also like