COSC 365 Midterm

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

D. Garbage detection and reclamation

A basic form of garbage collection has two main phases: _______________________. A. Allocation and initialization B. Interpretation and compilation C. Garbage reclamation and release D. Garbage detection and reclamation

Optimizations or Transformation Passes

A compiler may apply many _______ in order to produce faster and/or smaller code

D. instance

An object is a(n) ______ of a class. A. member B. method C. struct D. instance

Metadata

Automatic memory management strategies typically store extra information in an object's _______.

Environment

BASH stores variables in a key/value map called the ________. Every process has one of these.

Parse

Bytecode is typically consumed by the VM in binary form so that it doesn't have to ______ the bytecode.

B. Static

C's type system is: A. Strong B. Static C. Dynamic D. Procedural

C. Operands

A binary operator has two: A. Types B. Instructions C. Operands D. Grammars

an execution environment that allows code for one platform (guest) to run on another (host).

In general terms, what is a virtual machine?

C. Semantic Analysis

In which stage of the compiler would an error for this code be produced? int x; x = "abc"; A. Lexing B. Parsing C. Semantic Analysis D. Code Generation

• Imperative • Procedural • Object-Oriented • Shell/Scripting • Functional • Parallel • Multi-Paradigm

What are the Primary Language Paradigms

An object is an instance of a class.

What is the difference between a class and an object?

A. Inheritance

__________ allows classes to be defined as derivations of other classes. A. Inheritance B. Encapsulation C. Abstraction D. The Common Language Runtime (CLR)

Declarative programming is a style of building programs that express the logic of computation without talking about its control flow. The functional programming paradigm has its roots in mathematics and it is language-independent. The key principle of this paradigm is the execution of a series of mathematical functions. -> programming by applying and composing functions JavaScript : developed by Brendan Eich Haskell : developed by Lennart Augustsson, Dave Barton Scala : developed by Martin Odersky Erlang : developed by Joe Armstrong, Robert Virding Lisp : developed by John Mccarthy ML : developed by Robin Milner Clojure : developed by Rich Hickey

associate some of the first high-level languages with their primary paradigms: Declarative(Functional):

This paradigm emphasizes procedure in terms of the underlying machine model. There is no difference between the procedural and imperative approaches. -> programming by calling procedures or subroutines, which execute a series of instructions and return to the caller Languages that are Procedural are also imperative The Elders (Late 50s-60s) COBOL: COMMON BUSINESS-ORIENTED LANGUAGE • Created by the Department of Defense in 1959 • Primarily designed for portable business applications • Borrowed heavily from Grace Hopper's FLOW-MATIC • Had an English-like syntax • Little academic involvement or uptake FORTRAN FORMULA TRANSLATION SYSTEM • Created by IBM for scientific and engineering applications in 1957 • Had advanced programming features: › Subroutines › Pass-by-reference › Complex-number data type • First optimizing compiler • First example of a widely cross-platform language • Modern compilers: › GNU: gfortran › LLVM: flang ALGOL ALGORITHMIC LANGUAGE • Developed by a joint committee of American and European computer scientists in 1958 • Wanted to create a "universal language" for math and computing • ALGOL had extreme influence on the syntax of modern programming languages • Introduced the idea of "code blocks" and lexical scope: definitions local to a block and its sub-blocks • Portability problem: no I/O facilities defined by the specification LISP LIST PROCESSING • Took a lot of inspiration from Alonzo Church's Lambda Calculus • Used for early AI Lisp was the first high-level functional programming language (Still procedural but added functional programming)term-3 functional: programming by applying and composing functions • Lisp syntax is a textual representation of list data • Entire syntax comprised of "Symbolic Expressions" , or "S-Expressions": (item1, item2, item3, ...) • Each item in an S-expression can either be another list or an atom (number, string, symbol) Lisp contributions to programming languages: • Functional programming • Recursion • Higher-order functions • Dynamic type systems • Fully-featured macros • Garbage Collection • Incremental compilation • Self-hosted compiler • Read-Eval-Print-Loop (REPL) C : developed by Dennis Ritchie and Ken Thompson C++ : developed by Bjarne Stroustrup Java : developed by James Gosling at Sun Microsystems ColdFusion : developed by J J Allaire Pascal : developed by Niklaus Wirth

associate some of the first high-level languages with their primary paradigms: Procedural:

Encapsulation

Classes may define "private" members in order to take advantage of what object-oriented principle?

C. Data and behavior

Classes tie together which two parts of a program? A. Data and performance. B. Functions and methods. C. Data and behavior. D. Behavior and performance.

. Turing-Complete: capable of simulating any Turing machine . Implication: given enough time and memory, can solve any (finite) computational problem . Most practical programming languages are Turing-complete. . If a language is not Turing complete, there are computational problems it cannot solve. Programming Languages That are not Turing-complete: SQL92. Regular expressions (Regex) HTML. XML. JSON. YAML.

How does Turing-completeness relate to programming languages?

Syntax is the set of rules that dictate whether or not a program is structurally valid, they are typically expressed as a grammar. Describes how to create strings fitting the rules of a formal language Uses rules of replacement to describe language structure

How does a grammar relate to syntax?

Functional

LISP was the first high-level programming language of which paradigm?

A. Functional

Many recently developed, general-purpose programming languages are adopting features from which paradigm? A. Functional B. Imperative C. Procedural D. Quantum

D. Reusable

Parametric polymorphism helps you create ______ code. A. Fast B. Correct C. Object-oriented D. Reusable

Copy

Pass-by-value is typically slower than pass-by-reference because it must create a(n) ______ of the object

Interpret

Some VMs choose to _______________ the code before compiling it to reduce startup time. The CLR does not do this.

BASIC

This family of primarily imperative programming languages came with most early personal computers (including the Apple II and Commodore 64) and inspired a whole generation of programmers:

. the understood meaning of a program . give meaning and enforce correctness

What are semantics?

• Bytecode is almost always consumed by the runtime in binary form > This Eliminates the time needed to parse the code at startup • Textual forms exist primarily for debugging • Fixed width: each instruction takes up the same number of bytes > Simplifies many parts of decoding, but can be limiting • Variable width: instructions may take consume a different number of bytes depending on the opcode > Allows code to be more dense and use large immediates

What are some of the design decisions we learned about with respect to bytecode? (ex. binary vs. text, fixed vs variable width, etc.)

• Enable execution of a high-level language that compiles to a bytecode • Provide an environment that facilitates all features defined by the language • Often referred to as a language "runtime environment" or simply "runtime" • Most implement "garbage collectors" • Manage execution of threads (scheduling) • Exception Handling • Library Management (linking) • Foreign-Function Interface (FFI): a system to map functions from one system or interface to another (Interoperability) • OS Interfaces

What are some of the things that a high-level language VM provides?

› Terminals: symbols from the alphabet { a, b, ε} › Non-terminals: Names that refer to parts of the grammar { S } (≈Variables) › Productions: rules that define replacement of non-terminals with terminals { S → aSb | ε } › Start Symbol: Which production to use as a starting point { S }

What are the basic components of a Grammar?

Alphabet: finite set of symbols String: finite concatenation of symbols in alphabet › May be the "empty string" (denoted ε) Formal Language: specific set of strings over an alphabet › May be infinite

What are the basic components of a Language?

- Compute the size of data elements - Relate data to operations - Enforce consistency and correctness - Reduces possibilities for bugs in programs due to type errors

What are the benefits of having a type system in a language?

With manual memory management, memory acquisition, safety, and release are the responsibility of the programmer. There is little-to-no language involvement and any safety features are explicitly programmed. Downsides: • Easy to create memory bugs › Segmentation violations, memory leaks, use-after-free • Easy to create security vulnerabilities › Buffer overflow, race conditions • Takes a trained programmer to manage memory correctly and efficiently With Automatic memory management, Memory usage is automatically controlled through some kind of runtime system. › Typically a language runtime VM • When the application needs memory, it gets it from the runtime • Memory accesses are indirected through the runtime • Memory that is no longer needed is automatically identified • These objects are considered "garbage" • The runtime manages the reclamation of memory identified as garbage • The programmer is simply responsible for asking for objects and using them Advantages: • Entire classes of memory bugs disappear › Can't have a double-free if you never free! • The runtime can perform additional safety checks when objects are accessed • Makes code simpler and easier to write correctly . reduce or remove the potential for security vulnerabilities Could introduce their own security issues: Garbage collected languages may not give you the ability to properly dispose of sensitive memory

What are the differences and tradeoffs between manual and automatic memory-management?

Identify objects as garbage(dead) --> garbage detection, and removes dead objects --> reclamation, giving memory back to the Os or reused

What are the primary jobs of a garbage collector?

Tokenizer/Lexer: › Splits the input into a stream of tokens that can be processed by the parser Parser: › Creates an abstract syntax tree out of the input tokens › Structured, syntactic representation of a program Semantic Analysis: › Performs passes over AST that check for semantic errors, such as type checking IR Generator: › Translates parse tree into an intermediate representation (IR) IR Analyzer: › Analysis is performed on the IR to obtain useful information about control flow, loops, procedure calls, etc. Optimizer: › Runs transformation passes over the IR in order to make it faster and/or smaller using information from prior analyses (if needed) Machine-Code Generator: › Translates the final IR into executable machine code.

What are the stages of traditional ahead-of-time compilation?

Encapsulation: the bundling of data with the mechanisms or methods that operate on the data. (Public, Private) Inheritance: a mechanism for using the interface and implementation of one or more classes as the basis for another class. (subclass) Polymorphism: allows the use of a single interface with different underlying forms, such as data types or classes. (Generics, Subtyping)

What are the three pillars of object-oriented Programming?

Interpretation: • The VM has code that corresponds to each opcode • Each bytecode instruction gets interpreted by the matching VM code • Very slow compared to native code execution JIT Compilation: • Typically compiles entire functions/methods/etc. at a time • Only compiles the parts of the program that run • Very Complex • Optimizations cause it to take much more time to compile • Can add delays and increase startup cost

What are the tradeoffs between interpretation and JIT compilation?

Parametric polymorphism: not specifying concrete types and instead using abstract symbols that can substitute for any type. (Generic Functions and data-types.) Subtyping: a form of polymorphism in which many classes are related by a "superclass

What are the two types of polymorphism discussed in class?

A linker aggregates object files and makes sure that all external symbols are actually defined somewhere. A linker combines the sections from all objects into a single set of sections

What does a linker do?

A program that exposes the facilities of an operating system to the user › Run programs › Interact with a filesystem › Configure system settings

What does a shell do?

. a class that is designed to be specifically used as a base class. . common, implemented functionality among all the implementations of the component

What does it mean for a class to be abstract?

Implementing file and output redirection using <, >, |. File redirection(< >): The input and/or output of any program run in the shell can be redirected to/from a file. Pipes(|): Connect the inputs and outputs of system programs to "compose" greater functionality.

What functionality of UNIX, made easy in BASH, allows you to compose programs?

Regular expressions make up a small, regular language for matching patterns in strings.

What is REGEX?

. rules defining the set of structurally valid programs . enforce program structure

What is Syntax?

A language is dynamically typed if the type of a variable is checked during run-time. In this type of language, there is no need to specify the data type of each variable while writing code.

What is a Dynamically typed Language

A programming language is statically typed if the type of a variable is known at compile time. once a variable is assigned a type, it can't be assigned to some other variable of a different type. Java, C, C++, C#, Kotlin, Fortran, Pascal, Rust, Go, COBOL

What is a Statically typed language

Transform the IR into a faster and/or smaller version that is semantically equivalent. Examples: • Dead Code Elimination: find code that can be proven unreachable and remove it from the program • Constant Evaluation: replace instructions that generate known constants with their result • Function Inlining: inline the body of a function call at the call site

What is a compiler optimization?

a classification of programming languages based on features and "big ideas" • languages can belong to many paradigms (multi-paradigm) • some paradigms determine what a language can't do

What is a programming language paradigm?

A well-defined language with syntax and semantics used to solve computational problems

What is a programming language?

a set of semantic rules that assign a "type" to different parts of a program and checks for consistency between typed elements

What is a type system?

. A function or method used to override the behavior of the function in an inherited class . An abstract class contains at least one pure virtual method. . To access it, it must be inherited from another class

What is a virtual method and how does it relate to polymorphism?

The environment in UNIX is a key/value structure that exists for every running process. BASH variables are implemented in the environment.

What is the UNIX "environment" (i.e. environment variables) and how does it relates to BASH?

The program is written as a collection of classes and objects which are meant for data manipulation. Advantages: . Data security . Inheritance . Code reusability . Flexible and abstraction is also present

What is the basic premise and advantage(s) of object-oriented programming?

JIT compilation occurs at runtime and AOT compilation will occur at build time. JIT compilation is usually done on smaller parts of the program (one function at a time). Also, JIT compiled code may not be as heavily optimized

What is the difference between AOT compilation and JIT compilation?

General-purpose language (GPL): a widely applicable language that can be used to create a wide variety of computer programs › C, Java, C++, Python ... Domain-specific language (DSL): a language used for a specific purpose or domain application • Query: SQL, jq • Markup: HTML, Markdown, slide • Modeling: UML • Hardware description: VHDL • GPU Shaders: GLSL, HLSL

What is the difference between a domain-specific language and a general-purpose language?

Dynamically-typed languages perform type-checking at runtime. › Typically implies that the types may change as the program runs Statically typed languages: type errors are caught by the compiler/type checker before the program runs

What is the difference between a static and dynamic type system?

Generally, a strongly typed language has stricter typing rules at compile time, which implies that errors and exceptions are more likely to happen during compilation. A weakly typed language has looser typing rules and may perform implicit type conversion and/or operations between types at runtime.

What is the difference between a strong and weak type system?

Pass by value means you are making a copy in memory of the actual parameter's value that is passed in. Pass by reference means you are passing the parameter's memory location(variable) into the function

What is the difference between pass-by-value and pass-by-reference?

Programming with sequential instructions or commands that manipulate state

What is the main programming style that makes a language "imperative"?

A group of objects may reference each other, creating cyclical references. This creates a situation where basic reference counting technique will never be able to free this group of objects!

What is the major problem with reference counting as a memory-management strategy?

Programming by calling procedures or subroutines, which execute a series of instructions and return to the caller

What is the primary feature that makes a language "procedural"?

C. cycle

When two objects hold references to each other, there is a reference _______. A. pointer B. object C. cycle D. counter

Typedef

Which C keyword allows you to define named types?

Algol

Which language inspired the syntax for most common C-like languages?

D. Increased program performance

Which of the following is NOT an advantage of automatic memory management? A. Reduction of security vulnerabilities B. Code is easier to write C. Reduced burden on the programmer D. Increased program performance

B. Encapsulation

Which of the following is NOT an example of polymorphism? A. Generics B. Encapsulation C. Templates D. Subtyping

B. A compiler

Which of the following is NOT required for a programming language? A. Syntax B. A compiler C. Semantics D. Abstraction

D. Regular Expressions

Which of the following languages is NOT Turing-complete? A. LISP B. BASH C. The x86 MOV instruction D. Regular Expressions

B. Just-in-time

__________ compilers convert bytecode into machine code on the fly. A. Ahead-of-time B. Just-in-time C. Load-time D. Reactive

Imperative programming is based on Von Neumann's architecture. It works by changing the program state through assignment statements. It performs step-by-step tasks by changing state. The paradigm consists of several statements and after execution, all the result is stored. --> Programming with sequential instructions or commands that manipulate state C (1972) • Added a set of types, including char for byte-oriented machines and float • Included typed pointer arithmetic • Aggregate types, or, struct • Used for most UNIX applications thereafter • UNIX itself was rewritten in C almost immediately FORTRAN FORMULA TRANSLATION SYSTEM • Created by IBM for scientific and engineering applications in 1957 • Had advanced programming features: › Subroutines BASIC Beginners' All-purpose Symbolic Instruction Code • a family of programming languages • Originated in early 60s at Dartmouth University • Sought to enable non-experts to program computers • FORTRAN was difficult to learn, but inspired BASIC's design • Primarily imperative, but later dialects adopted procedural and object-oriented features

associate some of the first high-level languages with their primary paradigms: Imperative:

The program is written as a collection of classes and objects which are meant for communication. The smallest and basic entity is an object and all kind of computation is performed on the objects only. More emphasis is on data rather than procedure. It can handle almost all kinds of real-life problems. Languages that are Object-oriented are also Imperative Simula (1962): . Took syntax almost entirely from ALGOL, but extended it . First object-oriented language . Objects, classes . Inheritance . Dynamic dispatch (virtual methods) . Garbage Collection SmallTalk (1972) Used more "pure" form of object-oriented programming: › Everything is an object (integers, conditionals, etc.) › Objects communicate via "messages" › Objects inherit code from their "class", but can change on the fly (JIT compilation Objective-C (1984) • Took SmallTalk's message-style objects and added them to C C++ (1985) • Started as "C with classes" • Inspiration from Simula • First compiler/transpiler called "cfront" produced C code Java (1995) • Object-oriented language built on top of a bytecode virtual machine • Goal: WORA (write once; run anywhere) • C-like syntax • One of the most widely-used programming languages of all time C# (2000) • Microsoft language similar to Java • Runs on the .NET platform: › JIT compilation runtime management › Runtime features like libraries, garbage collection › Language interoperability

associate some of the first high-level languages with their primary paradigms: Object Oriented:


संबंधित स्टडी सेट्स

practice assessments and terms I am unsure about

View Set

DONE Chapters 2 and 3 multiple choice

View Set

Marketing 351 Ole Miss Cousley Chapters 12 (Shuffle to avoid repeating of the same topics)

View Set

Animal Behavior and Ecology Exam 4

View Set

hypothalamus-anterior pituitary axis hormones

View Set

Accounting: Chapter 7: Account/Notes Receivable

View Set