Kenny's Blog

03 Nov 2015

Some C Stuff

I never really appreciated C for what it was until now. It took me 5 years from my first programming course to appreciate it for what it was. C is a very pure programming language; it comes with no frills, bells, or whistles. I’m glad I had the opportunity to become exposed to C early on.

Not to say I dislike all other languages. Java was the second language I learned, ruby was the third and python followed after that. I throughly enjoyed learning all of them. But the influence I got from C followed the other languages; Java’s syntax (besides the object orientation), of course, is very C-like.

I just wanted to shared some of the recent thoughts I had regarding C.

C in Javascript?

More recently, however, I’ve enjoyed learning and working with Javascript. The community is large, and the functional programming features are still very novel (to me) and very interesting.

http://javascriptissexy.com/understand-javascript-callback-functions-and-use-them/ in particular were very interesting since I’d never gotten the chance to use callbacks outside of GUI functions. It took me a while to realize it, but callbacks can be implemented in C!

It might sound simple and trivial to some but this is a concept that takes some experience to understand. Some people get this experience early on, and some don’t. Callbacks are implemented in C by using function pointers! (http://stackoverflow.com/questions/142789/what-is-a-callback-in-c-and-how-are-they-implemented)

void populate_array(int *array, size_t arraySize, int (*getNextValue)(void))
    for (size_t i=0; i<arraySize; i++)
        array[i] = getNextValue();

int getNextRandomValue(void)
    return rand();

int main(void)
    int myarray[10];
    populate_array(myarray, 10, getNextRandomValue);

So the concept has transferred over the Javascript and is now available as a high level construct instead of the low level implementation you see in C with pointers.

The Language of Implementation

There is a lot of opinion out there on the interwebs; opinions about what language to use, why you should use it and why it’s better to start off with this particular language. Granted, starting with C is hard.

It’s a very pure language because it’s the language of implementation. Other languages have libraries built in C; they’re using C as a low level construct to implement the details. Someone, somewhere needs to worry about this. It used to be that assembly programmers worried about the implementation details, now we have C for that.

Out of all the other languages I’ve tried out, none of them are quite pure implementation languages. Java attempts to be that, but lacks pointers and has a ton of libraries. You can consider Java to be a high level contruction language. You use it to piece together chunks of code and make something.

It is what it is

So if you consider C for what it is, it’s not a bad programming language to start with. It gives you a huge survey of what the guts of programming looks like. And just like other languages, it is what it is.