Polyglot Programming Concepts
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 vs Static
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.
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. E.g. in Java world, there's one JVM specification however multiple implementations, like OpenJDK, Oracle JDK etc.
The implementations are compatible with ECMAScript though may also provide additional features.
System Programming Languages
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.
- JVM(Java Virtual Machine): Java, Scala, Groovy, Kotlin
- CLR(Common Language Runtime): C#
- HipHop Virtual Machine (HHVM): PHP/Hack
- 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’s need for both a bytecode compiler and a runtime interpreter.
Stack vs Heap
Stack: primitive values, references to objects, and methods
Heap: object created by
- 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.
Autoboxing and Unboxing: primitive to object wrapper classes, and back
String vs. StringBuilder
Lua - a powerful, lightweight and embeddable scripting language that’s incredibly fast. All Lua actions start from C code in the host program calling a function from the Lua library.
Lua is good for
- run inside nginx
- in Redis
- in games
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.
Go vs Rust
- Rust competes for mindshare with 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 competes for mindshare in the post 2006 Internet 2.0 generation of 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.
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.
HHVM similar to CLR and JVM
- 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).
Why Groovy is more Popular than Scala
Languages like Groovy on the other hand ARE 100% Java compatible because they ARE Java; take any Java class, change the extension to from '.java' to '.groovy' and it WILL compile (NOTE: one must have groovy library installed).
4th Generation Programming Language
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.
Compile Time and Run Time
Python and R have no compile-time type-safety,
The main use case for DI was ease of testing
- Flyweight Pattern: minimizes memory use by sharing as much data as possible with other similar objects.
- String Interning: is a method of storing only one copy of each distinct string value, which must be immutable.
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.
5 things about programming I learned with Go
- It is possible to have both dynamic-like syntax and static safety;
- It’s better to compose than inherit;
- Channels and goroutines are powerful way to solve problems involving concurrency;
- Don’t communicate by sharing memory, share memory by communicating;
- 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.
Modern js cheatsheet: https://github.com/mbeaudru/modern-js-cheatsheet