What is the point of make_heap?

Your direct question would be well-answered by a class in algorithms and data structures. Heaps are used all over the place in algorithms in computer science. To quote from the make_heap function linked below, “a heap is a tree where each node links to values not greater than its own value.” While there are lots … Read more

What are practical guidelines for evaluating a language’s “Turing Completeness”?

You need some form of dynamic allocation construct (malloc ornew or cons will do) and either recursive functions or some other way of writing an infinite loop. If you have those and can do anything at all interesting, you’re almost certainly Turing-complete. The lambda calculus is equivalent in power to a Turing machine, and if … Read more

What is typestate?

Note: Typestate was dropped from Rust, only a limited version (tracking uninitialized and moved from variables) is left. See my note at the end. The motivation behind TypeState is that types are immutable, however some of their properties are dynamic, on a per variable basis. The idea is therefore to create simple predicates about a … Read more

Why doesn’t Scala have static members inside a class?

The O in OO stands for “Object”, not class. Being object-oriented is all about the objects, or the instances (if you prefer) Statics don’t belong to an object, they can’t be inherited, they don’t take part in polymorphism. Simply put, statics aren’t object-oriented. Scala, on the other hand, is object oriented. Far more so than … Read more

Why are await and async valid variable names?

Reserved keywords cannot be used as identifiers (variable names). Unlike most other special Javascript words (like those listed in the question, let, finally, …), await is not a reserved keyword, so using it as a variable name does not throw a SyntaxError. Why wasn’t it made into a reserved keyword when the new syntax came … Read more

New language on top of PHP?

The idea is definitely not stupid, especially if executed well. I like coffeescript a lot, but it has it’s approach has downsides as well. Debugging a coffeescript script still requires you read the generated Javascript code, which can be tedious, since you haven’t written it actually yourself. I’ve understood that Jeremy Ashkenas, the creator of … Read more

Why does Python’s itertools.permutations contain duplicates? (When the original list has duplicates)

I can’t speak for the designer of itertools.permutations (Raymond Hettinger), but it seems to me that there are a couple of points in favour of the design: First, if you used a next_permutation-style approach, then you’d be restricted to passing in objects that support a linear ordering. Whereas itertools.permutations provides permutations of any kind of … Read more

OptionalInt vs Optional

Java 8 introduced a whole lot dedicated to primitives. The reason is most likely that boxing primitives can create a lot of waste “boxes”. For example this OptionalInt optionalFirst = IntStream .range(0, 100) .filter(i -> i % 23 > 7) .findFirst(); Here, an Optional<Integer> as result would be inconsistent. Also methods like ifPresent(IntConsumer consumer) then … Read more

Why must I provide ‘operator ==’ when ‘operator ‘ is enough?

Why must I provide operator== when operator<=> is enough? Well, mainly because it’s not enough 🙂 Equality and ordering are different buckets when it comes time for C++ to rewrite your statements: Equality Ordering Primary == <=> Secondary != <, >, <=, >= Primary operators have the ability to be reversed, and secondary operators have … Read more

What is the operator “” in C++?

Those are user-defined literals. They allow you to create stuff like std::string, std::chrono::durations or any user defined type (you can make your own literals) in place: auto str = “Hello”s; // str is std::string(“Hello”) auto sec = 5s; // sec is 5 std::chrono::seconds A list of the literal-operators provided by the standard library and their … Read more

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