strager.net

When exporting to PNG, gnuplot ignores the transparency of objects by default:

set term png size 1280, 1024
set output "plot2.png"

To fix this, set the truecolor option:

set term png size 1280, 1024 truecolor
set output "plot2.png"

Idea for a less ambiguous syntax for C++ forwarding references (i.e. universal references):

template<class T>
auto begin2(decltype(T) x)  // C++17: auto begin2(T&& x)
{
  return std::forward<T>(x);
}

In C++, initializing a const reference automatic variable might make a reference to an unnamed temporary:

struct s {
    int b: 6;
};
void f() {
    s my_s;
    my_s.b = 6;
    const int& b = my_s.b; // Copy!
    assert(b == 6);

    my_s.b += 1;
    assert(my_s.b == 7);
    // b was a copy to my_s.b (and not a reference to
    // my_s.b) and remains unchanged.
    assert(b == 6);
}
void g() {
    char a[] = "hello world";
    char* cs = a;
    const std::string& s = cs; // Copy!
    assert(s == "hello world");

    a[0] = 'y';
    assert(strcmp(cs, "yello world") == 0);
    // s was a copy of cs (not a reference to cs) and
    // remains unchanged.
    assert(s == "hello world");
}

I think this behavior is familiar for function parameters, but is fragile for automatic variables.

Tenative conclusion: avoid const reference automatic variables.

Follow-up questions for further research:

Possible solutions:

The extract method refactoring is symmetrical to the inline function optimization. What other symmetries are there between refactoring and optimization?

Brainstorm of refactorings which relate to optimizations
Refactoring Optimization
Extract function
Inline function
Inline function
Extract variable Common sub-expression elimination
Inline variable Constant folding
Remove dead code Dead code elimination
Slide statements Loop-invariant code motion
Split loop Loop fusion
Loop fission
Loop peeling
Loop un-switching
Replace conditional with polymorphism Devirtualization
Replace control flag with break Dead store elimination
Replace temp with query Common sub-expression elimination
Introduce parameter object Scalar replacement of aggregates

What are some overheads for different operating system kernel implementation techniques?

Overheads of OS kernels
Traditional ring0/ring3 kernel ring0 single address-space ring0 machine code sandbox (e.g. NaCl) ring0 virtual machine code sandbox (e.g. PNaCl, WebAssembly)
I/O system call context switch function call function call (none; inlinable)
Load code (none) (none) overhead overhead
Access memory (none) (none) overhead overhead
Jump indirect (none) (none) overhead overhead
Switch thread context switch (none) (none) (none)

Remove elements from the end of a JavaScript array by manipulating its length property:

eggs = ['a', 'b', 'c', 'd'];
eggs.length -= 1;
console.log(eggs); // [ 'a', 'b', 'c' ]

Idea for a tutorial for teaching programming to beginners:

  1. Learn I/O programming with no logic. Maybe CLI or Arduino.
  2. Learn logic programming with no I/O. Create tic-tac-toe. Code for a GUI is provided for you.
  3. Swap the pre-made GUI of the tic-tac-toe program with an Arduino-based UI (also pre-made).

The goal of this tutorial is to encourage learners to think of logic and I/O as separate things. The two components can be developed independently. Logic can be decoupled from its user-visible interface.