Linked by Eugenia Loli on Mon 10th Oct 2005 16:48 UTC, submitted by Shlomi Fish
General Development Shlomi Fish has written a new essay titled "When C is the Best? (Tool for the Job)". Its theme is giving several reasons (besides high speed and low memory consumption) why some code should still be written in C.
Thread beginning with comment 42704
To read all comments associated with this story, please click here.
Libraries
by ma_d on Mon 10th Oct 2005 19:08 UTC
ma_d
Member since:
2005-06-29

I'm not sure why one would use anything but c/c++ for libraries... Simply for ease of portability to other languages, but also as he mentioned minimum nested dependencies (besides, the best high level languages provide their own, fairly complete, libraries; and use of other libraries is probably by advanced programs or niche programs).

IMO, he's totally wrong on memory consumption. A well written program in anything, including java, can be just fine on memory consumption. And when you compare it to a graphical (obviously, console programs are a different bear) program in c you'll find similar memory consumption (because the GUI toolkit will suck RAM up). Of course, embedded code is another story; if Sun had its way your embedded code would be Java running on a Java machine ;) .
Speed is also a load as well. For most programs, a loss factor of 100% is not noticeable (your GUI toolkit will suck far more speed than most of your program). The little bit of benchmarking I've done indicates that Java is VERY similar to c for arithmetic performance... Python is about 30 times slower (I still prefer the language though).


People discount c as a waste of time too often IMO. It may not be faster or less memory intensive. But in the end, all these quick fix things to fast productivity seem to end up producing buggy code: "Oh, I have a garbage collector so I can write: strcat(z,strcat(v,strcat(x,y))) (a modified strcat that returns the pointer to the '' and allocates memory)." Then they do that, and it's not wrong; but they end up getting sloppy and not going back over their logic once they've written it.
Don't get me wrong: Garbage collection is great, because it's plenty efficient and saves you something like 2% of your time; and moreover, it further narrows down every problem you have (you know it wasn't that you freed to early) which probably does save significant time.

I don't think the cost of writing something in c verse another language is that great (at least not for a medium sized program). But I do hate it when people use pre-processor macros for things other than constants and compile decisions!

I think the best thing is almost invariably some combination of languages. For example, write your program design in something like python, and all your work code (support libraries) in c... Then you can easily change major program logic, and have fast localized c code for calculations!

Reply Score: 0