arnero said:
Sorry, it took me some time, but bitmask is procedural programming callback is functional programming calling a method would be OOP.
huh?
bitmasks have nothing to do with the type of programming. bit-twiddling (where bitmasks is just one aspect of) is a different view on integer numbers. The common view on integer numbers is that you can store an integer value in it, and add/subtract etc them. You can also see an integer number as eg 32 separate bits, ie you don't care about the numeric value, you only care which of the 32 bits is on or off. This way of looking gives you a set of up to 32 values (or 64 if you pick a longer integer number). The nice property of this view is that bit operations are very very very fast (compared with generic sets) and take very little space. So the next time you have loads of very small sets where the elements can be simply mapped onto a range of 0..31 (or whatever size integer you have), consider using integer as a set of bits.
functional programming is when you don't have assignments. You only have functions and parameters, but no “=” to give a variable a new value. I know it sounds weird ?
An example:
def fact(x):
if x == 0:
return 1
else:
return x * fact(x - 1)
See? no assignment and you can still compute a factorial. It takes a little getting used to, but the nice thing of functional programming is that variables never change value within one function call. The value of x in the last line is the same as when the function started, always. For complicated functions, that is a very useful property.
A callback is a notification that something has happened or something has been decided. It can be used in procedural (or imperative) programming as well. A common example is event notifications.
A method is indeed an OOP concept, but you don't need an OOP language to do OOP, ie you can code OOP style in C. The core idea of OOP is “smart data”, ie data that has some functions associated to it so you can ask it for information (eg mylist.size()), or ask it to do something (eg mylist.append(element)). You can do this in C too.
struct List mylist; /* my list data */
int size(struct List *lp) { /* compute and return length of *lp */ }
void append(struct List *lp, int element) { /* append ‘element’ to *lp */ }
// and now you can write
size(&mylist);
append(&mylist, element);
A bit more cluttered than a proper OOP language, but the idea of data with a bunch of functions associated to it is there.