• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/49

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

49 Cards in this Set

  • Front
  • Back

Ruby

dynamically-typed(duck typing), object-oriented, interpreted, scripting language.

Duck Typing

the type of an object is determined at run-time. Advantage: Simplifies code. Disadvantage: Loss of compile-time error checking.

Method Calls (Ruby)

When a message is sent to an object
The methods of the object’s class are searched for a method with the same name.
If found, the body is executed.
Otherwise the methods of the superclass are searched.
This continues until the top of the class hierarchy, BasicObject is reached.
If the method is not found, then the method_missing message is sent to the original object.
Note: method_missing is defined in BasicObject, but may be overridden.


Objects and Classes(Ruby)

Everything in Ruby is an object.
An object contains the instance variables and a reference to its class.
Classes are objects.
Every object has a class.
Classes have a reference to their superclass
Classes have references to the methods.


Adding Methods to Objects(Ruby)

In Ruby methods may be added to objects. These methods are called “singleton methods”

The singleton class

When a singleton method is defined, Ruby creates an anonymous class object and sets this as the classes new Class object and sets the original Class object as the superclass.


Modules

Modules are also objects.
They contain methods and instance variables.
Multiple Modules may be included in a Class.
How does Ruby resolve conflicts in Modules?
A Module may be included in different Classes.


Including a Module(Ruby)

When the statement:
include ‹module name›
is executed
Ruby defines an anonymous Class object that references the Module object
Ruby inserts this class as the superclass.


Resolving Conflicts in Modules

The chain of superclasses is a single-linked-list that acts as a Last-In-First-Out queue.
Thus the most recently included Module’s methods are searched first.


Blocks

A block is a sequence of Ruby statements and expressions, optionally preceded with an argument list.
Blocks are delimited by either { ... } or do ... end
A block may only appear after a method invocation.
The invoked method calls the block using the yield statement.
The value of the block is the value of the last statement or the value passed to the next statement executed in the block.


Procs

A block is not an object.
The class Proc encapsulates a block.
A Proc object can be
stored in a variable
passed as an argument
returned from a function
You invoke the associated block by calling the call method of the Proc object.








The & operator

If the last parameter of a method begins with a & character
then the block will be converted to a Proc and bound to this parameter.
If the & character is placed before a variable that is a Proc object
the Proc object is converted back to a block


lambdas

A lambda is a Proc that is created using the lambda method or the -> operator.
The resulting Proc object differs from what is returned from Proc.new:
When called, the number of arguments to the lambda must match the expected number of arguments.
The return statement from a lambda returns to the caller.
The return statement from a proc returns out of the caller.


Groovy

Groovy is a optionally dynamically-typed, object-oriented, compiled, scripting language.

Scripting language

There is an implicit main method


There are built-in methods to access the operating system

Meta-Object Protocol (MOP)

A Meta-Object Protocol (MOP) are the capabilities in a dynamic language (such as Groovy) that enable metaprogramming.

The Groovy MOP consists of:

reflection
metaclasses
categories
expandos


MetaClass

The MetaClass maintains the metadata about a Groovy class
methods, fields, and properties
Unlike the java.lang.Class class, the MetaClass can be modified at run-time.
MetaClass objects are assigned to the Java classes by the Groovy run-time.


Mixins

A mixin is a class that is mixed in (merged) with another class.
Similar to Ruby’s module
A mixin is added to a class as part of its declaration using the @Mixin annotition
A mixin is added to a class during run-time using the mixin method.


Scala

statically-typed, object-oriented, compiled, scripting language.

Statically-typed

Type of an object is determined at compile time
Variables are restricted to hold values of a particular type.
Variables may be declared without specifying their type, but the type is determined by the type of the expression that initialized them.


Traits

Traits are classes that are meant to be added as a mixin to some other class.
Traits do not have constructor parameters.
Traits can define methods or declare abstract methods.
A class/trait that mixes in an abstract method must implement it.
A trait that only defines abstract methods is the same as a Java interface.
Java interfaces may be used as traits.


Singleton Objects

A singleton object with the same name as a class is known as a companion module.
Companion modules act like ruby’s class objects in that they contain the equivalent of static methods and instance variables.


Option Type

The Option type is used to express values that might not be present.
The case subclass Some wraps a value.
The case subclass None indicates that there is no value.
Is safer than using null return as in Java.
Note Java 8 has introduced an Option type.


Actors

An actor is an object that processes incoming messages and executes actions associated with it.
Messages are immutable.
Actors are assigned threads from a thread pool.


The Actor trait

The Actor trait has one abstract method:
receive
that takes a partial function.
The partial function contains case clauses for each message.
The messages are case classes.


Software Transactional Memory

Turns the Java heap into a transactional dataset similar to database transactions.
ACID
Atomiticy
All modifications are “all or nothing”
Consistency
Transactions go from one consistent state to another
Isolation
No other transaction sees partial changes
Durability
Not provided by STM (local memory is not durible)


State

In imperative programming data is directly accessed and mutated.
Problem if two concurrent threads try to access/mutate at the same time.
Especially a problem if multiple values need to be changed consistently.
In STM isolates the values from what are called “identities”
The values are immutable
The identities can change, but do so as atomic operations.


PROLOG

Prolog (PROgramming in LOGic*) is a declarative language.
Instead of telling the computer the steps to solve the problem, the programmer defines the problem and the computer finds the solution.


Prolog Syntax

facts Statements that are true
rules Rules of inference
queries Problems to be solved


Clojure

a compiled dynamic functional programming language based on LISP.
Programs are compiled into JVM byte code, or CLR or Javascript.
The basic execution unit is the function.
The basic data structure is the list, but
Clojure adds the vector, map, and set to the available data structures.
Functions are represented by lists, thus the program and data are the same structure.


Data Types (Clojure)

Numbers
Symbols
Keywords
Strings
Characters


Data Structures (Clojure)

Lists, Maps, Vectors, Sets

Higher-Order Functions

A higher-order function is a function that takes a function as one of its arguments and/or returns a function as its result.


Macros

When a function is called each of its arguments are evaluated.
When a macro is called, the arguments are not evaluated.
The result of a macro call is Clojure code which will be compiled.
Macros allow you to add a feature to the language.


Lazy Sequences

The lazy-seq macro generates lazy sequences. (lazy-seq & body) The body is evaluated only when the seq function is called.

Context Free Grammar

A context free grammar consists of non-terminals and terminals
Non-terminals are of the form ‹string›
Terminals are of the form string
A non-terminal is defined by a string of terminals and non-terminals
More than one definition for a non-terminal is allowed.
Originally developed to study natural languages, these have proven very useful to define computer languages.


Type 3 — Regular

The left-hand side of a production rule is a single non-terminal
The right-hand side of a production rule is either
a single terminal
a single non-terminal followed by a terminal or a terminal followed by a single non-terminal (but not both in the same grammar)
Type 3 grammars can be expressed as regular expressions.
Type 3 languages can be recognized by a deterministic finite-state automata.


Type 2 — Context Free

The left-hand side of a production rule is a single non-terminal
The right-hand side of a production rule is a sequence of terminals and non-terminals
Type 2 languages can be recognized by a non-deterministic push-down automata (NP hard)
A sub-set of the type 2 languages can be recognized by a deterministic push-down automata (e.g. a computer program that is either recursive or uses a stack).


Type 1 — Context Sensitive

The left-hand side of a production rule consists of a sequence of terminals and non-terminals that contains at least one non-terminal.
The right hand side is the same sequence with the designated non-terminal replaced by a non-empty sequence of terminals and non-terminals.
e.g. The production rule established a context in which the designated non-terminal can be expanded, and the context is preserved.
Recognizing a type 1 language is NP hard. However, since programming languages are context sensitive, compilers are possible, but the context sensitivity is not part of the language’s formal definition.


Type 0 — Phrase Structured

There is no restriction on either the left-hand side or the right-hand side of a production rule.
Type 0 languages are equivalent to computer programs.
A general-purpose recognizer is not possible

Parsing

Parsing is the process of determining how a sentence was generated by the grammar.
The result is a Parse Tree


Abstract Syntax Tree

An Abstract Syntax Tree is a tree that shows the structure of the sentence.
The internal nodes are terminals or artificial nodes
The leaves are terminals.


Lexer

The Lexer parses the input into tokens.
It recognizes that sub-set of the grammar that is regular (e.g. type-3).
The lexer generator lex (flex) which is part of Unix (GNU) is regular-expression based.
A Lexer can also be generated using recursive-decent parsing.


Recursive Decent Parsing

Given a context-free grammar one can construct a parser as follows:
Define a method for each non-terminal
This method tries to match each of its choices to the input by looking at the next input token.
If there is a match, the method captures the input token and returns true.
If no match, the method leaves the input stream alone and returns false.


Bottom-Up Parsing

Bottom-up parsing constructs the parse tree starting at the leaves and working to the root.
The parser scans the input string from left to right.
Given a current input subsequence, the parser attempts to match this to the rhs of a production.
If it can match, it replaces the input symbols with the corresponding lhs.


LR Parsing Algorithm

The LR parsing algorithm is state/input driven.
There is a stack of symbols that represents the input that has been processed.
There is a stack of states that represents the history.
Given a current state/input either:
shift
The current input symbol is pushed onto the symbol stack
The next state is pushed onto the state stack
reduce
The top n symbols of the symbol stack are matched to the rhs of a production.
The top n states are popped off of the state stack
The lhs of the production is pushed onto the symbol stack
The next state is a function of the lhs and the current state


What is a Domain Specific Language

A computer programming language of limited expressiveness focused on a particular domain.*
Programming Language: Instructs computers to do something
Limited expressiveness: Generally not Turing Complete
Domain focus: Uses vocabulary specific to the problem domain.


Types of DSLs

Internal:
Build upon an existing general-purpose programming language:
Example: jMock expectations
External:
Processed by an interpreter or compiler:
Examples: Makefiles, SQL, Ant build.xml*