🔁 Transpiling vs 🧱 Compiling
🔁 Transpiling
Converting code from one language (or version) to another at the same level of abstraction.
- 📥 Input: Source code (e.g., modern JavaScript - ES6)
- 📤 Output: Equivalent source code (e.g., older JavaScript - ES5)
- 💡 Use Case: Compatibility. Browsers may not support modern JS, so tools like Babel transpile it to older versions.
Examples:
- TypeScript → JavaScript
- ES6 → ES5 (via Babel)
- SASS → CSS
💬
Note: SASS is technically a preprocessor, but often referred to as being "transpiled" into CSS.
🧱 Compiling
Translating high-level code into a lower-level form, usually machine code or bytecode.
- 📥 Input: High-level source code (e.g., C, Java)
- 📤 Output: Machine code or bytecode (e.g.,
.exe
, JVM bytecode) - 💡 Use Case: To run the program efficiently on hardware or in a runtime (like JVM or CLR)
Examples:
- C → Assembly → Machine code
- Java → Bytecode (
.class
files for JVM) - Go → Native binary executable
🧠 Summary
Feature | Transpiling | Compiling |
---|---|---|
Level | Source code → Source code | Source code → Lower-level code |
Abstraction | Same level | Lower level |
Output | Human-readable (usually) | Often binary or bytecode |
Example Tool | Babel, TypeScript compiler (tsc) | GCC, java, Go compiler |
Goal | Compatibility or feature support | Execution |