What is a sound programming language?

Taken from Dart’s language guide What is soundness? Soundness is about ensuring your program can’t get into certain invalid states. A sound type system means you can never get into a state where an expression evaluates to a value that doesn’t match the expression’s static type. For example, if an expression’s static type is String, … Read more

What does “Box

Let’s decompose it one-by-one. Box Box<T> is a pointer to heap-allocated T. We use it here because trait objects can only exist behind pointers. Trait objects In Box<Fn() + Send + ‘static>, Fn() + Send + ‘static is a trait object type. In future, it will be written Box<dyn (Fn() + Send + ‘static)> to … Read more

Python: Test if value can be converted to an int in a list comprehension

If you only deal with integers, you can use str.isdigit(): Return true if all characters in the string are digits and there is at least one character, false otherwise. [row for row in listOfLists if row[x].isdigit()] Or if negative integers are possible (but should be allowed): row[x].lstrip(‘-‘).isdigit() And of course this all works only if … Read more

Why can’t Rust infer the resulting type of Iterator::sum?

The way sum is defined, the return value is open-ended; more than one type can implement the trait Sum<i32>. Here’s an example where different types for a are used, both of which compile: #[derive(Clone, Copy)] struct Summer { s: isize, } impl Summer { fn pow(&self, p: isize) { println!(“pow({})”, p); } } impl std::iter::Sum<i32> … Read more

GUID / UUID type in typescript

You could create a wrapper around a string and pass that around: class GUID { private str: string; constructor(str?: string) { this.str = str || GUID.getNewGUIDString(); } toString() { return this.str; } private static getNewGUIDString() { // your favourite guid generation function could go here // ex: http://stackoverflow.com/a/8809472/188246 let d = new Date().getTime(); if (window.performance … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)