Coupling and cohesion

Coupling Loose: You and the guy at the convenience store. You communicate through a well-defined protocol to achieve your respective goals – you pay money, he lets you walk out with the bag of Cheetos. Either one of you can be replaced without disrupting the system. Tight: You and your wife. Cohesion Low: The convenience … Read more

How to program a fractal?

Programming the Mandelbrot is easy. My quick-n-dirty code is below (not guaranteed to be bug-free, but a good outline). Here’s the outline: The Mandelbrot-set lies in the Complex-grid completely within a circle with radius 2. So, start by scanning every point in that rectangular area. Each point represents a Complex number (x + yi). Iterate … Read more

The recognizing power of “modern” regexes

Pattern Recursion With recursive patterns, you have a form of recursive descent matching. This is fine for a variety of problems, but once you want to actually do recursive descent parsing, you need to insert capture groups here and there, and it is awkward to recover the full parse structure in this way. Damian Conway’s … Read more

“const correctness” in C#

I’ve come across this issue a lot of times too and ended up using interfaces. I think it’s important to drop the idea that C# is any form, or even an evolution of C++. They’re two different languages that share almost the same syntax. I usually express ‘const correctness’ in C# by defining a read-only … Read more

Is the C99 preprocessor Turing complete?

Well macros don’t directly expand recursively, but there are ways we can work around this. The easiest way of doing recursion in the preprocessor is to use a deferred expression. A deferred expression is an expression that requires more scans to fully expand: #define EMPTY() #define DEFER(id) id EMPTY() #define OBSTRUCT(…) __VA_ARGS__ DEFER(EMPTY)() #define EXPAND(…) … Read more

Difference between user-level and kernel-supported threads?

Edit: The question was a little confusing, so I’m answering it two different ways. OS-level threads vs Green Threads For clarity, I usually say “OS-level threads” or “native threads” instead of “Kernel-level threads” (which I confused with “kernel threads” in my original answer below.) OS-level threads are created and managed by the OS. Most languages … Read more