Missing features of programming languages
I have noticed that whenever a programming language is missing a feature, its users often tend to reimplement the feature in a way that is uglier, more complicated and more fragile, while arguing that adding the feature would make the language more complex.
Examples
- Language:
- C
- Feature:
- parametric polymorphism
- Workaround:
void*
, weird tricks with #include
& #define
- Language:
- C++ & Java
- Feature:
- structural pattern matching
- Workaround:
- the “visitor pattern”
- Language:
- Java (old versions)
- Feature:
- first-class functions
- Workaround:
- the “strategy pattern”
- Language:
- Go (old versions)
- Feature:
- parametric polymorphism
- Workaround:
interface{}
, code generation
- Language:
- Java
- Feature:
- free-standing procedures
- Workaround:
- static classes
- Language:
- C & C++
- Feature:
- a proper module system
- Workaround:
#include
, header files, guards, #pragma once
- Language:
- Go
- Feature:
- enums
- Workaround:
iota
(no type safety)
- Language:
- WebAssembly
- Feature:
- DOM API
- Workaround:
- JavaScript glue code
- Language:
- C
- Feature:
- bit sets
- Workaround:
#define STRAWBERRY (1 << 0)
#define BANANA (1 << 1)
#define WATERMELON (1 << 2)
#define APPLE (1 << 3)
- Language:
- JavaScript
- Feature:
- statements as expressions
- Workaround:
- immediately-invoked functions
- Language:
- C
- Feature:
- sum types
- Workaround:
- tagged unions (no type safety)
- Language:
- Java
- Feature:
- named arguments
- Workaround:
- “builder pattern”
- Language:
- C
- Feature:
- optional types / exceptions
- Workaround:
- error codes
Honorable mentions
- Haskell deals with missing features by having many language extensions, at the cost of creating 2many dialects