Type Systems

Data Types & Type Systems

Comparative study across C, JavaScript, Python, and Java.

SLIDE 1 / 6

1. Data Types Classification

Data types tell the compiler or interpreter how to interpret RAM bit sequences.

Primitive Types: Atomic values stored directly (numbers, chars, booleans).
Reference / Composite Types: Composite structures (arrays, objects, classes) stored in Heap.
MEMORY REPRESENTATION
int age = 25 [Primitive: 4 Bytes]
String name = "Ana" [Reference: Heap Addr]

2. Primitives Across Languages

  • C: char (8-bit), int (32-bit), float (32-bit IEEE), double.
  • JavaScript: number (64-bit float), bigint, string, boolean, symbol, null, undefined.
  • Python: int (precisión arbitraria), float, bool, str, NoneType.
  • Java: byte, short, int, long, float, double, boolean, char.
primitives.ts
// JS/TS: number abarca enteros y flotantes
let cantidad = 42; 
let precio = 19.99;

// C / Java: Explicitez estricta
int c_cantidad = 42;
double c_precio = 19.99;

3. Composite & Reference Types

Store complex structures or data collections via addresses pointing to the Heap.

Arreglos / Arrays: Secuencias contiguas de elementos.
Objetos / Structs: Agrupaciones de pares clave-valor o atributos.
structures.py
# Python List (Doble puntero a Heap)
items = [1, "dos", 3.0]

# C Struct (Bloque continuo contiguo)
struct Point { int x; int y; };

4. Static vs Dynamic & Strong vs Weak

Java (Estático / Fuerte): Chequeo en compilación; prohíbe operaciones incompatibles.
C (Estático / Nivel Medio): Chequeo en compilación; permite reinterpretación de punteros.
JavaScript (Dinámico / Débil): Chequeo en tiempo de ejecución con coherción implícita automática.
Python (Dinámico / Fuerte): Chequeo en tiempo de ejecución; rechaza conversiones implícitas no válidas.
typing_comparison.js
// JS (Débil): "5" + 2 === "52"
console.log("5" + 2);

# Python (Fuerte): TypeError!
# print("5" + 2) 

5. Type Coercion & Casting

Type conversion can be explicit (Casting) or implicit (Runtime Coercion).

  • Explicit Casting: `(int) 3.14` (C/Java), `int("5")` (Python).
  • Implicit Coercion: Ocurre automáticamente en JS al usar operadores binarios como `+` o `==`.
casting.c
double pi = 3.14159;
int entero_pi = (int) pi; // Trunca a 3

char c = 'A';
int ascii = (int) c; // 65

6. Interactive Type Inspector

Select an expression to evaluate each language result:

JavaScript
"105" (string)
Python
TypeError: can't concat str to int
C
Error de Compilación (Tipos incompatibles)
Java
"105" (String via StringBuilder)