3 ms·
> The standard library is not always your friend I fully expected him to mention all the land mines of functions that don't check buffer sizes. But he raised
by asveikau 12y ago
> The standard library is not always your friend
I fully expected him to mention all the land mines of functions that don't check buffer sizes.
But he raised an important example of strcat being O(n).
And I feel like this is a lesson many people could apply to high level languages. For example, I can't count the number of times I've seen people not realize that their language's "remove this element from a vector" method is O(n) and they used it in a loop to get O(n^2). Then when asked about it if their background is high level languages they will have great difficulty reasoning about it, they will pull out BS justifications like I am sure the libraries or the compiler knows what to do here... A good programmer in any language should be able to look at a function signature and have a good intuition about what a reasonable implementation might be, and when to be skeptical about whether or not they would use it.
> To a large extent, the answer is: C is that way because reality is that way. C is a low-level language, which means that the way things are done in C is very similar to the way they're done by the computer itself.
This is probably the one thing I wish the C-haters understood better. Reality has a very anti-GC, pro-pointer bias. These are not arbitrary decisions. Some part of the system needs to work this way. And if we want to continue to have nice things, we need programmers who can competently reason about these layers. I can't imagine that changing anytime soon.
- adrusi 12y ago> This is probably the one thing I wish the C-haters understood better. Reality has a very anti-GC, pro-pointer bias. These are not arbitrary decisions. Some part of the system needs to work this way. I don't know how many of the "C-haters" actually hate C-the-language because it's too low level, or if they hate the fact that C is used in many cases where a higher level language would be appropriate. It's definitely not reasonable to assert that C is too low level for writing an OS kernel, but when people argue that software like rhythmbox, for example, ought to be written in something a bit higher level, there's some merit. A lot of projects use C just because it's an OK choice that a lot of people are familiar with and few people will have strong objections to.
- deleted 12y ago[deleted]
- asveikau 12y ago> C is anti-GC because it hides the aspects of the machine which are needed to implement it, Otherwise known as it hides reality. I read most of what you say as in agreement with what I am saying. Maybe some context got lost somewhere? I never said C exposes all of what you can do machine code, or that it doesn't add some amount of abstraction that might seem odd (the article mentions integer overflow behavior), just that the particular areas of pointers and lack of GC are fundamental to how the machine works.