Compile-Time, Run-Time, and Execution Explained Simply
I learnt something today, i learnt some technical words like Run-time Error, Linting, compile-time. The truth is that i keep hearing and using this words without really knowing the meaning for real.
1. Run-time Error
Definition: An error that occurs while the program is running, after it has successfully compiled.
Example: Dividing by zero, accessing an array out of bounds, null pointer exceptions.
Explanation: The code looks fine to the compiler, but something unexpected happens when the program executes.
Example in Rust:
let x = 10;
let y = 0;
console.log(x / y); // Runtime error in some languages (Infinity in JS)
2. Linting
Definition: Linting is the process of analyzing code without running it to find potential errors, style issues, or bad practices.
Tools: ESLint (JS), Pylint (Python), RuboCop (Ruby).
Example: Detecting unused variables, missing semicolons, or inconsistent indentation.
Key point: Linting doesn’t execute the program, it just checks code quality and potential bugs.
Example:fn main() {
let text = "Hello, world!";
}Output:
cargo clippy ─╯
Checking rust_pract v0.1.0 (/Users/user/Downloads/workspace/AllAboutRust/rust_pract)
warning: unused variable: `text`
--> src/main.rs:3:9
|
3 | let text = "Hello, world!";
| ^^^^ help: if this is intentional, prefix it with an underscore: `_text`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
warning: `rust_pract` (bin "rust_pract") generated 1 warning
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
we use cargo clippy for linting in rust.
3. Compile-time
Definition: Errors or checks that happen when the code is being compiled (before running).
Example: Syntax errors, type mismatches, undeclared variables.
Explanation: The compiler prevents your program from running until these errors are fixed.
Example in Rust:
let x: u32 = "Hello"; // Compile-time error: type mismatch
but wait what does it even mean for your code to be compiled?
Compiled means translating that high-level code (The code human can read and understand) into machine code (the binary’s, the computer language that is that 0’s and 1’s)
Thank you for your time:
sign ✍🏽: iamtechhunter