5 ms·
Personally I take a different view: learn a high-level language, use it to study computer science, and if you feel like writing some low-level code go ahead an
by betterunix 13y ago
Personally I take a different view: learn a high-level language, use it to study computer science, and if you feel like writing some low-level code go ahead and learn C (though even then, you could probably do better by bootstrapping a compiler for your favorite high-level language and adding some extensions for low-level operations). C is not the best or even a particularly good language to try to learn abstract CS concepts with, professors who choose it are needlessly stressing out their students, and at the end of the day you can learn a lot more about algorithms and data structures when you are not busy worrying about pointers or trying to avoid the things that "everyone knows to avoid" (except people keep failing to do so).
I say this as someone who watched the catastrophic results of trying to use C++ as a language to teach data structures. It is far more important to be able to think abstractly than to know how to deal with pointers.
- banachtarski 13y agoThe thing that makes C a good candidate is that it's a very very small language. Yes there are plenty of strange quirks that the experts need to deal with but you can come up with an elegant and compact implementation of every standard data structure. High level languages tend to favor one data structure over another. Starting with those languages can give students the "hammer syndrome" w.r.t. that structure.
- anaphor 13y agoI see this a lot with functional programmers and linked lists. Yeah you can derive a lot of data structures from a list, but sometimes it's like putting a square peg into a round hole, and a custom data structure would be more efficient.
- nbouscal 13y agoAs far as I can tell, only hobbyist functional programmers try to make everything work with linked lists. Most people who write in functional languages professionally know to use the correct data structure for the job, and how to do so (the most common educational resource being Okasaki's Purely Functional Data Structures).
- betterunix 13y agoScheme is a small language as well, and it is worlds better for teach abstract concepts. You can write far more elegant and compact implementations of data structures in Scheme than you can write with C. As for preferring one data structure over another, C does that as well: arrays are the only data structure with first-class support.
- erichocean 13y agoScheme is a small language as well, and it is worlds better for teach abstract concepts. I've heard this claim many, many times, but for me, I find Scheme (and Haskell, for that matter) impossible to work with. I love what Scheme and Haskell do in theory, but in practice, I find them unusable for those things. With Scheme and Haskell, I find I'm always trying to figure out how I should make the compiler happy, vs. taking an abstract concept that I understand well and just implementing it, which is something I find easy to do with C. But I also suck at math, and my assumption is that for people who don't suck at math, Haskell and Scheme and all the others are probably easier, and that makes sense to me.
- smorrow 13y agoFunctions don't see arrays, functions see pointers, even if you passed an array. The sizeof a passed array is the sizeof a pointer. So they're not first class.
- pjmlp 13y ago> The thing that makes C a good candidate is that it's a very very small language. Modula-2 and Oberon are also quite small.
- knappador 13y agoC is about as close to teaching the mechanics of the computer as you can get while staying portable. I've found that my ISA knowledge "just works" on any architecture though, so I would feel okay teaching something like C-- or LLVM IR along with an arbitrary ISA to allow the mind to have a lowest-common denominator. CS is to CE as Chemistry is to Physics. Chemistry lets you do a lot with less, but Physics is where you understand a lot and have the capability to do things that can't be introspected using only a knowledge of Chemistry. The guts of CS are a great place to expand after a certain point.
- betterunix 13y ago"C is about as close to teaching the mechanics of the computer as you can get while staying portable" Why is it important to teach the underlying mechanics of a computer in a data structures course, or an algorithms course, or really anything beyond OS or computer architecture courses (and perhaps a compilers course)? The reality is that the way computers work "under the hood" is counterintuitive in an extreme sense. Pointers are a counterintuitive abstraction. Fixed-width arithmetic is counterintuitive, as is having integer division always round down, as is using floating pointer numbers to represent fractions. Yes, eventually a CS student should learn about these things -- but an introductory course is the wrong place, as is basically anything that deals with purely abstract notions (data structures, algorithms, cryptography, etc.).
- knappador 13y ago"The guts of CS are a great place to expand after a certain point." "...an introductory course is the wrong place" I'm glad we're in agreement.
- betterunix 13y agoAh, sorry, I misunderstood what you meant there ;)
- ForHackernews 13y agoI agree with you except for your use of cryptography as an example. In anything dealing with security, unfortunately the nitty-gritty implementation details wind up mattering as much (if not more) than the theoretical portion. Most cases of crypto failing are not examples where the algorithm is flawed (or outdated), but rather where the implementation is weak. Any course on crypto needs to address both algorithms in the abstract and the particularities of how they're implemented in the real world.
- soup10 13y agoC++ and C are completely different beasts. C is an elegant clean small language with few distracting elements, making it very suitable for a teaching language. C++ is a grotesquerie more suitable for a carnival horror show than something you want to introduce to new programmers. Unfortunately at some point, teaching OOP became all the rage in schools, and so C++ is chosen instead. That's a mistake, Java or C# should be used for teaching OOP, C should be used to teach data structures and at least some algorithms. Without hands on memory allocation, you're not really getting a full understanding of how data structures work.
- dmunoz 13y ago> C++ is a grotesquerie more suitable for a carnival horror show than something you want to introduce to new programmers. I bought into this previously after hearing it constantly repeated, but don't anymore. Your point about OOP is fair, but I think there is a sane subset of C++ that is incredibly useful for teaching new programmers. One thing to be avoided is needless OOP hierarchies. User-defined types are an incredibly powerful abstraction, and makes certain programming tasks look and feel extremely natural. If you listen to Stroustrup talk about C++, this is what he tends to highlights about C++, not the advanced features. Those can come later. C++ has plenty of warts, and I dislike certain parts of it as much as its detractors, but C++ is still an awesome language.
- pjmlp 13y agoI think the same way. Nowadays I jump between JVM and .NET ecosystems. For me C was just one year transition between Turbo Pascal and C++, back in the mid-90's. Only used it for university assigments and on my first job. Otherwise when the option is reduced to C vs C++, I always pick C++. For me, C was too litle when comparing with what Turbo Pascal offered me. Luckly I discovered C++ shortly after learning C.
- betterunix 13y ago"C++ is a grotesquerie more suitable for a carnival horror show than something you want to introduce to new programmers." In my experience TAing an undergrad course that used C++, almost all of the things that left students scratching their heads were things that are present in C. No garbage collector, no built-in way to determine array sizes at runtime, no way to determine if a pointer has already been deallocated, no requirement that non-void functions actually return a value on all control paths, etc. The worst thing C++ does is to amplify these problems (particularly that last one -- yes, I know, use -Wall, but someone who is just starting to use a language would not know that, and having to teach compiler flags is an even worse distraction from the subject matter of the course). Really the problem is not language size at all. Python is a big language too, but it does not have the above problems. Common Lisp is just as big as C++ (in terms of the number of pages in the standard), yet these are not problems Lispers have. Scheme is a small language, like C, yet the elegance and expressive power of Scheme is on a completely different level from C. The problem is that the few abstractions C presents are hard to deal with, especially for beginners, and the abstractions that C could present are sorely missed. Even the abstractions C presents are unreliable, with loads of undefined behavior and plenty of ways to break the abstractions. Really, the fact that real-world C programmers have to pick a subset of the language and enforce various style standards and coding conventions speaks volumes about the suitability of C for beginners. If we were going to require students to use a specific subset of C, why not just write a compiler for that subset and use that to teach? The answer is pretty clear: if we were going to write a compiler for a new language that was suitable for teaching students, we would write something better. Why bother when we already have better languages to choose from? Save C for the OS course, and only as long as it remains relevant there.
- RogerL 13y agoSomehow we managed to do so in the 80s. Classes at the time were a mix of C, Pascal, and Lisp (at my school, YMMV). Certainly all the chances for getting pointers wrong made developing in C harder, at first. Even today I prefer to reach to Python to throw together some algorithm I am musing about. So I definitely acknowledge your point. But, I just don't see a way around it. Today I am refactoring code to make it stay in the cache better. Doing that is not an exercise in pointless efficiency; it is the difference between the program being usable or not (it is a real time system). I contemplated compiling to assembly and eyeballing it, but a few sessions with the profiler got me the answers I needed. But to do this I had to keep in mind the pipeline architecture (cost of if statements if you don't get the branch prediction), the size of the cache, the cost of function calls, etc. I recognize there are careers out there where you never have to touch that stuff. You write SQL calls and use a 4GL language, and so on. But what happens when your SQL runs to slow? Do you randomly vary the various server settings until it seems to run better, or do you actually understand (say) the cost/benefit of making the cache for the indexes larger? How would you talk to a piece of hardware your boss drops in your office? How..., well, you get the idea. None of that is advocating building an entire 4 year curriculum solely on C/C++. Certainly it makes sense to do the algorithms class largely in a language like Lisp or Python. But after a certain point if you want real performance you are in C, battling low level details, and I think that is as important, if not more important, than proving the O() complexity of Fibonacci heaps.