5 ms·
Comments like these seem to have the underlying idea that C somehow explains how things work. It doesn't. It doesn't explain at all. It's only an abstraction am
by zxcdw 14y ago
Comments like these seem to have the underlying idea that C somehow explains how things work. It doesn't. It doesn't explain at all. It's only an abstraction among the others - granted, it's a lower level abstraction.
To understand how a computer works when it executes a program, accesses some data, writes to a disk, spawns a process and forks it, then kills the child after a certain interrupt can pretty much only be learned by learning assembly and some hardware and OS-related literature. Of course, for most programmers(let alone people in general) this is nearly useless information today. It's obsolete. And that's good.
But what C teaches you about how "things are under the hood", is just a leaky abstraction. C doesn't care about such low-level things because they are implementation details. Standard C could be ran by pen and paper just as well as on a computer. It's a "black box". Takes input and produces output according to the standard.
Frankly, the only "low-level" thing C has over e.g. Java is that most domains in which C is used are working close to the hardware and it runs on "the real hard machine". With C, in it's modern domains, you are exposed to these "low-level" details, not because of C, but because of the domain. With many other languages the user doesn't have to deal with such problems because of the problem domain is different.
- eliben 14y agoOf course C doesn't "explain" how things work. C is a language, it doesn't explain anything. However, when you write and read real-life C code, you have a chance to learn how software works under the hood much better than with higher-level languages. The low-level rigid type system makes you see how data structures are really laid out. Pointers and direct memory addressing makes you realize how memory is really managed, the real meaning of passing things by value and by reference, and many more things.
- RodgerTheGreat 14y agoWhat if I want to know how registers are used and allocated in a program? Most C compilers ignore "register" annotations, and with good reason- they hamstring the compiler's ability to optimize, which is usually a completely opaque process from the programmer's point of view in the first place. Why have a type system that includes implicit coercions between types, sometimes with different internal representations? (Just imagine an int promoting to a float.) Doesn't that obscure the "real meaning" of the program, or is it merely a detail you find uninteresting? C is not the only language that makes these low-level concepts accessible, and C does not represent the "floor" with respect to making the behavior of hardware explicit. If what you're actually getting at is that C is the most popular language today that exposes all of those things, it sounds less convincing- Systems languages cannot advance if we take C's position as given.
- swordswinger12 14y agoHaving really bizarre type conversions can allow for brilliant code in some cases - the Quake fast inverse sqrt function contains a float->int coercion, iirc.
- quesera 14y agoYou're right, C is the most popular language with the least amount of magic between you and assembly. It's a useful balance of abstractions on top of assembly without a total loss of the processor model. This isn't less convincing to me, I would never argue that someone learn C instead of all other languages. But I do believe that knowing C makes you a better programmer in all (current popular production) languages. Re: your point about systems programming not advancing...I didn't mean to imply that C was "perfect" (in the Latin sense, meaning "done, finished"), just that it's the best we have for many things. I do really like Go, and wish I could use it more, for non-personal projects.
- mccoyst 14y ago"low-level rigid type system" You've never written C.
- eliben 14y agoHmm... right, it was something with a C in it, but not sure what! Come on! Don't you have a constructive comment?
- stonemetal 14y agoHowever, when you write and read real-life C code, you have a chance to learn how software works under the hood much better than with higher-level languages. getchar(); //C STDIN.getc //Ruby getChar //Haskell System.in.read(); //java How do any of those show me how software works under the hood? In none of them do I have any clue how a character makes it from my terminal to my program. int* a; Teaches me nothing about caches, memory latency, NUMA etc. Hell, dereferences are even guarantied to read the same physical location in memory(just the same logical location.) struct stuff{ int a; int b; }; Doesn't teach me anything about memory layout. C assumes you are running on some hardware from the 70s, it doesn't know about virtual memory, address spaces, memory pages, NUMA, ram with multiple channels, the no execute bit, GPGPU programming. The only thing C has going for it is simplicity.
- kabdib 14y ago> The only thing C has going for it is simplicity. But it's an interesting /kind/ of simplicity. FORTRAN is simple, for instance. Yet we don't use it much any more. C is simple enough to not make you go bananas trying to learn the language [C++], but rich enough that you don't go bananas solving large, interesting problems [assembly]. It pretty much nailed the uncanny valley of just complex enough. It's a bit creaky. It desperately needs namespaces. I'm on the fence about memory models (this is a platform thing, in my mind), and definitely Do Not Want threads jammed into the language. I would love a decent macro language, but that's probably a decade-long debate (if what happened in the Scheme community is any indication). I would love a compilation system that didn't suck [yes, macros and a Go-like build system probably don't mix well]. I've been writing C for over 30 years. I plan to keep writing it for another 20. The unscientific, neat thing about C is that it's /fun/. I know this doesn't go over well with standards types and cow-orkers who feel the urge to override operator = and take dependencies on Koenig lookup all the time, but C has a charm that other, similar languages have been unable to capture.
- gaius 14y agoFORTRAN is simple, for instance. Yet we don't use it much any more. Computing is like an iceberg, with the web being the bit above the surface. rich enough that you don't go bananas solving large, interesting problems [assembly] Two words: macro assembler. It may surprise you to know that not that long ago, sophisticated GUI apps were written in assembly language (in fact the IDE I use on my ST, Devpac, was written in assembly, and it's everything you would expect of a modern IDE - editor, compiler, debugger, etc - running under GEM). Many games were written in pure ASM.
- quesera 14y ago> To understand how a computer works when it executes a program, accesses some data, writes to a disk, spawns a process and forks it, then kills the child after a certain interrupt can pretty much only be learned by learning assembly and some hardware and OS-related literature. Well yes, but you're talking about library code there. Your code, which links in libraries, will never fully describe those libraries. But that library code was very likely written in C...so...
- dpeck 14y ago"Of course, for most programmers(let alone people in general) this is nearly useless information today. It's obsolete. And that's good." I'm not sure how you can say that knowledge of assembly/hardware is obsolete. Perhaps unneeded for tasks that most programmers have in our hip new ad-driven world, but someone still has to understand and write the code that runs the code that eventually puts the cat-based meme on your screen. Engineers seldom use calculus, but they used derived functions every day. The same applies to programming, everyone who programs should be exposed to the low level innards enough to at least take the magic away and have a basic concept of what a computer actually does. You'll be better for it.
- amcintyre 14y agoOf course, for most programmers(let alone people in general) this is nearly useless information today. It's obsolete. And that's good. Damn right it's good--for me--that most programmers think low-level programming/machine knowledge is obsolete. I'm pretty certain it means I'll never want for a (good) job as long as I can still think and move enough to edit code.
- haberman 14y ago> To understand how a computer works when it executes a program, accesses some data, writes to a disk, spawns a process and forks it, then kills the child after a certain interrupt can pretty much only be learned by learning assembly and some hardware and OS-related literature. That's funny, because 97% of the Linux kernel (the code that implements the things you mentioned) is written in C. I think you're getting confused by the fact that C has a standard library, so it's true that you don't have to write process spawning yourself. But the standard library is written mostly in C and calls into an OS that is written mostly in C. So C's computational model can indeed explain how low-level things work. The C standard even defines a "freestanding implementation," which is a C platform that has no access to an OS. So C-the-language can work without any OS at all, and without any runtime/interpreter that is filling the role of a traditional OS. Very few languages can say that, and indeed it's the reason why it makes sense to develop an OS in the language. To write an OS in a language that requires an OS begs the question.
- philh 14y agoI personally learned a lot more about how computers work from assembly than from C. One example: C programmers talk about "the stack", but it's an implementation detail, you can learn C without knowing what the stack really is. Assembly will teach you. As for process spawning, I/O, etc.: it might be that C is just as good as assembly for those, but I would be surprised if either was sufficient. Presumably that's where "hardware and OS-related literature" comes in.
- agumonkey 14y agoI've seen a fair share of lispers and clojurians blogging about compiled assembly, cpu cycles and cache usage of their ludicrously high-level macro-expanded DSLs. As people said already, C semantics is closer to the metal but that's about it, it's just one small language (not insulting) It's not reality, even assembly isn't. In any language, doing full stack design will get you close to reality.
- aiscott 14y agoI agree, C doesn't itself explain "how things work." But I think the process of learning C can (but won't always) lead to a pretty good understanding of how things work. I'm admittedly not a very good programmer, but I love the ideas of programming, and it's probably my second best creative outlet. I just struggle with some of the higher level concepts... it seems the more abstraction that goes on, the harder I find it to understand. Closures, for example. Sometimes I think I understand them, and sometimes I don't. I work in hardware design, and perhaps it is only because it is what is familiar to me, but it seems to be a very concrete way of thinking. Certainly not just because it's physical, but that probably helps too. As far as programming, I think C and Assembly have to be my two favorite programming languages. By that I mean real C, not c++ or objective-c or whatever. And a "purer" form of assembly on simpler CPU designs. Assembly is great because the operations are so simple. Move, Load, Store, Add, etc... My problem solving has always been to take the problem and break it down into smaller problems, and Assembly seems to be an extreme view of that. Assembly is naturally close to the hardware. (Although how close varies with CPU design and can be argued in light of micro-ops, caching, out of order execution, etc...) Vanilla C translates so directly to Assembly, that if you know Assembly, it's easy to envision what Assembly could be generated by the code you are writing in C. If you have an understanding of the hardware involved, there just isn't very much mystery to C. As such, it can provide a springboard to understanding higher levels of abstraction.