4 ms·
Learn C - Just the basics, if you don't already. I think it's valuable to understand why everyone complains about it. When you say just the basics, what are yo
by SnowingXIV 10y ago
Learn C - Just the basics, if you don't already. I think it's valuable to understand why everyone complains about it.
When you say just the basics, what are you referring to? Syntax? Pointers? Dealing with garbage? I've got a vague idea about it, but never had to really do anything with it so I feel now is a good time to mess around with it.
Great read though, always a pleasure seeing James mentioned (someone that definitely inspires me).
- deleted 10y ago[deleted]
- anatoly 10y agoI think most advice to "learn C" really aims to get you to learn how things work closer to the metal. What actually becomes of your code and data, broadly speaking, once your high-level language's interpreter or compiler have had their way with them. So things like: - viewing primitive objects, structs and arrays as blobs of bytes arranged between address X and address Y - a pointer as an address of that blob. Understanding what it means to copy that blob vs. to pass around the pointer: calling by value/reference not in terms of the semantic effect, but in terms of what happens underneath. - the stack and how it's typically used, esp. in recursion. Local vars vs. heap-allocated vars. How control flow leaves its trace on the stack. How arguments are passed and return values are returned. - complex data objects viewed as blobs of memory pointing to each other vs. pointers. Concept of "owning" such a blob and how ownership is passed. Understanding how your language's runtime keeps track of the blobs if you don't have to, and what are common pitfalls. - clear understanding of the difference between int8, int32, int64. Strings as null-terminated or counted arrays. Bitops. "Learn C" is just a useful way to force you to internalize all of the above, because you can't properly "learn C" without doing that. But it's the above that helps you back in your favorite language. That, and perhaps the fact that C gives you a feeling what it's like when you can look at a line of source code and understand immediately what happens in the machine (broadly) when executing it. No hidden effects. C++ doesn't have that (constructors you don't know about when looking at the line, exceptions etc.) That "local clarity" isn't the most important thing in the world, but if you feel and appreciate it, perhaps you'll strive for local clarity back in your favorite language, too.
- scarlac 10y agoMy personal recommendation would be to learn and understand how pointers work. In the years I spent dealing with C and C++ I can trace many of my major learnings back to how pointers work. You can't really understand pointers until you understand how memory is managed, including all the pitfalls and performance tricks that comes along.
- metaphorm 10y ago> Syntax? yes, because so many other languages have copied that syntax in superficial ways. being familiar with C syntax (ugly as it is, way too much punctuation imo) automatically makes you able to comfortably read Java, JavaScript (sort of), PHP, C#, etc. it's kind of a shame because aesthetically speaking its so full of bad choices, but it is still very influential. > Pointers? yes, absolutely this. most memory managed languages don't give you pointers at all and let the GC and objects implementation handle that completely. however, understanding the details of reference, dereference, and memory addressing is good for developing insight into how things are implemented at a lower level and what the performance characteristics of those implementations will be. > Dealing with garbage? C is a manual memory management language. Doesn't even have smart pointers or optional GC. To avoid memory leaks you have to be extremely dilligent about error handling and cleaning up/deallocating on every possible program branch. this will really hammer home a few points about rigor that are easy to gloss over in memory managed languages. however, it's a pain in the butt and I'm really really glad I don't have to do manual memory management on a daily basis. still, learning a bit about this has made me a lot more sensitive to possible memory leaks that turn up even in higher level languages.