Is bit shifting O(1) or O(n)?

Some instruction sets are limited to one bit shift per instruction. And some instruction sets allow you to specify any number of bits to shift in one instruction, which usually takes one clock cycle on modern processors (modern being an intentionally vague word). See dan04’s answer about a barrel shifter, a circuit that shifts more … Read more

When a method has too many parameters? [closed]

There is no clear limit, but I am uncomfortable with more than 3-4 parameters. AFAIR Uncle Bob Martin in Clean Code recommends max 3. There are several refactorings to reduce the number of method parameters (see Working Effectively with Legacy Code, by Michael Feathers for details). These come to my mind: encapsulate many related parameters … Read more

The type system in Scala is Turing complete. Proof? Example? Benefits?

There is a blog post somewhere with a type-level implementation of the SKI combinator calculus, which is known to be Turing-complete. Turing-complete type systems have basically the same benefits and drawbacks that Turing-complete languages have: you can do anything, but you can prove very little. In particular, you cannot prove that you will actually eventually … Read more

Is “Out Of Memory” A Recoverable Error?

It really depends on what you’re building. It’s not entirely unreasonable for a webserver to fail one request/response pair but then keep on going for further requests. You’d have to be sure that the single failure didn’t have detrimental effects on the global state, however – that would be the tricky bit. Given that a … Read more

What does ‘foo’ really mean? [closed]

See: RFC 3092: Etymology of “Foo”, D. Eastlake 3rd et al. Quoting only the relevant definitions from that RFC for brevity: Used very generally as a sample name for absolutely anything, esp. programs and files (esp. scratch files). First on the standard list of metasyntactic variables used in syntax examples (bar, baz, qux, quux, corge, … Read more