What makes programming languages feel the way they do?
What makes these programs different?
Simplicity: How many concepts to memorize?
Conciseness: How much code to write to solve a problem?
Familiarity: How many well-known concepts and syntactic elements?
Accessibility: How easy to install, build, run?
Some are mutually exclusive!
class Cat {
std::string _name;
bool _is_angry;
public:
Cat(std::string name, bool is_angry) : _name(std::move(name)), _is_angry(is_angry) {}
void pet() const {
std::cout << "Petting the cat " << _name << std::endl;
if(_is_angry) {
std::cout << "*hiss* How dare you touch me?" << std::endl;
} else {
std::cout << "*purr* This is... acceptable." << std::endl;
}
}
};
int main() {
Cat cat1{"Milo", false};
Cat cat2{"Jack", true};
cat1.pet();
cat2.pet();
}
class Cat {
std::string _name;
bool _is_angry;
public:
Cat(std::string name, bool is_angry) : _name(std::move(name)), _is_angry(is_angry) {}
void pet() const {
std::cout << "Petting the cat " << _name << std::endl;
if(_is_angry) {
std::cout << "*hiss* How dare you touch me?" << std::endl;
} else {
std::cout << "*purr* This is... acceptable." << std::endl;
}
}
};
int main() {
Cat cat1{"Milo", false};
Cat cat2{"Jack", true};
cat1.pet();
cat2.pet();
}
class Cat {
std::string _name;
bool _is_angry;
public:
Cat(std::string name, bool is_angry) : _name(std::move(name)), _is_angry(is_angry) {}
void pet() const {
std::cout << "Petting the cat " << _name << std::endl;
if(_is_angry) {
std::cout << "*hiss* How dare you touch me?" << std::endl;
} else {
std::cout << "*purr* This is... acceptable." << std::endl;
}
}
};
int main() {
Cat cat1{"Milo", false};
Cat cat2{"Jack", true};
cat1.pet();
cat2.pet();
}
class Cat {
std::string _name;
bool _is_angry;
public:
Cat(std::string name, bool is_angry) : _name(std::move(name)), _is_angry(is_angry) {}
void pet() const {
std::cout << "Petting the cat " << _name << std::endl;
if(_is_angry) {
std::cout << "*hiss* How dare you touch me?" << std::endl;
} else {
std::cout << "*purr* This is... acceptable." << std::endl;
}
}
};
int main() {
Cat cat1{"Milo", false};
Cat cat2{"Jack", true};
cat1.pet();
cat2.pet();
}
struct Student {
pub id: String,
pub gpa: f64,
pub courses: Vec<String>,
}
fn which_courses_are_easy(students: &[Student]) -> HashSet<String> {
students
.par_iter() // Run on all CPU cores (using the rayon crate)
.filter(|student| student.gpa >= 3.0)
.flat_map(|student| student.courses.clone())
.collect()
}
virtual
functions)max<T>
)tokio
Rust framework using async / .await:use mini_redis::{client, Result};
#[tokio::main]
async fn main() -> Result<()> {
// Open a connection to the mini-redis address.
let mut client = client::connect("127.0.0.1:6379").await?;
// Set the key "hello" with value "world"
client.set("hello", "world".into()).await?;
// Get key "hello"
let result = client.get("hello").await?;
println!("got value from the server; result={:?}", result);
Ok(())
}
class
, no inheritance
Identify the programming paradigms that these three snippets use
Programming paradigms are ways of thinking. Which one fits your mind best, which one will stretch it the most?