[ProgClub list] Memory management in C

John Elliot jj5 at progclub.org
Sun Oct 2 03:59:51 AEDT 2011


On 1/10/2011 8:00 PM, Asher Glynn wrote:
>> I'm learning more about C, and the more I learn the more I'm convinced that
>> C programmers just like making life difficult for themselves. There really
>> isn't anything that great about C. It's full of bugs and hacks, and it is
>> really showing its age. I can't imagine recommending the language to anyone.
>
> Never going to argue with that, unless they are doing Unix development. I
> bite though - what _would_ you recommend?

What would I recommend, for what? I guess I wouldn't argue with you or 
jedd that if you're going to be writing UNIX you're going to be wanting C!

I'm fairly enamoured with C# on Mono. I think that's going to be my 
language/platform of choice. I say "going to be", because at the moment 
I'm pretty heavily involved with writing web apps in PHP. I'm happy 
writing web apps in PHP, by the way. Although it's all quite new to me, 
I'm enjoying the experience. PHP is a little brain-dead in parts, but 
it's functional. I have so much planned to do in PHP that I might not be 
finished for a few years. :P

Unfortunately C# on Mono has a really sorry story for UI development in 
its buggy WinForms implementation. I think I'm going to stick with 
web-based UIs for the foreseeable future. I'd like to get back to 
writing web apps in C# (on Mono), but I'm a long way from there at the 
moment and there's no reason to believe I'll catch up any time soon.

I think my current application is a great example of a system that 
*shouldn't* be written in C. I think if you're going to be doing the 
kind of "batch mode" "network sockets" "string processing" programming 
that I'm doing that you're better off picking a safer language. I guess 
python would be the typical recommendation, although there are others 
such as Thomas mentioned, e.g. OCaml.

>> Although, there is something mystical (and powerful) about it.
>
> I think its aged remarkably well - what hasn't aged well is more the bits at
> the edge (APIs etc) and some of the assumptions about how it'd be used. It
> dates back to a time where the competition was assembler, not high level
> languages. Its also interesting to note the amount of C that isn't actually
> in C as such - the compiler directives.

Yeah, good point. I've always been a little intimidated by how much you 
need to know to compile a C program.

Coming from a statically typed language like C# (or Java) into C is a 
scary journey. You lose all the safety that you've come to know and 
love, and this impacts heavily on the kind of design decisions you can make.

I think the absolute failure of C is its approach to strings, it should 
have standardised a string structure that included the string length. 
And it probably should have done the same for arrays and included index 
bounds checking.

I think I'm probably going to implement a FuckedString structure for my 
strings in C like the one that Spolsky dumps on.



More information about the list mailing list