4 ms·
Coding algs and data structures in C lets you see how those things _actually work_ in the computer. A lot is hidden by the abstractions of higher-level language
by javert 14y ago
Coding algs and data structures in C lets you see how those things _actually work_ in the computer. A lot is hidden by the abstractions of higher-level languages.
In particular, I am thinking about pointers and memory management, but there are other things.
- robomartin 14y agoYup. Exactly why I think C is a great starting point. This is also why I think we have so much bloated code these days. Everything has to be an object with a pile of methods and properties, whether you need them or not. Meanwhile nobody seems to be able to figure out that you might be able to solve the problem with a simple lookup table and clean, fast C code. There was a blog post somewhere about exactly that example recently but I can't remember where I saw it. I wrote a GA in Objective-C because, well, I got lazy. Then, after seeing the dismal performance I got I re-coded it in C. It's been a couple of years but I think that the performance was hundreds of times faster than anything the optimized Objective-C code could achieve. The heavy bloated NS data types just don't cut it when it comes to raw performance. Someone who has only been exposed to OO languages simply has no clue as to what is happening when they are filling out the objects they are creating with all of those methods and properties or instantiating a pile of them.
- derleth 14y ago> This is also why I think we have so much bloated code these days. 'Bloat' is a snarl term. It's meaningless. It literally means nothing, except to express negative emotion. > I wrote a GA in Objective-C because, well, I got lazy. Then, after seeing the dismal performance I got I re-coded it in C. Did you try any other algorithms? Any other data structures? Simply picking a new language is laziness.
- robomartin 14y agoNo, it's not a snarl term. It's very real. When dealing win an array is 400 times slower in a "modern OO language" then in raw C, well, the code id fucking bloated. When you can use a simple data structure and some code to solve a problem and, instead, write an object with a pile of properties and methods because, well, that's all you know, that's bloated code. Of course there are lots of places where OO makes absolute sense. And the fat and slow code is the compromise you might have to make. That's the way it goes. With regards to my GA example. No, I had to implement a GA. That's what was required to even attempt to solve the problem at hand. Later on we used it to train a NN, which made the ultimate solution faster. But, the GA was required. There was no way around it and Objective-C was such a an absolute pig at it that it made it unusable. > Simply picking a new language is laziness See, there's the difference. I started programming at a very low level and have experienced programming languages and approaches above that, from C, to C++, Forth, Lisp, APL, Python, Java, etc. I have even done extensive hardware design with reconfigurable hardware like PLD, PLA's and FPGA's using Verilog/VHDL. I have designed my own DDR memory controllers as well as raw-mode driver controllers and written all of the driver software for the required embedded system. My last design was a combination embedded DSP and FPGA that processed high resolution image data in real time at a rate of approximately SIX BILLION bytes per second. So, yes, I am an idiot and make really fucking dumb suggestions. Because of that I would like to think that, if the choice exists --and very often it does not-- I do my best to pick the best tool for the job. More often than not, when it's pedal-to-the-metal time C is the most sensible choice. It used to be that you had to get down to assembler to really optimize things, but these days you can get a way with a lot if C is used smartly.
- derleth 14y ago> When dealing win an array is 400 times slower in a "modern OO language" then in raw C, well, the code id fucking bloated. Social science numbers do not impress me. Besides, what is a "modern OO language"? Haskell? How can you give any numbers without even specifying that detail? > Of course there are lots of places where OO makes absolute sense. And the fat and slow code is the compromise you might have to make. Your idea that "OO = fat and slow" is blown away by actual benchmarks. http://www.haskell.org/haskellwiki/Shootout http://www.haskell.org/haskellwiki/Shootout (And, yes, unless and until you define what "OO" is to you, I'll pick Haskell as a perfectly reasonable OO language. Given than I've seen C called OO by people with better writing skills than you, this is hardly a strange choice in this context.) > So, yes, I am an idiot Again, I did not call you an idiot. The only one calling you an idiot here is you. > More often than not, when it's pedal-to-the-metal time C is the most sensible choice. I agree fully with this. However, I disagree that "pedal-to-the-metal time" is all of the time, or even most of the time. Especially when you're trying to teach programming. Do you teach new drivers in an F1 racecar? Why or why not?
- derleth 14y ago> Coding algs and data structures in C lets you see how those things _actually work_ in the computer. No. Not really. C doesn't show you any of the essential parts of cache, opcode reordering, how multicore interacts with your code, or much of anything else that actually makes hardware fast. C makes you act as if your computer was a VAX.
- robomartin 14y agoI am holding my breath to learn what language you are going to propose, as a first language, that teaches all of those things.
- derleth 14y ago> I am holding my breath to learn what language you are going to propose, as a first language, that teaches all of those things. You're not reading my other posts, then. I explicitly said programmers can learn those things as and when they need to.
- aidenn0 14y agoRobomartin: I learned in C. I also find C to be superior to e.g. Java for learning data structures and algorithms. On the other hand you are losing this argument: Below let X represent roughly the sentiment "C is a good learning language, since it teaches you what happens at a low level" darleth: C sucks as an intro language robomartin: No it doesn't because X darleth: X was true 30 years ago but isn't anymore robomartin: well C is still better because there is no language that does X A better refutation is that I cannot predict the order of complexity for an algorithm written in Haskell that I could trivially do in C. Haskell presents immutable semantics, but underneath it all, the compiler will do fancy tricks to reuse storage in a way that is not trivially predictable for a beginner. Similarly with Java, you end up having to explain pointers and memory and all that nastyness the first time the GC freezes for 1-2 seconds when they are testing the scaling of an algorithm they implemented in it. Yes there is a "learn that when you need it" for a lot of stuff, but for someone actually learning fundamentals like data-structures and algorithms, we are talking about a professional or at least a serious student of CS. Someone in that boat will need to be exposed to these low-level concepts early and often because it is a major stumbling block for a lot of people. If you just want to write a webapp, use PHP. If you want to learn these fundamentals you will also need to be exposed to the mess underneath, and it needs to happen sooner than most people think.