Programming Languages - Concepts

Updated: 2019-02-03

Standard vs. Implementation

  • Standard is the language specification, listing all the definitions and features of the language, however nothing "physical".
  • Implementation is the actual engine that can execute the code that comply with the spec.

Examples:

  • Java:

  • JavaScript/ECMAScript:

    • one specification: ECMA-262
    • JavaScript, JScript and ActionScript are all implementations of ECMA-262 standard. The implementations are compatible with ECMAScript though may also provide additional features.
  • SQL

    • Standards like SQL-92, SQL-2011, etc.
    • Databases usually implement only a portion of the standards, plus some custom features. So one SQL query from a certain database may or may not work in another database.

Package Managers

  • Java/Scala: Maven Central
  • Python: Python Package Index
  • Node.js: npm(Node Package Manager)
  • Ruby: RubyGems.
  • Perl: Comprehensive Perl Archive Network (CPAN)
  • R: Comprehensive R Archive Network (CRAN).

Imperative vs Functional

  • In a imperative program: a function depends on two things

    • the parameters it is passed and also
    • the current state of the machine store.
  • In a functional language:

    • only the parameters it is passed matters.

Dynamic Type vs Static Type

dynamically typed language. This means that variables do not have types; only values do. There are no type definitions in the language. All values carry their own type.

Dynamically Linked vs Statically Linked

  • static: link at compile time
  • dynamic: link at runtime

Some languages use both: static linking to deploy, dynamic linking to iterate, e.g.

  • clang for testing(quick to compile, slower to run)
  • cpp for deploy(slow to compile, quick to run)

Statically Declared Array vs Dynamically Declared Array

  • static: allocates memory at compile-time, size is fixed, in stack, no need to manage memory
  • dynamic: can alter the size at run time, in heap, need to allocate and free memory
int* a = new int[10];
delete[] a;

Alternatively std::vector can be used, which resizes itself automatically

std::vector<int> v = {1, 2, 3, 4}

System Programming Languages

wiki

A system programming language usually refers to a programming language used for system programming; such languages are designed for writing system software, which usually requires different development approaches when compared with application software. System software is computer software designed to operate and control the computer hardware, and to provide a platform for running application software.

Go vs Rust

  • Rust: replacing C++ and D for programmers who are prepared to accept more complex syntax and semantics (and presumably higher readability costs) in return for the maximum possible performance. For example, micro controllers, AAA game engines, and web rendering engines.
  • Go: for companies who have outgrown languages like Ruby, Python, and Node.js (v8) and have lost patience with the high deployment costs of JVM based languages.

Virtual Machines

  • JVM(Java Virtual Machine): Java, Scala, Groovy, Kotlin

    • Why Groovy is more Popular than Scala: Groovy is 100% Java compatible because it IS Java; take any Java class, change the extension to from '.java' to '.groovy' and it WILL compile (NOTE: one must have groovy library installed).
  • CLR(Common Language Runtime): C#
  • HipHop Virtual Machine (HHVM): PHP/Hack. HHVM JIT compilation, executed PHP or Hack code is first transformed into intermediate HipHop bytecode (HHBC), which is then dynamically translated into x86-64 machine code, optimized, and natively executed. This contrasts with PHP's usual interpreted execution, in which the Zend Engine transforms PHP source code into opcodes that serve as a form of bytecode, and executes the opcodes directly on the Zend Engine's virtual CPU.

LLVM

  • Clang: frontend for C/C++/Object-C/Object-C++
  • LLVM: the backend and the umbrella project name. Backend converts the LLVM Intermediate Representation(IR) to code for a specified machine or other languages(hardware OR software target)

JIT

  • static compiler, or ahead-of-time(AOT) compiler: at compile-time, e.g. from .java to bytecode .class
  • dynamic compiler, or just-in-time(JIT) compiler: at run-time, e.g. in Java compiles bytecode to native instructions

bytecode is portable, but native code is not.

Java JIT 2 flavors:

  • client-side compiler(with -client option): fewer resources, sensitive to startup time
  • server-side compiler(with -server option): long running, more advanced optimizations.

Besides Java, PyPy provides JIT for Python, V8 compiles javascript directly to native machine code.

Mutability

  • Immutable: cannot be changed once created
  • Mutable: can be changed

Java: String and all of the number classes, such as Integer, Double, Character, and BigInteger.

Compiled vs Scripts

  • compiled to standalone executables: C/C++, COBOL
  • ran in an interpreter: Perl, Tcl
  • Java need for both a bytecode compiler and a runtime interpreter.
  • Python and R have no compile-time type-safety,
  • Compiled-to-JavaScript language: dart, typescript, flow

Stack vs Heap

  • Stack: primitive values, references to objects, and methods; short-lived. LIFO. Whenever a method is invoked, a new block is created in the stack memory for the method to hold local primitive values and reference to the other objects.
  • Heap: object created by new; array is also object, so also in heap.

    • Young gen
    • Old gen
    • PermGen(replaced by Metaspace, which uses native memory, in Java 8)
  • use -Xmx, -Xms to specify the size of Heap
  • use -Xss to specify the size of stack

Recursive methods usually use much more stack space, and therefore more memory, than an iterative counterpart.

Coroutines: also called collaborative multithreading. A coroutine in Lua represents an independent thread of execution. Unlike threads in multithread systems, however, a coroutine only suspends its execution by explicitly calling a yield function.

Reactive Programming

In a nutshell reactive programming is about non-blocking, event-driven applications that scale with a small number of threads with backpressure as a key ingredient that aims to ensure producers do not overwhelm consumers.

A practical challenge when switching from imperative-style logic to non-blocking is the ability to compose async logic without getting lost in “callback hell”.

The basic idea behind reactive programming is that there are certain datatypes that represent a value "over time". Computations that involve these changing-over-time values will themselves have values that change over time.

reactive-streams

COBRA vs RMI

  • RMI is a Java-specific technology. CORBA has implementations for many languages. You can use CORBA to share objects between programs written in different languages (e.g. C++ and Java).
  • CORBA uses IDL (Interface Definition Language) to separate interface from implementation. RMI just uses Java interfaces.

libc++ vs libstdc++

  • libc++: sourced from LLVM(preferred)
  • libstdc++: sourced from GNU

5 things about programming I learned with Go

http://mjk.space/5-things-about-programming-learned-with-go/

  1. It is possible to have both dynamic-like syntax and static safety;
  2. It’s better to compose than inherit;
  3. Channels and goroutines are powerful way to solve problems involving concurrency;
  4. Don’t communicate by sharing memory, share memory by communicating;
  5. There is nothing exceptional in exceptions.

Good comment section: C++ can do all that, Erlang did all that before, Go doesn't make you do all that.

PPL: Probabilistic Programming Language

http://dippl.org/

4th Generation Programming Language

https://en.wikipedia.org/wiki/Fourth-generationprogramminglanguage

Char in Programming Language

  • Java: 2 bytes, 16 bits, unsigned([0, 65535]), unicode(UTF-16)
  • C/C++: 1 byte, 8 bits, ASCII

WebAssembly

A bytecode for browsers, intended to be faster to parse than asm.js

Domain-Specific Language (DSL)

Different from a General-Purpose Language (GPL), a DSL is for a specific problem. For example, CSS is just for styling web elements, SQL is for database queries, make for building programs.

Ruby, Scala, Groovy are especially good for building DSLs. E.g. Gremlin is a graph traversal language written in the Groovy.