Programming Languages Cheat Sheet

Programming Language Paradigms

ParadigmDescriptionCharacteristicsExamples
ImperativeSpecify how to solve a problem using statements that change program stateVariables, assignment, control flow, subroutinesC, Pascal, Fortran, Basic
Object-OrientedStructure programs around objects that contain data and methodsEncapsulation, inheritance, polymorphism, abstractionJava, C++, C#, Python
FunctionalTreat computation as evaluation of mathematical functionsImmutability, higher-order functions, recursionHaskell, Lisp, ML, F#, JavaScript
LogicExpress programs as relations and use logical inferenceDeclarative, predicates, rules, factsProlog, Datalog
ProceduralBased on procedure calls and structured programmingFunctions, procedures, variables, loopsPascal, C, Fortran
Event-DrivenProgram flow determined by eventsEvent handlers, callbacks, asynchronous executionJavaScript, Visual Basic, C#

Type Systems

ConceptDescriptionExamplesAdvantages/Disadvantages
Static TypingTypes checked at compile timeJava, C, C++, HaskellEarly error detection, performance, but less flexibility
Dynamic TypingTypes checked at runtimePython, Ruby, JavaScript, PHPFlexibility, rapid development, but runtime errors possible
Strong TypingStrict enforcement of type rulesHaskell, Python, JavaPrevents type errors, but may require explicit conversions
Weak TypingLoose enforcement of type rulesC, C++, JavaScriptFlexibility, but potential for errors
PolymorphismSame interface for different data typesFunction overloading, generics, inheritanceCode reusability, but complexity
Type InferenceCompiler deduces types automaticallyHaskell, ML, Scala, C#Less verbose, but harder to debug type errors

Memory Management

ApproachDescriptionExamplesAdvantages/Disadvantages
Manual ManagementProgrammer explicitly allocates/deallocates memoryC, C++Full control, performance, but memory leaks possible
Automatic (Garbage Collection)Runtime system automatically reclaims unused memoryJava, C#, Python, JavaScriptNo memory leaks, but performance overhead
Reference CountingTrack number of references to each objectPython (partially), Objective-CDeterministic deallocation, but cycle detection issues
Borrowing/Rust ModelCompile-time ownership checkingRustNo garbage collection, memory safety
Stack AllocationAutomatic allocation/deallocation in LIFO orderAll languagesFast allocation, automatic cleanup
Heap AllocationDynamic allocation with manual or automatic managementMost languagesFlexible lifetime, but slower allocation

Scoping Rules

Scoping TypeDescriptionExamplesCharacteristics
Lexical (Static)Variable scope determined by source code structureC, Java, Python, C++Predictable, checked at compile time
DynamicVariable scope determined at runtimeEarly Lisp, Perl (special variables)Flexible, but harder to debug
Global ScopeVariable accessible throughout programAll languagesEasy access, but can cause naming conflicts
Local ScopeVariable accessible only within specific blockAll languagesEncapsulation, avoids naming conflicts
Block ScopeVariable accessible within a blockC, Java, JavaScriptFine-grained control
Function ScopeVariable accessible within functionJavaScript (var)Hoisting behavior

Programming Language Constructs

ConstructPurposeExamplesImplementation
Control StructuresControl flow of executionif/else, while, for, switchConditional jumps, loops in machine code
Functions/MethodsModularize code into reusable unitsfunction, procedure, method, subroutineStack frames, parameter passing, return mechanisms
Data StructuresOrganize and store dataArrays, records, classes, structsMemory layout, access methods
AbstractionHide implementation detailsClasses, modules, interfacesEncapsulation, information hiding
Error HandlingDeal with exceptional conditionstry/catch/finally, exceptions, error codesStack unwinding, exception handling mechanism
ConcurrencyExecute multiple tasks simultaneouslyThreads, coroutines, async/awaitOS threads, event loops, green threads

Compilation Process

PhaseDescriptionInputOutput
Lexical AnalysisConvert source code to tokensCharacter streamToken stream
Syntax AnalysisParse tokens into syntax treeToken streamParse tree/AST
Semantic AnalysisCheck semantic rulesParse treeDecorated AST
Intermediate Code GenerationCreate intermediate representationDecorated ASTIR code
OptimizationImprove code efficiencyIR codeOptimized IR
Code GenerationCreate target machine codeOptimized IRAssembly/machine code
AssemblyConvert assembly to machine codeAssembly codeObject code
LinkingCombine object filesObject files, librariesExecutable

Language Implementation

MethodDescriptionExamplesAdvantages/Disadvantages
CompilationTranslate entire program before executionC, C++, Go, RustFast execution, but longer development cycle
InterpretationExecute program directly without prior translationPython, Ruby, JavaScript (initially)Fast startup, interactive development
Hybrid (Bytecode)Compile to intermediate code, then interpretJava (JVM), Python (.pyc), C# (.NET)Platform independence, good performance
Just-In-Time (JIT)Compile code at runtimeJava (HotSpot), JavaScript (V8), .NETOptimization opportunities, but warm-up time
TranspilationTranslate source to sourceTypeScript → JavaScript, CoffeeScript → JavaScriptUse advanced features on existing platforms

Language Features Comparison

FeatureCJavaPythonJavaScript
TypingStatic, weakStatic, strongDynamic, strongDynamic, weak
Memory ManagementManualGarbage collectedGarbage collectedGarbage collected
ParadigmProceduralOOP, imperativeMulti-paradigmMulti-paradigm
ExecutionCompiledBytecode + JITInterpretedInterpreted + JIT
ConcurrencyThreads, POSIXThreads, asyncThreads, async, GILEvent loop, async
PlatformCross-platformWrite once, run anywhereCross-platformBrowser, server

Standard Language Components

ComponentPurposeExamplesImplementation
Standard LibraryProvide common functionalityString handling, I/O, data structuresBuilt-in functions, classes, modules
Runtime SystemSupport program executionMemory manager, garbage collectorSystem libraries, kernel interfaces
Package ManagerManage dependencies and librariesnpm, pip, Maven, CargoRepository systems, dependency resolution
Development ToolsSupport development processIDEs, debuggers, profilersLanguage-specific tools
DocumentationExplain language featuresAPI docs, tutorials, specificationsAutomated doc generation

Language Design Principles

PrincipleDescriptionApplicationBenefits
SimplicityKeep language features minimal and clearAvoid unnecessary complexityEasier to learn, implement, and maintain
OrthogonalityCombine features in consistent waysIndependent language constructsPredictable behavior, fewer special cases
GeneralityUse few constructs for many purposesPolymorphism, generic typesReduced redundancy, increased flexibility
UniformityConsistent syntax and semanticsConsistent naming, syntax rulesEasier to learn and use
AbstractionHide complexity behind simple interfacesFunctions, classes, modulesManageable complexity, code reuse
EfficiencyEnable performance optimizationLow-level access, optimization opportunitiesFast execution, resource utilization