Skip to content

Instantly share code, notes, and snippets.

@gusalbukrk
Last active January 12, 2021 01:35
Show Gist options
  • Save gusalbukrk/ae2344bf2ae11f22fccb353bf73901be to your computer and use it in GitHub Desktop.
Save gusalbukrk/ae2344bf2ae11f22fccb353bf73901be to your computer and use it in GitHub Desktop.
#cs #jargon

Programming jargon

Paradigms

  • example of procedural vs functional in JS: for loop vs forEach

Imperative

  • how to do something
  • uses statements (e.g. for, if, switch) that changes the program flow

Procedural

  • groups instructions into procedures
  • e.g. C

Object-oriented

  • groups instructions with the part of the state they operate on
  • objects contain properties and methods
  • e.g. Java

Declarative

  • what the problem is = expresses the logic, not how to solve the problem
  • doesn't describe its control flow,
  • relies on expressions (function calls, values and operators)

Functional

  • desired result is declared as the value of a series of pure function applications
  • avoids: shared state, mutating state and side effects
    • shared state = any non-constant variable used by multiple separate scopes
  • e.g. Haskell

Logic

  • based on formal logic
  • in which the desired result is declared as the answer to a question about a system of facts and rules
  • e.g. Prolog

Mathematical

  • desired result is declared as the solution of a optimization problem
  • e.g. MatLab

Scripting vs compiled languages

Scripting

  • doesn't require compilation
  • are interpreted at runtime
  • usually have less access to the computer's native abilities

Compiled

  • requires compilation
  • run faster because they're first converted to native machine code
  • errors are caught before execution

Lazy evaluation

  • or call-by-need delays the evaluation of an expression until its value is needed
  • benefits: define potentially infinite data structures, performance increase by avoid needless calculations
  • e.g. Haskell

Expression & Statement

Expression

  • produces a value(s); an expression is evaluated
  • often don't have side effects
  • e.g. values and function

Statement

  • syntactic unit of an imperative programming language
  • performs actions; a statement is executed
  • don't return results and are executed solely for their side effects
  • many statements are introduced by identifiers like if, while, for

Expression statements

  • expressions that have side effects
  • e.g. assign/change a variable
  • in many languages (C++) a expression becomes an expression statement when is ended with a semicolon
    • this makes the program evaluate the expression only for its side-effects and disregard its result

Functions

Scope chain

  • function call's outer environment
  • define which variables are available to a specific function execution

Lexical

  • scope is defined by the location of its definition within the source code, not by the location of its call
  • if a variable is not available in the local environment the function always go searching one level up from where it was written until it reaches the global level
  • most languages have this type of scope
    • JavaScript = the only dynamically scoped mechanism is this inside an non-arrow function

Dynamic

  • scope is defined by the location of the function calling, not by the location of its definition
  • bash is the most common language to have this type of scope

Higher-order functions

  • takes a function as argument or returns a function
  • e.g. map, filter...
  • a language that allow this is said to have first-class functions, i.e. it treats function as first-class citizens

Callback

  • a function you provide to another piece of code, allowing it to be executed by that code
  • execution may be immediate as in a synchronous callback, or it might happen at a later time as in an asynchronous callback

Closure

  • implemented in languages with first-class functions (functions can return a function)
  • stores a function together with its lexical environment (referenced variables of the outer function)

Recursion

  • functions that call themselves within their code
  • usually recursive problems can also be solved with iteration

Curry

  • function which takes multiple arguments one at a time
  • in Haskell all functions are curried; this is hide in notation and not apparent

(Partial) application

Application

  • *applying a function to its arguments in order to produce a return value

Partial application

  • apply a function to some of its arguments
  • this function will return a function with fewer parameters

Function composition

  • the result of each function is passed as the argument of the next, and the result of the last one is the result of the whole
  • e.g.
    • z = f(g(x)); = C
    • [3, 5, 8].map(x => x * 2).filter(x => x >= 10) = JavaScript functional style
    • (f . g . z) x = in Haskell (equivalent to f (g (z x)))

Lambda/anonymous function

  • function definition not bound to an identifier
  • often, is used in a higher-order function

Functors

  • any object that can be mapped over
  • apply a function in a specific context (type)
  • JavaScript’s built in array and promise objects act like functors
    • .then() is an asynchronous .map()

Monoid

  • monoid is when you have an associative binary function and a value which acts as an identity with respect to that function
    • acts as an identity = when called with that function and some other value, the result is always equal to that other value
    • e.g. number 1 is the multiplication identity

Monad

  • pattern for chaining (compose) functions that require context (computation, branching, I/O) in addition to the return value
  • if you have a value with a context (M a) how do you apply to it a function that takes a normal 'a' and returns a value with a context
  • Functors map with context, monads flatten and map (flatMap) with context
    • monads are a type of functor but with the special power to unwrap any value from its context using the flatMap
  • usefulness: needed because lots of functions aren’t simple mappings from a => b. Some functions to deal with side effects (promises, streams), handle branching (Maybe), deal with exceptions (Either)

Pure functions

  • no side-effects; only produces and returns a value
  • deterministic: same input always returns the same output
  • referential transparency is a property of pure functions
    • allows the replacement of a function call with its resulting value without changing the meaning of the program

Control structures

  • specify flow of control in programs

Sequential

  • sequential execution of code statements (one line after another)

Selection/conditional

  • e.g. if-else, case & switch

Repetition/iteration

  • e.g. for loop, while, repeat

Coupling

  • is the degree of interdependence between software modules and routines

Tight coupling

  • modules and routines are highly dependent on one another
  • disadvantages: changes cause ripple effect, harder to reuse

Loose coupling

  • promotes independency, single-responsibility and separation of concerns
  • advantages: changes are easier to make, code reusability

Operators

Rules

Operator precedence

  • which operator gets called first

Operator associativity

  • what order should operators of the same precedence (without parentheses) be called
  • left-to-right or right-to-left

Types

Arithmetic

  • e.g. plus (+)

Logical

  • AND, OR, NOT

Comparison

  • e.g. equal (=)

Assignment

  • usually =, := or <-

Object's property acess

  • usually .

Type system

  • typing = assigning a data type

Type inference

  • capability of the type system to deduce the type of a variable

Statically vs dynamically typed

Statically

  • type of variables are know at compile time
  • this means that you as the programmer must specify what type each variable is (e.g. Java, C++); other languages offer some form of type inference (e.g. Haskell, Scala)
  • a lot of trivial bugs are caught early

Dynamically

  • don't have to specify type
  • type of variables are know at run time (the interpreter will assign a type based on the variable's value)
  • e.g.
    • Python, PHP, JavaScript
    • scripting languages have this feature as there is no compiler

Strong vs weak typing

Strong

  • stricter rules, error and exceptions are more likely to happen
  • implicit conversion doesn't happen

Weak

  • may produce unpredictable or may perform implicit type conversion

Short-circuit evaluation

  • one() && two() = two will be executed only if one returns a truthy value
  • one() || two()= two will be executed only if one returns a falsy value

Yoda conditions

  • 42 === myValue = solves a very common mistake: assign a value unintentionally instead of writing a conditional statement

Versioning

  • 4.1.7-beta
    • 4 = major
    • 1 = minor
    • 7 = patch
    • beta = optional pre-release label

Symbols

  • ^ = minor releases
  • ~ = patch releases

Parameters vs arguments

Parameters

  • variables defined at function definition

Arguments

  • values passed to a function call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment