Friday, June 28, 2013

Chapter 16 - Logic Programming Language

Review Question 1. What are the three primary uses of symbolic logic in formal logic ? - to express propositions, to express the relationships between propositions, and to describe how new propositions can be inferred from other propositions that are assumed to be true. 2. What are the two parts of a compound term ? - functor and and ordered list of of parameters 3. What are the two modes in which a proposition can be stated ? - one in which a proposition is defined to be true and one in which that the proposition is something to be determined. 4. What is general form of a proposition in clausal form ? -B1 U B2 U . . . U Bn C A1 n A2 n . . . n Am 5. What are antecedents ? Consequents ? - Antecedents are right side of a clausal form proposition. Consequent is left side of a clausal form propositions 6. Give general definitions of resolution and unification - Resolution : inference rule that allows inferred propositions to be computed from given propositions, thus providing a method with potential application to automatic theorem proving. Unification : Process of determining useful values for variables. 7. What are the forms of Horn clauses ? - a. Have a single atomic proposition on the left side b. empty left side. 9. What does it mean for a language to be nonprocedural ? - Language in which the programs do not exactly state how a result is to be computed but rather describe the form of the result. Problem Set 1. “All predicate calculus propositions can be algorithmically converted to clausal form”. Is this statement true or false ? Explain. - True. 8. Critically comment on the following statement : “ Logic programs are nonprocedural” - It is true, because logical programs use lots of different processes based on its conditions. If a certain logical requirement is true, then a program will execute the corresponding process, instead of procedurally executing the statements. 9. From a book on Prolog, learn and write a description of a monkey-banana prolem. Why does Prolog allow this problem to exist in its implementation ? - The problem is defined as this : a monkey is in a room. Suspended from the ceiling is a bunch of bananas, beyond the monkey’s reach. However, in the room there are also a chair and a stick. The ceiling is just the right height so that a monkey standing on a chair could knock the bananas down with the stick. The monkey knows how to move around, carry other things around, reach for the bananas, and wave a stick in the air. What is the best sequence of actions for the monkey? It exists to create a variation in output of Prolog. As Prolog is an AI programming language, a variation might be needed in AI output to make them respond relevant to the situation.

Chapter 15 - Functional Programming Language

REVIEW QUESTION 2. What does a lambda expression specify? => The predicate function is often given as a lambda expression, which in ML is defined exactly like a function, except with the fn reserved word, instead of fun, and of course the lambda expression is nameless. 5. Explain why QUOTE is needed for a parameter that is a data list. => To avoid evaluating a parameter, it is first given as a parameter to the primitive function QUOTE, which simply returns it without change. 6. What is a simple list? => A list which membership of a given atom in a given list that does not include sublists. 7. What does the abbreviation REPL stand for? =>REPL stand for read-evaluate-print loop. 11. What are the two forms of DEFINE? => The simplest form of DEFINE is one used to bind a name to the value of an expression. This form is (DEFINE symbol expression) The general form of such a DEFINE is (DEFINE (function_name parameters) (expression) 13. Why are CAR and CDR so named? => The names of the CAR and CDR functions are peculiar at best. The origin of these names lies in the first implementation of LISP, which was on an IBM 704 computer. The 704’s memory words had two fields, named decrement and address, that were used in various operand addressing strategies. Each of these fields could store a machine memory address. The 704 also included two machine instructions, also named CAR (contents of the address part of a register) and CDR (contents of the decrement part of a register), that extracted the associated fields. It was natural to use the two fields to store the two pointers of a list node so that a memory word could neatly store a node. Using these conventions, the CAR and CDR instructions of the 704 provided efficient list selectors. The names carried over into the primitives of all dialects of LISP. 18. What is tail recursion? Why is it important to define functions that use recursion to specify repetition to be tail recursive? => A function is tail recursive if its recursive call is the last operation in the function. This means that the return value of the recursive call is the return value of the nonrecursive call to the function. It is important to specify repetition to be tail recursive because it is more efficient(increase the efficiency). 19. Why were imperative features added to most dialects of LISP? => LISP began as a pure functional language but soon acquired some important imperative features to increased its execution efficiency. 26. What is type inferencing, as used in ML? => Type inference refers to the automatic deduction of the type of an expression in a programming language. If some, but not all, type annotations are already present it is referred to as type reconstruction. 29. What is a curried function? => Curried functions a function which a new functions can be constructed from them by partial evaluation. 30. What does partial evaluation mean? => Partial evaluation means that the function is evaluated with actual parameters for one or more of the leftmost formal parameters. 32. What is the use of the evaluation environment table? => A table called the evaluation environment stores the names of all implicitly and explicitly declared identifiers in a program, along with their types. This is like a run-time symbol table. 33. Explain the process of currying. => The process of currying replaces a function with more than one parameter with a function with one parameter that returns a function that takes the other parameters of the initial function. PROBLEM SET 8. How is the functional operator pipeline ( |> ) used in F#? => The pipeline operator is a binary operator that sends the value of its left operand, which is an expression, to the last parameter of the function call, which is the right operand. It is used to chain together function calls while flowing the data being processed to each call. 9. What does the following Scheme function do? (define ( y s lis) (cond (( null? lis) ‘ () ) ((equal? s (car lis)) lis) (else (y s (cdr lis))) )) => y returns the given list with leading elements removed up to but not including the first occurrence of the first given parameter. 10.What does the following Scheme function do? (define ( x lis) (cond (( null? lis) 0 ) (( not(list? (car lis))) (cond ((eq? (car lis) #f) (x (cdr lis))) (else (+1 (x (cdr lis)))))) (else (+ (x (car lis)) (x (cdr lis)))) => x returns the number of non-#f atoms in the given list

Chapter 14 - Exception Handling and Event Handling

Review Question 1. Define exception, exception handler, raising an exception, disabling an exception, continuation, finalization, and built-in exception. An exception is an unusual event that is detectable by either hardware or software and that may require special processing. The special processing that may be required when an exception is detected is called exception handling. The processing is done by a code unit or segment called an exception handler. Program execution can simply terminate. We term this the question of control continuation after handler execution, or simply continuation. The ability to specify such a computation is called finalization. Built-in exceptions have a built-in meaning, it is generally inadvisable to use these to signal program-specific error conditions. Instead we introduce a new exception using an exception declaration, and signal it using a raise expression when a run-time violation occurs. 6 . What is exception propagation in Ada? Exception propagation allows an exception raised in one program unit to be handled in some other unit in its dynamic or static ancestry. This allows a single exception handler to be used for any number of different program units. This reuse can result in significant savings in development cost, program size, and program complexity. 7. Where are unhandled exceptions propagated in Ada if raised in a subprogram? A block? A package body? A task? When an exception is raised in a block, in either its declarations or executable statements, and the block has no handler for it, the exception is propagated to the next larger enclosing static scope, which is the code that “called” it. The point to which the exception is propagated is just after the end of the block in which it occurred, which is its “return” point. When an exception is raised in a package body and the package body has no handler for the exception, the exception is propagated to the declaration section of the unit containing the package declaration. If the package happens to be a library unit (which is separately compiled), the program is terminated. If an exception occurs at the outermost level in a task body (not in a nested block) and the task contains a handler for the exception, that handler is executed and the task is marked as being completed. If the task does not have a handler for the exception, the task is simply marked as being completed; the exception is not propagated. The control mechanism of a task is too complex to lend itself to a reasonable and simple answer to the question of where its unhandled exceptions should be propagated. 9. What is the scope of exception handlers in Ada? Exception handlers can be included in blocks or in the bodies of subprograms, packages, or tasks. 10. What are the four exceptions defined in the Standard package of Ada? The four exception defined in the standard package of Ada are Constraint_Error, Program_Error, Storage_Error, Tasking_Error 11. What is the use of suppress pragma in Ada? An Ada pragma is a directive to the compiler. Certain run-time checks that are parts of the built-in exceptions can be disabled in Ada programs by use of the Suppress pragma, the simple form of which is pragma Suppress(check_name). Where check_name is the name of a particular exception check. The Suppress pragma can appear only in declaration sections. When it appears, the specified check may be suspended in the associated block or program unit of which the declaration section is a part. Explicit raises are not affected by Suppress. Although it is not required, most Ada compilers implement the Suppress pragma. 13. Describe three problems with Ada’s exception handling. There are several problems with Ada’s exception handling. One problem is the propagation model, which allows exceptions to be propagated to an outer scope in which the exception is not visible. Also, it is not always possible to determine the origin of propagated exceptions. Another problem is the inadequacy of exception handling for tasks. For example, a task that raises an exception but does not handle it simply dies. Finally, when support for object-oriented programming was added in Ada 95, its exception handling was not extended to deal with the new constructs. For example, when several objects of a class are created and used in a block and one of them propagates an exception, it is impossible to determine which one raised the exception. 14. What is the name of all C++ exception handlers? Each catch function is an exception handler. A catch function can have only a single formal parameter, which is similar to a formal parameter in a function definition in C++, including the possibility of it being an ellipsis (. . .). A handler with an ellipsis formal parameter is the catch-all handler; it is enacted for any raised exception if no appropriate handler was found. The formal parameter also can be a naked type specifier, such as float, as in a function prototype. In such a case, the only purpose of the formal parameter is to make the handler uniquely identifiable. When information about the exception is to be passed to the handler, the formal parameter includes a variable name that is used for that purpose. Because the class of the parameter can be any user-defined class, the parameter can include as many data members as are necessary. 15. Which standard libraries define and throw the exception out_of_range in C++? The exception out_of_range in C++ thrown by library container classes 16. Which standard libraries define and throw the exception overflow_error in C++? The exception overflow_error in C++ thrown by math library functions 19. State the similarity between the exception handling mechanism in C++ and Ada In some ways, the C++ exception-handling mechanism is similar to that of Ada. For example, un-handled exceptions in functions are propagated to the function’s caller. 20. State the differences between the exception handling mechanism in C++ and Ada There are no predefined hardware-detectable exceptions that can be handled by the user, and exceptions are not named. Exceptions are connected to handlers through a parameter type in which the formal parameter may be omitted. The type of the formal parameter of a handler determines the condition under which it is called but may have nothing whatsoever to do with the nature of the raised exception. 30. In which version were assertions added to Java? Assertions were added to Java in version 1.4. 31. What is the use of the assert statement? The assert statement is used for defensive programming. A program may be written with many assert statements, which ensure that the program’s computation is on track to produce correct results. 32. What is event-driven programming? Event-driven programming is a programming where parts of the program are executed at completely unpredictable times, often triggered by user interactions with the executing program. 33. What is the purpose of a Java JFrame? The JFrame class defines the data and methods that are needed for frames. So, a class that uses a frame can be a subclass of JFrame. A JFrame has several layers, called panes. 34. What are the different forms of assert statement? There are two possible forms of the assert statement: assert condition; assert condition : expression; Problem Set 1 . What mechanism did early programming languages provide to detect or attempt to deal with errors? Early programming languages were designed and implemented in such a way that the user program could neither detect nor attempt to deal with such errors. In these languages, the occurrence of such an error simply causes the program to be terminated and control to be transferred to the operating system. The typical operating system reaction to a run-time error is to display a diagnostic message, which may be meaningful and therefore useful, or highly cryptic. After displaying the message, the program is terminated. 2. Describe the approach for the detection of subscript range errors used in C and Java. Java compilers usually generate code to check the correctness of every subscript expression (they do not generate such code when it can be determined at compile time that a subscript expression cannot have an out-of-range value, for example, if the subscript is a literal). In C, subscript ranges are not checked because the cost of such checking was (and still is) not believed to be worth the benefit of detecting such errors. In some compilers for some languages, subscript range checking can be selected (if not turned on by default) or turned off (if it is on by default) as desired in the program or in the command that executes the compiler. 5. From a textbook on FORTRAN, determine how exception handling is done in FORTRAN programs. For example, a Fortran “Read” statement can intercept inputerrors and end-of-file conditions, both of which are detected by the input device hardware. In both cases, the Read statement can specify the label of some statement in the user program that deals with the condition. In the case of the end-of-file, it is clear that the condition is not always considered an error. In most cases, it is nothing more than a signal that one kind of processing is completed and another kind must begin. In spite of the obvious difference between end-of-file and events that are always errors, such as a failed input process, Fortran handles both situations with the same mechanism. 6. In languages without exception-handling facilities, it is common to have most subprograms include an “error” parameter, which can be set to some value representing “OK” or some other value representing “error in procedure”. What advantage does a linguistic exception-handling facility like that of Ada have over this method? There are several advantages of a linguistic mechanism for handling exceptions, such as that found in Ada, over simply using a flag error parameter in all subprograms. One advantage is that the code to test the flag after every call is eliminated. Such testing makes programs longer and harder to read. Another advantage is that exceptions can be propagated farther than one level of control in a uniform and implicit way. Finally, there is the advantage that all programs use a uniform method for dealing with unusual circumstances, leading to enhanced readability. 7. In a language without exception handling facilities, we could send an error-handling procedure as a parameter to each procedure that can detect errors that must be handled. What disadvantages are there to this method? There are several disadvantages of sending error handling subprograms to other subprograms. One is that it may be necessary to send several error handlers to some subprograms, greatly complicating both the writing and execution of calls. Another is that there is no method of propagating exceptions, meaning that they must all be handled locally. This complicates exception handling, because it requires more attention to handling in more places.

Chapter 13 - Concurrency

REVIEW QUESTION 1. What are the three possible levels of concurrency in programs? => – Instruction level (executing two or more machine instructions simultaneously) – Statement level (executing two or more high-level language statements simultaneously) – Unit level (executing two or more subprogram units simultaneously) 7. What is the difference between physical and logical concurrency? => Physical concurrency is several program units from the same program that literally execute simultaneously. Logical concurrency is multiple processors providing actual concurrency, when in fact the actual execution of programs is taking place in interleaved fashion on a single processor. 8. What is the work of a scheduler? => Scheduler manages the sharing of processors among the tasks. 12. What is a heavyweight task? What is a lightweight task? => Heavyweight task executes in its own address space. Lightweight task all run in the same address space. 16. What is a task descriptor? => Task descriptor is a data structure that stores all of the relevant information about the execution state of a task. 18. What is the purpose of a task-ready queue? => The purpose of a task-ready queue is to be storage of tasks that are ready to run. 21. What is a binary semaphore? What is a counting semaphore? => Binary semaphore is a semaphore that requires only a binary-valued counter, like the one used to provide competition synchronization. A counting semaphore is a synchronization object that can have an arbitrarily large number of states. 30. What is purpose of an Ada terminate clause? => The purpose of an Ada terminate clause is to mark that the task is finished with its job but is not yet terminated. 34. What does the Java sleep method do? => Sleep method blocks the the thread. 35. What does the Java yield method do? => Yield method surrenders the processor voluntarily as a request from the running thread. 36. What does the Java join method do? => Java forces a method to delay its execution until the run method of another thread has completed its execution. 37. What does the Java interrupt method do? => Interrupt becomes one way to communicate to a thread that it should stop. 55. What is Concurrent ML? => Concurrent ML is an extension to ML that includes a fform of threads and a form of synchronous message passing to support concurrency. 56. What is the use of the spawn primitive of CML? => The use of Spawn primitive of CML is to create a thread. 57. What is the use of subprograms BeginInvoke and EndInvoke in F#? => The use of subprograms BeginInvoke and Endinvoke in F# is to call threads asynchronously. 58. What is the use of the DISTRIBUTE and ALIGN specification of HPC? => The use of DISTRIBUTE and ALIGN specification of HPC is to provide information to the compiler on machines that do not share memory, that is, each processor has its own memory. PROBLEM SET 1. Explain clearly why a race condition can create problems for a system. => Because two or more tasks are racing to use the shared resource and the behavior of the program depends on which task arrives first (and wins the race). The importance of competition synchronization should now be clear. 2. What are the different ways to handle deadlock? => – Ignoring deadlock – Detection – Prevention – Avoidance 3. Busy waiting is a method whereby a task waits for a given event by continuously checking for that event to occur. What is the main problem with this approach? => Busy-waiting or spinning is a technique in which a process repeatedly checks to see if a condition is true, such as whether keyboard input or a lock is available. Spinning can also be used to generate an arbitrary time delay, a technique that was necessary on systems that lacked a method of waiting a specific length of time. Processor speeds vary greatly from computer to computer, especially as some processors are designed to dynamically adjust speed based on external factors, such as the load on the operating system. Busy waiting may loop forever and it may cause a computer freezing.

Chapter 12 - Support for Object-Oriented Programming

Review Questions 4. What is message protocol? Message protocol is the entire collection of methods of an object. 5. What is an overriding method? Overriding method is method that overrides the inherited method. 7. What is dynamic dispatch? Dynamic dispatch is the third characteristic (after abstract data types and inheritance) of object-oriented programming language which is a kind of polymorhphism provided by the dynamic binding of messages to method definitions. 12. From where are Smalltalk objects allocated? Smalltalk objects are allocated from the heap and are referenced through reference variables, which are implicitly dereferenced. 15. What kind of inheritance, single or multiple, does Smalltalk support? Smalltalk supports single inheritance; it does not allow multiple inheritance. 19. How are C++ heap-allocated objects deallocated? C++ heap-allocated objects are deallocated using destructor. 29. Does Objective-C support multiple inheritance? No Objective-C doesn’t support it. (It supports only single inheritance). 33. What is the purpose of an Objective-C category? The purpose of an Objective-C category is to add certain functionalities to different classes and also to provide some of the benefits of multiple inheritance, without the naming collisions that could occur if modules did not require module names on their functions. 38. What is boxing? Boxing is primitive values in Java 5.0+ which is implicitly coerced when they are put in object context. This coercion converts the primitive value to an object of the wrapper class of the primitive value’s type. 39. How are Java objects deallocated? By implicitly calling a finalizemethod when the garbage collector is about to reclaim the storage occupied by the object. Problem Set 3. Compare the inheritance of C++ and Java. - In Java, all classes inherit from the Object class directly or indirectly. Therefore, there is always a single inheritance tree of classes in Java, and Object class is root of the tree. In Java, if we create a class that doesn’t inherit from any class then it automatically inherits from Object Class. In C++, there is forest of classes; when we create a class that doesn’t inherit from anything, we create a new tree in forest. - In Java, members of the grandparent class are not directly accessible. - The meaning of protected member access specifier is somewhat different in Java. In Java, protected members of a class “A” are accessible in other class “B” of same package, even if B doesn’t inherit from A (they both have to be in the same package) - Java uses extends keyword for inheritence. Unlike C++, Java doesn’t provide an inheritance specifier like public, protected or private. Therefore, we cannot change the protection level of members of base class in Java, if some data member is public or protected in base class then it remains public or protected in derived class. Like C++, private members of base class are not accessible in derived class. Unlike C++, in Java, we don’t have to remember those rules of inheritance which are combination of base class access specifier and inheritance specifier. - In Java, methods are virtual by default. In C++, we explicitly use virtual keyword. - Java uses a separate keyword interface for interfaces, and abstract keyword for abstract classes and abstract functions. - Unlike C++, Java doesn’t support multiple inheritance. A class cannot inherit from more than one class. A class can implement multiple interfaces though. – In C++, default constructor of parent class is automatically called, but if we want to call parametrized constructor of a parent class, we must use Initalizer list. Like C++, default constructor of the parent class is automatically called in Java, but if we want to call parametrized constructor then we must use super to call the parent constructor 5. Compare abstract class and interface in Java. - First and major difference between abstract class and interface is that, abstract class is a class while interface is a interface, means by extending abstract class you can not extend another class becauseJava does not support multiple inheritance but you can implement multiple inheritance in Java. - Second difference between interface and abstract class in Java is that you can not create non abstract method in interface, every method in interface is by default abstract, but you can create non abstract method in abstract class. Even a class which doesn’t contain any abstract method can be abstract by using abstract keyword. - Third difference between abstract class and interface in Java is that abstract class are slightly faster than interface because interface involves a search before calling any overridden method in Java. This is not a significant difference in most of cases but if you are writing a time critical application than you may not want to leave any stone unturned. - Fourth difference between abstract class vs interface in Java is that, interface are better suited for Type declaration and abstract class is more suited for code reuse and evolution perspective. - Another notable difference between interface and abstract class is that when you add a new method in existing interface it breaks all its implementation and you need to provide an implementation in all clients which is not good. By using abstract class you can provide default implementation in super class. 7. What is one programming situation where multiple inheritance has a significant disadvantage over interfaces? A situation when there are two classes derived from a common parent and those two derived class has one child. 9. Give an example of inheritance in C++, where a subclass overrides the superclass methods. class plan{ public: void fly(){ cout << “fly” << endl; } }; class jet:public class plan{ public: void fly() { cout << “Fly! Rocket jet activated!” << endl; } } 10. Explain one advantage of inheritance. Inheritance offers a solution to both the modification problem posed by abstract data type reuse and the program organization problem. If a new abstract data type can inherit the data and functionality of some existing type, and is also allowed to modify some of those entities and add new entities, reuse and is also allowed to modify some of those entities and add new entities, reuse is greatly facilitated without requiring change to the reused abstract data type. Programmers can begin with an existing abstract data type and design a modified descendant of it to fit a new problem requirement. Furthermore, inheritance provides a framework for the definition of hierarchies of related classes that can reflect the descendant relationship in the problem space. 12. Compare inheritance and nested classes in C++. Which of these supports an is-a relationship? Inheritance is where one class (child class) inherits the members of another class (parent class).Nested class is a class declared entirely within the body of another class or interface. Inheritance does. 17. What are the different options for object destruction in Java? There is no explicit deallocation operator. A finalize method is implicitly called when the garbage collector is about to reclaim the storage occupied by the object.

Chapter 11 - Abstract Data Types and Encapsulation Constructs

Review question 2. Define abstract data type. Answer : data type that satisfies the following conditions: -The representation of objects of the type is hidden from the program units that use the type, so the only direct operations possible on those objects are those provided in the type’s definition. -The declarations of the type and the protocols of the operations on objects of the type, which provide the type’s interface, are contained in a single syntactic unit. The type’s interface does not depend on the representation of the objects or the implementation of the operations. Also, other program units are allowed to create variables of the defined type. 8. What is the difference between private and limited private types in Ada? Answer : Limited private is more restricted form and objects of a type that is declared limited private have no built-in operations. 10. What is the use of the Ada with clause? Answer : With clause makes the names defined in external packages visible; in this case Ada. Text_IO, which provides functions for input of text. 11. What is the use of the Ada use clause? Answer : The with clause makes the names defined in external packages Visible. 12. What is the fundamental difference between a C++ class and an Ada package? Answer : Ada packages are more generalize encapsulations that can define any number of types. 15. What is the purpose of a C++ destructor? Answer : The purpose of a C++ desctructor is as a debugging aid, in which case they simply display or print the values of some or all of the object’s data members before those members are deallocated. 16. What are the legal return types of a desctructor? Answer : Destructor has no return types and doesn’t use return statements. 20. What is the use of limited private types? Answer : An alternative to private types is a more restricted form: limited private types. Nonpointer limited private types are described in the private section of a package specification, as are nonpointer private types. The only syntactic difference is that limited private types are declared to be limited private in the visible part of the package specification. The semantic difference is that objects of a type that is declared limited private have no built-in operations. Such a type is useful when the usual predefined operations of assignment and comparison are not meaningful or useful. For example, assignment and comparison are rarely used for stacks. 21. What are initializers in Objective-C? Answer : The initializers in Objective-C are constructors. 22. What is the use of @private and @public directives? Answer : The use is to specify the access levels of the instance variables in a class definition. 27. Where are all Java methods defined? Answer : All Java methods are defined in a class. 30. What is a friend function? What is a friend class? Answer : a “friend” of a given class is allowed access to public, private, or protected data in that class. Normally, function that is defined outside of a class cannot access such information. Class that can access the private and protected members of the class in which it is declared as a friend. On declaration of friend class all member function of the friend class become friends of the class in which the friend class was declared. Problem set 4. What are the advantages of the nonpointer concept in Java? Any task that would require arrays, structures, and pointers in C can be more easily and reliably performed by declaring objects and arrays of objects. Instead of complex pointer manipulation on array pointers, you access arrays by their arithmetic indices. The Java run-time system checks all array indexing to ensure indices are within the bounds of the array. You no longer have dangling pointers and trashing of memory because of incorrect pointers, because there are no pointers in Java. 10. Which two conditions make data type “abstract”? The representation of objects of the type is hidden from the program units that use the type, so the only direct operations possible on those objects are those provided in the type’s definition. The declarations of the type and the protocols of the operations on objects of the type, which provide the type’s interface, are contained in a single syntactic unit. The type’s interface does not depend on the representation of the objects or the implementation of the operations. Also, other program units are allowed to create variables of the defined type. 12. How are classes in Ruby made dynamic? Classes in Ruby are dynamic in the sense that members can be added at any time. This is done by simply including additional class definitions that specify the new members. Moreover, even predefined classes of the language, such as String, can be extended. 13. Compare and contrast the data abstraction of Java and C++. Java support for abstract data types is similar to that of C++. There are, however, a few important differences. All objects are allocated from the heap and accessed through reference variables. Methods in Java must be defined completely in a class. A method body must appear with its corresponding method header. Therefore, a Java abstract data type is both declared and defined in a single syntactic unit. A Java compiler can inline any method that is not overridden. Definitions are hidden from clients by declaring them to be private. Rather than having private and public clauses in its class definitions, in Java access modifiers can be attached to method and variable definitions. If an instance variable or method does not have an access modifier, it has package access. 19. Compare Java’s packages with Ruby’s modules. In Ruby, the require statement is used to import a package or a module. For example, the extensions package/module is imported as follows. require ‘extensions’ External files may be included in a Ruby application by using load or require. For example, to include the external file catalog.rb, add the following require statement. require “catalog.rb” The difference between load and require is that load includes the specified Ruby file every time the method is executed and require includes the Ruby file only once. In Java, the import statement is used to load a package. For example, a Java package java.sql is loaded as follows. import java.sql.*;

Chapter 10 - Implementing Subprograms

REVIEW QUESTIONS 1. What is the definition used in this chapter for “simple subprograms”? Subprogram cannot be nested and all local variables are static. 4.What is the task of a linker? The task of a linker is to find the files that contain the translated subprograms referenced in that and load them into memory. 8. What kind of machines often use registers to pass parameters? RISC. 11. What is an EP, and what is its purpose? EP is a point or first address of the activation record instance of the main program. It is required to control the execution of a subprogram. 14. What are two potentialproblems with the static-chain method? - It is difficult for a programmer working on a time-critical program to estimate the costs of nonlocal references, because the cost of each reference depends on the depth of nesting between the reference and the scope of declaration. - Subsequent code modifications may change nesting depths, thereby changing the timing of some references, both in the changed code and possibly in code far from the changes. 17. Describe the shallow-access method of implementing dynamic scoping. Shallow access is an alternative implementation method, not an alternative semantics. The semantics of deep access and shallow access are identical. In the shallow-access method, variables declared in subprograms are not stored in the activation records of those subprograms. PROBLEM SET 6. Although local variables in Java methods are dynamically allocated at the beginning of each activation, under what circumstances could the value of a local variable in a particular activation retain the value of previous activation? If the variable is declared as static. Static modifier is a modifier that makes a variable history – sensitive. 8. Pascal allows gotos with nonlocal targets. How could such statements be handled if static chains were used for nonlocal variable access? Finding the correct activation record instance of a nonlocal variable using static links is relatively straightforward. When a reference is made to nonlocal variable, the activation record instance containing the variable can be found by searching the static chain until a static ancestor activation record instance is found that contains the variable. 9. The static-chain method could be expanded slightly by using two static links in each activation record instance where the second points to the static grandparent activation record instance. How would this approach affect the time required for subprogram linkage and nonlocal references? Including two static links would reduce the access time to nonlocals that are defined in scopes two steps away to be equal to that for nonlocals that are one step away. Overall, because most nonlocal references are relatively close, this could significantly increase the execution efficiency of many programs. 11. If a compiler uses the static chain approach to implementing blocks, which of the entries in the activation records for subprograms are needed in the activation records for blocks? There are two options for implementing blocks as parameterless subprograms: One way is to use the same activation record as a subprogram that has no parameters. This is the most simple way, because accesses to block variables will be exactly like accesses to local variables. Of course, the space for the static and dynamic links and the return address will be wasted. The alternative is to leave out the static and dynamic links and the return address, which saves space but makes accesses to block variables different from subprogram locals.

Chapter 9 - Subprograms

Review Questions 1. What are the three general characteristic of subprograms? 2. What does it mean for a subprogram to be active? 5. What languages allow a variable number of parameters ? 7. What is a parameter profile? What is a subprogram protocol? 8. What are formal parameters? What are actual parameters? 9. What are the advantages and disadvantages of the keyword parameter? 10 . What are the differences between a function and a procedure ? 22. What are the design issues for functions? 23. In what ways are coroutines different from conventional subprogram? 24. What is an overloaded subprogram? 26. What is multicast delegate? 32. What exactly is a delegate? 34. What is a closure? Answers: 1. Each subprogram has a single entry point, 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, and control always returns to the caller when the subprogram execution terminates. 2. A subprogram is said to be active if, after having been called, it has begun execution but has not yet completed that execution. 5. C,C++,Perl JavaScript, and Lua. 7. Parameter profile is the number, order, and types of its formal parameters. Subprogram protocol is its parameter profile plus, if it is a function, its return type. In languages in which subprograms have types, those types are defined by the subprogram’s protocol. 8. The parameters in the subprogram header are called formal 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. 9. The advantage of keyword parameters is that they can appear in any order in the actual parameter list. The disadvantage to keyword parameters is that the user of the subprogram must know the names of formal parameters. 10. Functions return values while procedure does not, and procedure defines new statements, while function define new user-defined operators. 22. Are side effects allowed and what types of values can be returned. 23. Conventional subprograms are subordinate to their callers. When a routine calls a subprogram, execution suspends at that point in the program and resumes after the subprogram has run to completion. As a result, conventional subprogram invocation is atomic, much like a built-in statement in the programming language. 24. Overloaded subprogram is a subprogram that has the same name as another subprogram in the same referencing environment. 26. Multicast delegate is all of the methods stored in a delegate instance are called in the order in which they were placed in the instance. 32. A delegate is the power and flexibility of method pointers in C# increased by making them objects. 34. Closure is a nested subprogram ant its referencing environment, which together allow the subprogram to be called from anywhere in a program. Problem Set 3. Argue in support of the template functions of C++. How is it different from the template functions in other languages? 6 . Compare and contrast PHP’s parameter passing with that of C#. 8 . Argue against the Java design of not providing operator overloading 12 . Research Jensen’s Device, which was a widely known use of pass-by-name parameters, and write a short description of what it is and how it can be used. 15. How is the problem of passing multidimensional arrays handles by Ada? Answers: 3. C++ templated classes are instantiated to become typed classes at compile time. For example, an instance of the templated Stack class, as well as an instance of the typed class, can be created with the following declaration: Stack myIntStack; However, if an instance of the templated Stack class has already been created for the int type, the typed class need not be created. 6. PHP’s parameter passing is similar to that of C#, except that either the actual parameter or the formal parameter can specify pass-by-reference. Passby- reference is specified by preceding one or both of the parameters with an ampersand. 8. Arithmetic operators are often used for more than one purpose. For example, + usually is used to specify integer addition and floating-point addition. Some languages—Java, for example—also use it for string catenation. This multiple use of an operator is called operator overloading and is generally thought to be acceptable, as long as neither readability nor reliability suffers. 12. Implementing a pass-by-name parameter requires a subprogram to be passed to the called subprogram to evaluate the address or value of the formal parameter. The referencing environment of the passed subprogram must also be passed. This subprogram/referencing environment is a closure. Pass-by-name parameters are both complex to implement and inefficient. They also add significant complexity to the program, thereby lowering its readability and reliability. Because pass-by-name is not part of any widely used language, it is not discussed further here. However, it is used at compile time by the macros in assembly languages and for the generic parameters of the generic subprograms in C++, Java 5.0, and C# 2005. 15. Ada compilers are able to determine the defined size of the dimensions of all arrays that are used as parameters at the time subprograms are compiled. In Ada, unconstrained array types can be formal parameters. An unconstrained array type is one in which the index ranges are not given in the array type definition. Definitions of variables of unconstrained array types must include index ranges. The code in a subprogram that is passed an unconstrained array can obtain the index range information of the actual parameter associated with such parameters.

Chapter 8 - Statement-Level Control Structures

Review Questions 2. What did Bohm and Jocopini prove about flowcharts? It was proven that all algorithms that can be expressed by flowcharts can be coded in a programming languages with only two control statements: one for choosing between two control flow paths and one for logically controlled iterations. 3. What is the definition of block? In Ruby, block is a sequence of code, delimited by either breves or the do and and reserved words. 4. What is/are the design issue(s) for all selection and iteration control statements? There is only one design issue that is relevant to all of the selection and iteration control statements: Should the control structure have multiple entries? 7. Under what circumstances must an F# selector have an else clause? An F# selector have an “else” clause if the “if” expression does return a value. 9. What are the design issues for multiple-selection statements? What is the form and type of the expression that controls the selection? How are the selectable segments specified? How are the case values specified? How should unrepresented selector expression values be handled, if at all? Is execution flow through the structure restricted to include just a single selectable segment? 14. What are the design issues for all iterative control statements? How is the iteration controlled? Where should the control mechanism appear in the loop statement? 15. What are the design issues for counter-controlled loop statements? What are the type and scope of the loop variable? Should it be legal for the loop variable or loop parameters to be changed in the loop, and if so, does the change affect loop control? Should the loop parameters be evaluated only once, or once for every iteration? 21. What are the design issues for logically controlled loop statements? Should the control be pretest or post-test? Should the logically controlled loop be a special form of a counting loop or a separate statement? 23. What are the design issues for user-located loop control mechanisms? Should the conditional mechanism be an integral part of the exit? Should only one loop body be exited, or can enclosing loops also be exited? Problem Set 1. What design issues should be considered for two-way selection statements? The design issues for two-way selectors can be summarized as follows: • What is the form and type of the expression that controls the selection? • How are the then and else clauses specified? • How should the meaning of nested selectors be specified? 4. What are the limitations of implementing a multiple selector from two-way selectors and gotos? A multiple selector can be built from two-way selectors and gotos, but the resulting structures are cumbersome, unreliable, and difficult to write and read. 5. What are the arguments pro and con, for Java’s approach to specify compound statements in control statements? • Compound statements are required in control statements when the body of the if or else clause requires multiple statements. • Java uses braces to form compound statements, which serve as the bodies of if and else clauses. 9. Boolean expressions are necessary in the control statements in Java, as opposed to also allowing arithmetic expressions, as in C++. Give a conditional statement that is correct in C++ but not in Java. int i=10; if( i ) { // block of statements } This block of statement is valid in C++ but not in Java. 11. Explain the advantages and disadvantages of the Java switch statement, compared to C++’s switch statement. The Java variable in the argument of a switch statement can be of type integral ( byte, short etc.), char and String( JDK 1.7 onwards), whereas in C++ the argument can be int or char.

Monday, April 8, 2013

Chapter 7 - Expressions and Assignment Statements

Review Question
1.The operator precedence rules for expression evaluation partially define the order in which the operators of different precedence levels are evaluated. The operator precedence rules for expressions are based on the hierarchy of operator priorities, as seen by the language designer. 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. An operator can have either left or right associativity, meaning that when there are two adjacent operators with the same precedence, the left operator is evaluated first or the right operator is evaluated first, respectively.
2.It is a conditional operator that provides a shorter syntax for the if..then..else statement. The first operand is a boolean expression; if the expression is true then the value of the second operand is returned otherwise the value of the third operand is returned.
3.The operators ++ for increment, and –– for decrement, can be used either in expressions or to form stand-alone single-operator assignment statements. They can appear either as prefix operators, meaning that they precede the operands, or as postfix operators, meaning that they follow the operands.
5.Operator with illegal expression.
8.A side effect of a function, naturally called a functional side effect, occurs when the function changes either one of its parameters or a global variable. (A global variable is declared outside the function but is accessible in the function.)
9. coercion is an automatic conversion. For example, if an int variable and a float variable are added in Java, the value of the int variable is coerced to float and a floating-point add is done.
11. In object-oriented programming, operator overloading—less commonly known as operator ad-hoc polymorphism—is a specific case of polymorphism, where different operators have different implementations depending on their arguments. Operator overloading is generally defined by the language, the programmer, or both.
12. A narrowing conversion converts a value to a type that cannot store even approximations of all of the values of the original type. A widening conversion converts a value to a type that can include at least approximations of all of the values of the original type.
28.Cast is explicit type conversions. To specify a cast, the desired type is placed in parentheses just before the expression to be converted.
Problem Set
1. Suppose Type1 is a subrange of Integer. It may be useful for the difference between Type1 and Integer to be ignored by the compiler in an expression.
2.If operands in an expression contains both INTEGER and REAL constants or variables, this is a mixed mode arithmetic expression. In mixed mode arithmetic expressions, INTEGER operands are always converted to REAL before carrying out any computations. As a result, the result of a mixed mode expression is of REAL type. can coercion be used in some cases of type mismatch? Fortran, C, C++, and Perl use coercion rules for mixed-mode assignment that are similar to those they use for mixed-mode expressions; that is, many of the possible type mixes are legal, with coercion freely applied.7 Ada does not allow mixed-mode assignment. In a clear departure from C++, Java and C# allow mixed-mode assignment only if the required coercion is widening.8 So, an int value can be assigned to a float variable, but not vice versa. Disallowing half of the possible mixedmode assignments is a simple but effective way to increase the reliability of Java and C#, relative to C and C++.
3. The elimination of overloaded operators in my favorite language would not be beneficial. Operator overloading is claimed to be useful because it allows the developer to program using notation "closer to the target domain"[1] and allows user-defined types a similar level of syntactic support as types built into the language. It can easily be emulated using function calls; for an example, consider the integers a, b, c:
7. An expression such as a + fun(b)
8. Consider the integer expression A + B + C. Suppose the values of A, B, and C are 20,000, 25,000, and -20,000, respectively. Further suppose that the machine has a maximum integer value of 32,767. If the first addition is computed first, it will result in overflow. If the second addition is done first, thewhole expression can be correctly computed.
10. (a) ( a * ( b – ( 1 + c )1 )2 )3
(b) ( a * ( ( b – 1 )2 / ( c mod d )1 )3 )4
(c) ( ( a – b )5 / ( c & ( d * ( e / ( a – 3 )1 )2 )3 )4 )6
(d) ( – ( a or ( c = ( d and e )1 )2 )3 )4
(e) ( a > ( xor ( c or ( d <= 17 )1 )2 )3 )4 (f) ( – ( a + b )1 )2

Chapter 6 - Data Types

Review Questions
1.A descriptor is the collection of the attributes of a variable.
2.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, and their representation in memory is mildly wasteful.
3.- The two most important design issues that are specific to character string types are the following:
• Should strings be simply a special kind of character array or a primitive type?
• Should strings have static or dynamic length?
5.A subrange type is a contiguous subsequence of an ordinal type. An ordinal type is one in which the range of possible values can be easily associated with the set of positive integers. An enumeration type is one in which all of the possible values, which are named constants, are provided, or enumerated, in the definition. The third option is to allow strings to have varying length with no maximum, as in JavaScript, Perl, and the standard C++ library. These are called dynamic length strings. This option requires the overhead of dynamic storage allocation and deallocation but provides maximum flexibility.
6.Enumeration types can provide advantages in both readability and reliability. Readability is enhanced very directly: Named values are easily recognized, whereas coded values are not.
7.C# includes both the references of Java and the pointers of C++. However, the use of pointers is strongly discouraged. In fact, any subprogram that uses pointers must include the unsafe modifier. Note that although objects pointed to by references are implicitly deallocated, that is not true for objects pointed to by pointers. Pointers were included in C# primarily to allow C# programs to interoperate with C and C++ code.
15.An aggregate constant is a nonscalar constant which value never change or are not changed during execution of the program.
18.Arrays are part of most programming languages. The relationship between a reference to an array element and the address of that element is given in an access function, which is an implementation of a mapping.
20.An associative array is an unordered collection of data elements that are indexed by an equal number of values called keys. In the case of non-associative arrays, the indices never need to be stored (because of their regularity). In an associative array, however, the user-defined keys must be stored in the structure. So each element of an associative array is in fact a pair of entities, a key and a value. We use Perl’s design of associative arrays to illustrate this data structure.an associative array?
21.evel numbers in COBOL indicate by their relative values the hierarchical structure of the record. Any line that is followed by a line with a higher-level number is itself a record.
43.A compatible type is one that either is legal for the operator or is allowed under language rules to be implicitly converted by compiler-generated code (or the interpreter) to a legal type.
44. A type error is the application of an operator to an operand of an inappropriate type. For example, in the original version of C, if an int value was passed to a function that expected a float value, a type error would occur (because compilers for that language did not check the types of parameters).
45.A programming language is strongly typed if type errors are always detected. This requires that the types of all operands can be determined, either at compile time or at run time. The importance of strong typing lies in its ability to detect all misuses of variables that result in type errors. A strongly typed language also allows the detection, at run time, of uses of the incorrect type values in variables that can store values of more than one type.
50.Name type equivalence means that two variables have equivalent types if they are defined either in the same declaration or in declarations that use the same type name.
Problem Set
2.The CPU doesn't care whether a byte holds -1 or 15 when it moves it from one place to another. There's no such thing as a "signed move" (to a location of the same size - there is a signed move for larger or smaller destinations). The CPU only cares about the representation when it does arithmetic on the byte. The CPU knows whether to do signed or unsigned arithmetic according to the op-code that you (or the compiler on your behalf) chose.
3.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.
5.When implicit dereferencing of pointers occurs only in certain contexts, it makes the language slightly less orthogonal. The context of the reference to the pointer determines its meaning. This detracts from the readability of the language and makes it slightly more difficult to learn.
6.The Boolean or logical data type is a data type, having two values (usually denoted true and false), intended to represent the truth values of logic and Boolean algebra. It is named after George Boole, who first defined an algebraic system of logic in the mid-19th century. The Boolean data type is the primary result of conditional statements, which allow different actions and change control flow depending on whether a programmer-specified boolean condition evaluates to true or false. C++ has a separate Boolean data type ('bool'), but with automatic conversions from scalar and pointer values that are very similar to those of C. This approach was adopted also by many later languages, especially by some scripting ones such as AWK. One problem with this approach is that the tests if(t==TRUE){...} and if(t) are not equivalent. Python has a related situation, where the Boolean type, bool is a subtype of the integer type, int, and Booleans False and True act as 0 and 1, respectively, in arithmetic contexts.
8.In their quest for increased safety over C++, the designers of Java removed C++-style pointers altogether. Unlike C++ reference variables, Java reference variables can be assigned to refer to different class instances; they are not constants. All Java class instances are referenced by reference variables. That is, in fact, the only use of reference variables in Java.
16.C and C++ are not strongly typed languages because both include union types, which are not type checked. ML is strongly typed, even though the types of some function parameters may not be known at compile time. F# is strongly typed. Java and C#, although they are based on C++, are strongly typed in the same sense as Ada. Types can be explicitly cast, which could result in a type error. However, there are no implicit ways type errors can go undetected.

Chapter 5 - Names, Bindings, and Scopes

Review Question
1. - The following are the primary design issues for names:
• Are names case sensitive?
• Are the special words of the language reserved words or keywords?
These issues are discussed in the following two subsections, which also include examples of several design choices.
2. - In that sense, case sensitivity violates the design principle that language constructs that look similar should have similar meanings. But in languages whose variable names are case-sensitive, although Rose and rose look similar, there is no connection between them.
3.- A reserved word is a special word of a programming language that cannot be used as a name. As a language design choice, reserved words are better than keywords because the ability to redefine keywords can be confusing.
6.-value is the address of a variable. r-value is a variable’s value that’s required when the name of the variable appears in the right side of an assignment statement.
7. A binding is an association between an attribute and an entity, such as etween a variable and its type or value, or between an operation and a symbol. The time at which a binding takes place is called binding time. Binding and binding times are prominent concepts in the semantics of programming languages.
16. The referencing environment of a statement is the collection of all variables that are visible in the statement.
Problem Set
1.The valid identifier names are _Student, Student, and Student123. We cannot use ‘int’ as name because it’s a reserved keyword and we cannot use the 123Student because C doesn’t allow identifier format with a digit at the first letter.
2.n lvalue is a way of describing the term on the left hand side of an assignment. It is usually an address or variable.
if (0 = foo)
{
}
4.A data type, such as int in C, is bound to a range of values at language implementation time. At compile time, a variable in a Java program is bound to a particular data type. A variable may be bound to a storage cell when the program is loaded into memory. That same binding does not happen until run time in some cases, as with variables declared in Java methods. A call to a library subprogram is bound to the subprogram code at link time.

Tuesday, March 26, 2013

Chapter 3 - Describing Syntax and Semantics

Name : Agata Sri Sartika Servina
NIM : 1601218804
Class: 02PCT
Special thanks to : Mr. Tri Djoko Wahjono, Ir., M.Sc.
Review Question
1. The syntax of a programming language is the form of its expressions, statements, and program units. Semantics is the meaning of those expressions, statements, and program units.
2. A language generator is a device that can be used to generate the sentences of a language. We can think of the generator as having a button that produces a sentence of the language every time it is pushed . In this term, people prefer certain forms of generators over recognizers because they can more easily read and understand them. By contrast, the syntax- checking portion of a compiler is not as useful a language description for a programmer because it can be used only in trial and error mode.
4. Sentence form is a program consists of the special word begin, followed by a list of statements separated by semicolons, followed by the special word end. Sentential form is each of the strings in the derivation, including
6. Synthesized attributes are used to pass semantic information up a parse tree, inherited attributes are used to pass semantic information down and across a tree.
9. The wp function is helpful to treat the process of producing a weakest precondition as a function. It is called a predicate transformer because it takes a predicate, or assertion, as a parameter and returns another predicate.
10. Total correctness is the axiomatic description of the loop when the loop termination is shown Partial correctness is the other condition can be met but termination is not guaranteed.
23. Axiomatic semantics, named because it is based on mathematical logic.
28.A weakest precondition is the least restrictive precondition that will guarantee the postcondition. It is often called a predicate transformer because it takes a predicate, or assertion as a parameter and returns another predicate.
Problem Set
1. Syntax Error: error due to missing colon, semicolon, parenthesis, etc. Syntax is the way in which we construct sentences by following principles and rules.
Examples:
1. int x = “three”;
In C++, this will not compile because it does not follow the syntax of the language and does not make any sense to the compiler.
5. →id = = id | id != id
7. S A {bA}
Aa [b]A
b |
a | ab
8. A fully attributed parse tree is a condition when all the attributed values in parse tree have been computed.
16. =
→ A | B | C
(+ | -)
| ()
|
17. S → A | A B
B → b A | b A B
A → a A | a b A
18. if all the attributed values in a parse tree have been computed. a parse tree of an attributed grammar is the parse tree based on its underlying BNF grammar, with a possibly empty set of attribute values attached to each node.
24. a. a= 2*b+1
b=a-3 {b<0}
b. a= 3*(2*b+a)
b= 2*a-1 {b>5}
2*a-1>5
2*a>6
(a). -> a-3<0
a<3
a=2*b+1 {a<3}
2*b+1<3
2*b<2
b<1
(b). -> a= 3*(2*b+a) {a>3}
3*(2*b+a)>3
6*b+3*a>3
2*b+a>1
b>(1-a)/2

Monday, March 18, 2013

Chapter 2 - Evolution of the Major Programming Languages

Name : Agata Sri Sartika Servina
NIM : 1601218804
Class: 02PCT
Special thanks to : Mr. Tri Djoko Wahjono, Ir., M.Sc.
Review Question
1. Designed in 1943 and Published in 1972
3. Program Calculus
7. John Backus
8. John Mauchly. Because, it clearly simplified the programming process, but at the expense of execution time.
9. IBM,Fortran 0.
10. Independent compilation of subroutines
11. Logical loop control statements
12. Fortran IV
13. Fortran 77
14. Because, Linguists were concerned with natural language processing
15. Records, arrays, complex numbers and character strings
17. Scheme
18. GAMM and ACM
19. C has adequate control statements and data-sructuring facilities to allow its use in many application areas. It also has a rich set of operators that provide a high degree of expressiveness.
21. COBOL.
22. Common Business Language (CBL).
23. 1959
28. Designed to replace FORTRAN & COBOL languages.
33. ALGOL-W
46. Objective-C 2.0.
47. Ken Thompson.
49. Sun Microsystems.
54. You will find it used in a web browser.
64. .NET
Problem Set
1. The logical loop control statements, and an “if” with an optional “else” caluse.
2. Short Code clearly simplified the programming process, but at the expense of execution time. Short Code interpretation was approximately 50 times slower than machine code (hand calculator).
6. The most common syntax error in C i think is forget to end a statement with semicolon (;)
8. Because, Speedcoding fills up a lot of space on the disk so it’s ineffective
9. The choice of the letters for this convention was based on the fact that at that time scientists and engineers used letters as variables subscripts, usually i, j, and k, and then Fortran’s designers threw in the three additional letters.
13. Because, C is flexible and well suited for various applications and also a compiler for C was part of the widely used UNIX operating system in 1980s.
15. Yes, Fortran, C++, COBOL, ALGOL.
16. depend to the programmer they want to use a simple or a complex, but many will choose simple because it is more readable and more easy to spot a mistake.
25. Java servlet is a Java programming language class used to extend the capabilities of a server. Although servlets can respond to any types of requests, they are commonly used to extend the applications hosted by web servers, so they can be thought of as Java Apllets that run on servers instead of in web browsers

Monday, March 4, 2013

Chapter 1 - Preliminaries

Name : Agata Sri Sartika Servina
NIM : 1601218804
Class: 02PCT
Special thanks to : Mr. Tri Djoko Wahjono, Ir., M.Sc. ()
Review Question
3.The first language of scientific applications was FORTRAN
4.COBOL
13.A program is said to be reliable if it performs to its specifications under all conditions.
15.Aliasing is a distortion caused in analog-to-digital conversion by a too low rate of data sampling. Aliasing can occur either because the anti-alias filter in the A-D converter (or in a sample-rate converter) isn’t very good, or because the system has been overloaded.
16.Exception handling is a mechanism in which a programming construct is used to consistently trap, intercept and handle the error occurred during application execution. The Common Language Runtime (CLR) of .NET Framework is designed to use an exception handling model based on exception objects and protected blocks of code.
23.Smalltalk
26.a compiler.
Problem Set
2.Refer from Wikipedia.com the first programmer was Ada Lovelace. She is today appreciated as the “first programmer” since she was writing programs that is, encoding an algorithm in a form to be processed by a machine for a machine that Babbage had not yet built.
8.> pros:
a. easier way to maintain error
b. make the collaborative working on project easier
c. save development time
d. easier testing
> Cons:
a. function and subroutines require knowledge of programming language so it is a difficult thing for a programmer how doesn’t have enough skill
b. different programming language usually has a different way to create a function and subroutines so in this case it makes the programmer have to learn many different way to make function and subroutines in different programming language.
13.One of the first programming language i learned is C. C uses a compiler