#Java
Collections
It was designed to meet three goals:
• its implementations for the fundamental collections had to be highly efficient.
• it had to allow different types of collections to work in a similar manner and with interoperability.
• it had to adapt a new collection easily.
Lists
Sets
Maps
Collections
It was designed to meet three goals:
• its implementations for the fundamental collections had to be highly efficient.
• it had to allow different types of collections to work in a similar manner and with interoperability.
• it had to adapt a new collection easily.
AbstractCollection: Implements most of the Collection interface.Lists
AbstractList: Extends AbstractCollection and implements most of the List interface.AbstractSequentialList: Extends AbstractList for use by a collection that uses sequential rather than random access of its elements.LinkedList: Implements a linked list by extending AbstractSequentialList.ArrayList: Implements a dynamic array by extending AbstractList.Sets
AbstractSet: Extends AbstractCollection and implements most of the Set interface.HashSet: Extends AbstractSet for use with a hash table.LinkedHashSet: Extends HashSet to allow insertion-order iterations.TreeSet: Implements a set stored in a tree. Extends AbstractSet.Maps
AbstractMap: Implements most of the Map interface.HashMap: Extends AbstractMap to use a hash table.TreeMap: Extends AbstractMap to use a tree.WeakHashMap: Extends AbstractMap to use a hash table with weak keys.LinkedHashMap: Extends HashMap to allow insertion-order iterations.IdentityHashMap: Extends AbstractMap and uses reference equality when comparing documents.#Java
LinkedList
1.
Inserts the specified element at the specified position index in this list. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index > size()).
2.
Appends the specified element to the end of this list.
3.
Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator. Throws NullPointerException if the specified collection is null.
4.
Inserts all of the elements in the specified collection into this list, starting at the specified position. Throws NullPointerException if the specified collection is null.
5.
Inserts the given element at the beginning of this list.
6.
Appends the given element to the end of this list.
7.
Removes all of the elements from this list.
8.
Returns a shallow copy of this LinkedList.
9.
Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).
10.
Returns the element at the specified position in this list. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()).
11.
Returns the first element in this list. Throws NoSuchElementException if this list is empty.
12.
Returns the last element in this list. Throws NoSuchElementException if this list is empty.
13.
Returns the index in this list of the first occurrence of the specified element, or -1 if the list does not contain this element.
14.
Returns the index in this list of the last occurrence of the specified element, or -1 if the list does not contain this element.
15.
Returns a list-iterator of the elements in this list (in proper sequence), starting at the specified position in the list. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()).
16.
Removes the element at the specified position in this list. Throws NoSuchElementException if this list is empty.
17.
Removes the first occurrence of the specified element in this list. Throws NoSuchElementException if this list is empty. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()).
18.
Removes and returns the first element from this list. Throws NoSuchElementException if this list is empty.
19.
Removes and returns the last element from this list. Throws NoSuchElementException if this list is empty.
20.
Replaces the element at the specified position in this list with the specified element. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()).
21.
Returns the number of elements in this list.
22.
Returns an array containing all of the elements in this list in the correct order. Throws NullPointerException if the specified array is null.
23.
Returns an array containing all of the elements in this list in the correct order; the runtime type of the returned array is that of the specified array.
LinkedList
1.
void add(int index, Object element)Inserts the specified element at the specified position index in this list. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index > size()).
2.
boolean add(Object o)Appends the specified element to the end of this list.
3.
boolean addAll(Collection c)Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator. Throws NullPointerException if the specified collection is null.
4.
boolean addAll(int index, Collection c)Inserts all of the elements in the specified collection into this list, starting at the specified position. Throws NullPointerException if the specified collection is null.
5.
void addFirst(Object o)Inserts the given element at the beginning of this list.
6.
void addLast(Object o)Appends the given element to the end of this list.
7.
void clear()Removes all of the elements from this list.
8.
Object clone()Returns a shallow copy of this LinkedList.
9.
boolean contains(Object o)Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).
10.
Object get(int index)Returns the element at the specified position in this list. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()).
11.
Object getFirst()Returns the first element in this list. Throws NoSuchElementException if this list is empty.
12.
Object getLast()Returns the last element in this list. Throws NoSuchElementException if this list is empty.
13.
int indexOf(Object o)Returns the index in this list of the first occurrence of the specified element, or -1 if the list does not contain this element.
14.
int lastIndexOf(Object o)Returns the index in this list of the last occurrence of the specified element, or -1 if the list does not contain this element.
15.
ListIterator listIterator(int index)Returns a list-iterator of the elements in this list (in proper sequence), starting at the specified position in the list. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()).
16.
Object remove(int index)Removes the element at the specified position in this list. Throws NoSuchElementException if this list is empty.
17.
boolean remove(Object o)Removes the first occurrence of the specified element in this list. Throws NoSuchElementException if this list is empty. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()).
18.
Object removeFirst()Removes and returns the first element from this list. Throws NoSuchElementException if this list is empty.
19.
Object removeLast()Removes and returns the last element from this list. Throws NoSuchElementException if this list is empty.
20.
Object set(int index, Object element)Replaces the element at the specified position in this list with the specified element. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()).
21.
int size()Returns the number of elements in this list.
22.
Object[] toArray()Returns an array containing all of the elements in this list in the correct order. Throws NullPointerException if the specified array is null.
23.
Object[] toArray(Object[] a)Returns an array containing all of the elements in this list in the correct order; the runtime type of the returned array is that of the specified array.
Pattern matching
- is the act of checking a given sequence of tokens for the presence of the constituents of some pattern. In contrast to pattern recognition, the match has to either be or not be an exact match. The patterns have the form of either sequences or trees.
Sequence patterns, like strings, are often described using regular expressions and matched using techniques such as backtracking.
#regex
- is the act of checking a given sequence of tokens for the presence of the constituents of some pattern. In contrast to pattern recognition, the match has to either be or not be an exact match. The patterns have the form of either sequences or trees.
Sequence patterns, like strings, are often described using regular expressions and matched using techniques such as backtracking.
#regex
GoTo
- is a statement that performs a one-way transfer of control to another point of code; in contrast to a function call which returns control.
Its use has declined significantly since the advent of structured programming in the 1960s. Structured programming languages like #Pascal introduced control structures such as: subroutines, loops and multiway branch for clarity and efficiency. These replace equivalent flows written using gotos and ifs.
Language support:
• #C
• #CSharp: also makes
• #Perl
• #PHP there was no native support for goto until version 5.3
• #Java:
• #Python: does not support it but there are several joke modules that provide it.
The structured program theorem proves that
- is a statement that performs a one-way transfer of control to another point of code; in contrast to a function call which returns control.
Its use has declined significantly since the advent of structured programming in the 1960s. Structured programming languages like #Pascal introduced control structures such as: subroutines, loops and multiway branch for clarity and efficiency. These replace equivalent flows written using gotos and ifs.
Language support:
• #C
• #CSharp: also makes
case and default statements labels, whose scope is the enclosing switch statement; goto case or goto default is often used to replace explicit "fall-through", which C# disallows.• #Perl
• #PHP there was no native support for goto until version 5.3
• #Java:
goto is a reserved word, but is unusable.• #Python: does not support it but there are several joke modules that provide it.
The structured program theorem proves that
goto is not necessary to write programs.Structured program theorem
- states that the three combinations of subprograms which are sequence, choice, and iteration are sufficient for any computation that can be performed by a #Turing_machine; however, additional variables may be needed.
• Sequence: Executing one subprogram, and then another subprogram.
• Choice: Executing one of two subprograms according to the value of a boolean expression.
• Iteration: Executing a subprogram as long as a boolean expression is true.
- states that the three combinations of subprograms which are sequence, choice, and iteration are sufficient for any computation that can be performed by a #Turing_machine; however, additional variables may be needed.
• Sequence: Executing one subprogram, and then another subprogram.
• Choice: Executing one of two subprograms according to the value of a boolean expression.
• Iteration: Executing a subprogram as long as a boolean expression is true.
Forwarded from Ali "AnotherTest" Mohammad Pur
You should try making something that makes you think "I'm a fucking genius"
ComputerScientist
#Programming_paradigms : Declarative versus Imperative #Declarative All about relations. Does not state the order in which operations execute. Focuses on what the program should accomplish without specifying how the program should achieve the result. Expresses…
#Programming_paradigms
Expression versus Statement
An expression is a unit of #declarative programming.
A statement is a unit of #imperative programming.
An expression is evaluated whereas a statement is executed.
Expressions
A combination of values, variables and functions that return a value and have no side effects.
Expressions can contain functions and functions may have side effects. A side effect is a change to the abstract state of the running program that does not depend on the function input.
Functional programs do not have assignment statements therefore the value of a variable never changes once defined. An expression is said to be referentially transparent if it can be replaced with its corresponding value without changing the program's behavior. Evaluating a referentially transparent function gives the same value for same arguments. Such functions are called pure functions. Referentially transparent expressions allow #memoization.
Statements
Do not return results and are executed solely for their side effects.
Simple statements:
• assertion
• assignment
• goto
• return
• call
Compound statements: (may contain statements as components)
• block
• choice
• iteration
Expression versus Statement
An expression is a unit of #declarative programming.
A statement is a unit of #imperative programming.
An expression is evaluated whereas a statement is executed.
Expressions
A combination of values, variables and functions that return a value and have no side effects.
Expressions can contain functions and functions may have side effects. A side effect is a change to the abstract state of the running program that does not depend on the function input.
Functional programs do not have assignment statements therefore the value of a variable never changes once defined. An expression is said to be referentially transparent if it can be replaced with its corresponding value without changing the program's behavior. Evaluating a referentially transparent function gives the same value for same arguments. Such functions are called pure functions. Referentially transparent expressions allow #memoization.
Statements
Do not return results and are executed solely for their side effects.
Simple statements:
• assertion
• assignment
• goto
• return
• call
Compound statements: (may contain statements as components)
• block
• choice
• iteration
Computer Science is no more about computers than astronomy is about telescopes.
~ #EdsgerDijkstra
~ #EdsgerDijkstra
“Trees sprout up just about everywhere in computer science.”
— #Donald_Knuth
— #Donald_Knuth
#Programming_paradigms
#Structured
Structured versus non-structured
Non-structured programming
• Historically the earliest programming paradigm capable of creating #Turing_complete algorithms.
• Uses unstructured control flow construct of GoTo which can lead to "spaghetti code" that is potentially difficult to follow and maintain.
Structured programming
• Aims at improving the clarity, quality, and development time.
• Uses structured control flow constructs of choice and repetition, block structures, and subroutines.
Elements
• Control structures: following the structured program theorem, all programs are seen as composed of control structures of sequence, choice, iteration.
• Blocks: enable groups of statements to be treated as one statement.
• Subroutines: are callable units such as procedures, functions, methods, or subprograms are used to allow a sequence to be referred to by a single statement.
• Recursion: a subroutines is executed by repeatedly calling itself until termination conditions are met. While similar in practice to iterations, recursions may be more efficient.
#Structured
Structured versus non-structured
Non-structured programming
• Historically the earliest programming paradigm capable of creating #Turing_complete algorithms.
• Uses unstructured control flow construct of GoTo which can lead to "spaghetti code" that is potentially difficult to follow and maintain.
Structured programming
• Aims at improving the clarity, quality, and development time.
• Uses structured control flow constructs of choice and repetition, block structures, and subroutines.
Elements
• Control structures: following the structured program theorem, all programs are seen as composed of control structures of sequence, choice, iteration.
• Blocks: enable groups of statements to be treated as one statement.
• Subroutines: are callable units such as procedures, functions, methods, or subprograms are used to allow a sequence to be referred to by a single statement.
• Recursion: a subroutines is executed by repeatedly calling itself until termination conditions are met. While similar in practice to iterations, recursions may be more efficient.
#mathematics #geometry
Plane curve
Parametric equation:
Examples:
• Straight line
As a function:
• Circle
• Parabola
• Ellipse
Tangent
The tangent line (or simply tangent) to a plane curve at a given point is the straight line that "just touches" the curve at that point.
The line through a pair of infinitely close points on the curve. — #Gottfried_Leibniz
A straight line is a tangent of a curve
Plane curve
Parametric equation:
(x, y) = (f(x), g(y))Examples:
• Straight line
(x, y) = (x0+a*t, y0+b*t)As a function:
y = m*x + c• Circle
(x, y) = (r*cos(t), r*sin(t))• Parabola
(x, y) = (t, t^2)• Ellipse
(x, y) = (a*cos(t), b*sin(t))Tangent
The tangent line (or simply tangent) to a plane curve at a given point is the straight line that "just touches" the curve at that point.
The line through a pair of infinitely close points on the curve. — #Gottfried_Leibniz
A straight line is a tangent of a curve
y = f(x) at x = c if the line passes through the point (c, f(c)) on the curve and has a slope of (derivative(f))(c).#mathematics #calculus
Derivative
The derivative of a function of a real variable measures the sensitivity to change of the function value (output value) with respect to a change in its argument (input value).
The derivative of a function of a single variable at a chosen input value, when it exists, is the slope of the tangent line to the graph of the function at that point.
The process of computing a derivative is called differentiation. The reverse process is called antidifferentiation. The fundamental theorem of calculus states that antidifferentiation is the same as integration.
Differentiable function
- is a function whose derivative exists at each point in its domain. Its graph has a non-vertical tangent line at each point in its domain, is relatively smooth, and does not contain breaks, bends, or cusps (when a curve suddenly starts to move backwards).
If f is differentiable at x0, then f must also be continuous at x0. In particular, any differentiable function must also be continuous at every point in its domain. The converse does not hold.
Continuous function
- is a function for which sufficiently small changes in the input result in arbitrarily small changes in the output. Otherwise it is discontinuous.
Definition: f is continuous at c if
The function itself is said to be continuous if it is continuous at every point.
Derivative
The derivative of a function of a real variable measures the sensitivity to change of the function value (output value) with respect to a change in its argument (input value).
The derivative of a function of a single variable at a chosen input value, when it exists, is the slope of the tangent line to the graph of the function at that point.
The process of computing a derivative is called differentiation. The reverse process is called antidifferentiation. The fundamental theorem of calculus states that antidifferentiation is the same as integration.
Differentiable function
- is a function whose derivative exists at each point in its domain. Its graph has a non-vertical tangent line at each point in its domain, is relatively smooth, and does not contain breaks, bends, or cusps (when a curve suddenly starts to move backwards).
If f is differentiable at x0, then f must also be continuous at x0. In particular, any differentiable function must also be continuous at every point in its domain. The converse does not hold.
Continuous function
- is a function for which sufficiently small changes in the input result in arbitrarily small changes in the output. Otherwise it is discontinuous.
Definition: f is continuous at c if
limit(f(x), x approaches c) == f(c).The function itself is said to be continuous if it is continuous at every point.
#mathematics #geometry
Arc
- is a closed segment of a differentiable curve. A common example in the plane, is a segment of a circle called a circular arc.
Every pair of distinct points on a circle determines two arcs.
Arc
- is a closed segment of a differentiable curve. A common example in the plane, is a segment of a circle called a circular arc.
Every pair of distinct points on a circle determines two arcs.
#toRead
📚 Program Development by Stepwise Refinement
By #Niklaus_Wirth
http://sunnyday.mit.edu/16.355/wirth-refinement.html
📚 Program Development by Stepwise Refinement
By #Niklaus_Wirth
http://sunnyday.mit.edu/16.355/wirth-refinement.html
#toRead
📚 If Smalltalk Is So Good Why Does Nobody Use It
#Smalltalk
http://wiki.c2.com/?IfSmalltalkIsSoGoodWhyDoesNobodyUseIt
📚 If Smalltalk Is So Good Why Does Nobody Use It
#Smalltalk
http://wiki.c2.com/?IfSmalltalkIsSoGoodWhyDoesNobodyUseIt
#language #Haskell
Haskell
First appeared: 1990
Features:
• Purely #functional
• Statically and strongly typed (#Static_typing, #Strong_typing)
• #Type_inferring
• Lazy (#Lazy_evaluation)
• #pattern_matching
• #list_comprehension
• Type classes and type polymorphism (#type_class)
• Concurrent (#concurrency)
• Monads
Monads
Monads are a general framework that can model different kinds of computation, including error handling, nondeterminism, parsing and software transactional memory. Monads are defined as ordinary datatypes, but Haskell provides some syntactic sugar for their use.
Glasgow Haskell Compiler
GHC or Glasgow Haskell Compiler is the most commonly-used Haskell compiler and the main implementation of Haskell. It is open source and provides a cross-platform environment for writing and testing. It supports numerous extensions, libraries, and optimisations that streamline the process of generating and executing code. GHC itself is written in Haskell (#Bootstrapping); but the runtime system which is essential to run programs is written in C and C--.
Front end: (lexer, parser and typechecker)
Preserves as much information about the source as possible until after type inference is complete, to provide clear error messages to users. After type checking, the code is desugared (#syntactic_sugar) into a typed, intermediate language known as "Core".
Simplifier or "middle end":
- is where most of the optimizations are performed as a series of source-to-source transformations in Core code.
Back end:
Transforms Core code into an internal representation of C--. The C-- code can then take one of three routes: it is either printed as C code for compilation with GCC, converted directly into native machine code, or converted to LLVM virtual machine code for compilation with LLVM. In all three cases, the resultant native code is finally linked against the GHC runtime system to produce an executable.
C--
C-- is a #C like programming language, designed to be generated by compilers for very high-level languages rather than written by human programmers. Unlike many other intermediate languages, its representation is plain #ASCII text, not bytecode or another binary format.
C-- is a "portable #assembly language", designed to ease the task of implementing a compiler which produces high quality #machine_code. This is done by having the compiler generate C-- code, delegating the harder work of low-level code generation and optimisation to a C-- compiler.
The C-- type system is deliberately designed to reflect constraints imposed by hardware rather than conventions imposed by higher-level languages. In C-- a value stored in a register or memory may have only one type: bit vector. However, bit vector is a polymorphic type and may come in several widths, e.g., bits8, bits32, or bits64. In addition to the bit-vector type C-- also provides a Boolean type bool, which can be computed by expressions and used for control flow but cannot be stored in a register or in memory. As in an assembly language, any higher type discipline, such as distinctions between signed, unsigned, float, and pointer, is imposed by the C-- operators or other syntactic constructs in the language.
Haskell
First appeared: 1990
Features:
• Purely #functional
• Statically and strongly typed (#Static_typing, #Strong_typing)
• #Type_inferring
• Lazy (#Lazy_evaluation)
• #pattern_matching
• #list_comprehension
• Type classes and type polymorphism (#type_class)
• Concurrent (#concurrency)
• Monads
Monads
Monads are a general framework that can model different kinds of computation, including error handling, nondeterminism, parsing and software transactional memory. Monads are defined as ordinary datatypes, but Haskell provides some syntactic sugar for their use.
Glasgow Haskell Compiler
GHC or Glasgow Haskell Compiler is the most commonly-used Haskell compiler and the main implementation of Haskell. It is open source and provides a cross-platform environment for writing and testing. It supports numerous extensions, libraries, and optimisations that streamline the process of generating and executing code. GHC itself is written in Haskell (#Bootstrapping); but the runtime system which is essential to run programs is written in C and C--.
Front end: (lexer, parser and typechecker)
Preserves as much information about the source as possible until after type inference is complete, to provide clear error messages to users. After type checking, the code is desugared (#syntactic_sugar) into a typed, intermediate language known as "Core".
Simplifier or "middle end":
- is where most of the optimizations are performed as a series of source-to-source transformations in Core code.
Back end:
Transforms Core code into an internal representation of C--. The C-- code can then take one of three routes: it is either printed as C code for compilation with GCC, converted directly into native machine code, or converted to LLVM virtual machine code for compilation with LLVM. In all three cases, the resultant native code is finally linked against the GHC runtime system to produce an executable.
C--
C-- is a #C like programming language, designed to be generated by compilers for very high-level languages rather than written by human programmers. Unlike many other intermediate languages, its representation is plain #ASCII text, not bytecode or another binary format.
C-- is a "portable #assembly language", designed to ease the task of implementing a compiler which produces high quality #machine_code. This is done by having the compiler generate C-- code, delegating the harder work of low-level code generation and optimisation to a C-- compiler.
The C-- type system is deliberately designed to reflect constraints imposed by hardware rather than conventions imposed by higher-level languages. In C-- a value stored in a register or memory may have only one type: bit vector. However, bit vector is a polymorphic type and may come in several widths, e.g., bits8, bits32, or bits64. In addition to the bit-vector type C-- also provides a Boolean type bool, which can be computed by expressions and used for control flow but cannot be stored in a register or in memory. As in an assembly language, any higher type discipline, such as distinctions between signed, unsigned, float, and pointer, is imposed by the C-- operators or other syntactic constructs in the language.
“TBH I had a pretty solid syntax in mind from the beginning.
#Smalltalk was very much the only thing that inspired the syntax at first.
Then I just replaced the unsightly
And much much later added
— #TheSemicolon, on syntax development of #Citron
#Smalltalk was very much the only thing that inspired the syntax at first.
Then I just replaced the unsightly
[] for code blocks with {}And much much later added
(\:arg expr)”— #TheSemicolon, on syntax development of #Citron