58
votes

My first programming language was PHP (gasp). After that I started working with JavaScript. I've recently done work in C#.

I've never once looked at low or mid level languages like C.

The general consensus in the programming-community-at-large is that "a programmer who hasn't learned something like C, frankly, just can't handle programming concepts like pointers, data types, passing values by reference, etc."

I do not agree. I argue that:

  1. Because high level languages are easily accessible, more "non-programmers" dive in and make a mess
  2. In order to really get anything done in a high level language, one needs to understand the same similar concepts that most proponents of "learn-low-level-first" evangelize about.

Some people need to know C; those people have jobs that require them to write low to mid-level code. I'm sure C is awesome, and I'm sure there are a few bad programmers who know C.

Why the bias? As a good, honest, hungry programmer, if I had to learn C (for some unforeseen reason), I would learn C. Considering the multitude of languages out there, shouldn't good programmers focus on learning what advances us? Shouldn't we learn what interests us? Should we not utilize our finite time moving forward? Why do some programmers disagree with this?

I believe that striving for excellence in what you do is the fundamental deterministic trait between good programmers and bad ones.

Does anyone have any real world examples of how something written in a high level language—say Java, Pascal, PHP, or JavaScript—truly benefited from a prior knowledge of C? Examples would be most appreciated.

7
  • @Stephen Oh, sorry... I misunderstood. (but u do see why u need to learn c /c++ right?) Jul 14, 2011 at 13:27
  • 1
    @burningprodigy Yes, in the case that I need to do something where C/C++ is required, or makes the most sense, of course I would learn C. My beef is with people who say you need to learn C to be able to effectively develop in high level languages. And that is absurd.
    – Stephen
    Jul 14, 2011 at 23:16
  • @burningprodigy let us continue this discussion in chat
    – Stephen
    Jul 14, 2011 at 23:16
  • can you give us some context (url) where "can't handle programming concepts like pointer..." comes from?
    – k3b
    Aug 13, 2013 at 12:47
  • If there was one language I wish I could learn, it would be Common Lisp, not C. As primarily a C# developer, I'm rather certain I'd benefit more from it. We already have pointers in C#. Mostly, I'd rather learn more ways to approach a problem than to try to implement my same solution in a more difficult way. (Just as a note, I'm half lying. I've done some C, and I know that it has its advantages. Just wanted to give credit to an incredibly powerful and expressive language that predated C by a decade.)
    – Magus
    Feb 18, 2014 at 23:56

15 Answers 15

111
votes

The advantage to knowing C is that you have a very good idea of how a computer works. Not just how your programming model works, but how memory's laid out, and suchlike.

The only level below C is the assembly spoken by a particular CPU.

(I'd add that knowing C also lets you appreciate how much less work you have to do in a higher level language. And hopefully an appreciation of the cost involved in working in that higher level language.)

31
  • 12
    Frank: You hit the nail on the head. Understanding how a computer works, memory management and allocation along with the idea that you can further appreciate higher level languages is the reason to learn C. I am lucky we had to learn C to implement class projects such as implementing a basic TCP layer over UDP.
    – Chris
    Oct 26, 2010 at 12:43
  • 12
    I agree with this, although: C brings you only a few steps closer to the grass roots, not all the way to the ground. Ok, there's a thing called memory layout. But what does it mean physically? Do you understand how computer works if you don't understand electronics? Quantum mechanics? And so on. I'm not sure if there's a single mind in the world who deeply understands the whole food chain from a high-level language, via C, down to quantum mechanics. Oct 26, 2010 at 13:19
  • 14
    My question is how can you benefit from knowing how a computer works internally? What are you gaining? Appreciation of what you have now isn't a very good reason to learn a very low level language like C. Its like saying I should learn Fortran to appreciate what I have now
    – TheLQ
    Oct 26, 2010 at 14:15
  • 18
    @TheLQ I'm speechless. How can you benefit from knowing how a computer works internally? You're gaining a clearer understanding of what you're doing, is what you're gaining. Rather: you're learning what it is you're actually doing to the machine in the first place. Oct 26, 2010 at 14:38
  • 15
    I'm going to mark this as correct, as it seems to be the favorite answer. That said, I don't really care "how a computer works" on a fundamental level, as it really doesn't help me develop the next cool feature of my application. It's like driving a car: I'm very good at it, but could care less how the break fluid pressure works. It just stops when I hit the brake. Also, I'm sure I would appreciate driving a car more if I had to first ride around in a horse-and-buggy for five years. Doesn't mean I'm incapable of postulating how much better things are with the car rather than the buggy.
    – Stephen
    Oct 26, 2010 at 21:17
71
votes

I don't think any of the answers here are really what the OP was looking for, so I'm going to throw in my own opinion.

Look, I'm an unapologetic C snob. My attitude is that if you don't know C, then to some extent you don't really know what you're doing as a programmer. So, I think I'm the sort of "biased" person you're talking about here.

However, in practice, whether or not you really know what you're doing as a programmer doesn't necessarily prevent you from developing really awesome, useful software using high-level tools. I mean, the creator of Stack Overflow, Jeff Atwood, apparently doesn't even know C, and yet I would say Stack Overflow is a pretty damn good web application.

Whether or not you decide to learn C (or C++, or assembly) depends on what type of programmer you want to be. If you just want to develop cool web apps or business apps, that's fine - no real need to learn C. But if you want to really excel at what you do - if you want to work on really cool projects that push the state of the art, then you really need to take yourself seriously enough as a programmer to really understand how computers work. Since C is essentially the OS lingua franca, as well as the language that powers just about everything else (from the Linux kernel to most Java VMs, to the Python and Ruby interpreters, SQL databases, web servers, and just about every device driver), an intimate understanding of the language goes a long way.

Not to mention that knowing C (or C++) opens up a huge opportunity for contributing to large open-source projects that impact millions (or hundreds of millions) of people. Want to work on improving the Python interpreter, or the Chromium web browser? Well, you need to know C for the first and C++ for the latter.

That's why comparing C to dead natural languages like Latin or outdated technologies like the horse and carriage is completely wrong. A large portion of our 21st century software infrastructure is powered by C code, which is why C remains as relevant today as ever.

So, whether or not you should learn C really depends on what you want out of your career as a programmer.

6
  • 5
    You don't sound that snobbish. Okay maybe a little. :)
    – Stephen
    Nov 15, 2010 at 18:37
  • 7
    Excellent answer. I programmed successfully for ten years without learning C and C++, and could have gone the rest of my career without ever learning it. But since I learned it last year, I've written better software, not just in C++, but in my other languages as well. Dec 20, 2010 at 19:37
  • 3
  • 3
    Why would it be "completely wrong" to compare C to Latin? I think it's an excellent analogy. Latin is everywhere around us. 58% of the English vocabulary is influenced by Latin (directly or through other Romance languages). Latin also holds the key to understanding our culture. Law, democracy, religion, infrastructure, city-planning and a range of other areas can be traced back to the Roman Empire. You can choose to ignore C in the same way that you can ignore Latin, but you can never avoid them. "Latin and Greek are not dead languages. They have merely ceased to be mortal." (J. W. McKail) Nov 23, 2014 at 14:39
  • 2
    @AndersSjöqvist, it would be wrong because nobody speaks Latin anymore, even though it has profoundly influenced the development of modern languages. Whereas C is actively used and in use everywhere - in just about every OS, VM, database or interpreter. Latin is more like, let's say... Simula - a mostly dead language that has profoundly influenced living languages, yet isn't used outside of academia. Dec 22, 2014 at 22:07
12
votes

A practical rule of thumb is that you need to understand at least one level of abstraction below the one you usually work in. Consider that your PHP or JavaScript interpreter may actually be implemented in C or C++. Eventually you are going to hit a bug in the interpreter or even a C runtime error. If you don't understand C you are going to be limited to sending a bug report to the maintainer, hoping they can reproduce it and care about it, and then twiddling your thumbs. If you know C you can tell them exactly where the problem is and what it is.

This also means that if you work in C/C++ you should at least be able to read assembly on your platform.

As for learning C when you need it: my observation is that most programmers can learn Perl/Python/Javascript on demand, but assembler/C/Lisp seem to require a lot more time, so it's worth learning at least some basics before the need arises.

3
  • 9
    Ok, "C/C++" I can live with (language lawyers be damned). And "Perl/Python/Javascript" is perfectly reasonable. But for the love of God, why "assembler/C/Lisp"? That's like saying "apple/orange/Barrack Obama". Those three languages have nothing to do with each other. Sep 12, 2011 at 5:07
  • @Jason, the only commonality I was suggesting is that most folks find that trio of languages harder to pick up on the fly, and so it might be worth the OP's while to spend some time with them before an immediate need to use them arises. Pointer arithmetic and functional programming don't have much in common except that people seem to have to stare at them longer before they make sense. Sep 12, 2011 at 6:02
  • I couldn't agree more. Going the other way, to higher levels of abstraction, the “office IT guy/gal” who can do at least some programming will usually be better than the one who can't.
    – Emmet
    Jul 27, 2014 at 23:09
7
votes

I don't agree that you need to learn C first, but I do believe you should learn C eventually. All abstractions are leaky and understanding C makes it easier to understand what's really happening when you use some fancy high-level abstraction. That said, I also think all serious programmers should eventually learn to at least read assembler, for the same reason.

Learning these low-level concepts gives surprising ability to reason about high-level stuff. For example, in C++ and D, default arguments to virtual functions are determined by the static (compile time) type of the object, not the dynamic (runtime) type. This makes no sense unless you understand how vtables and calling conventions work and why it would be extremely hard to implement virtual functions in the opposite way.

5
  • 2
    Learn to read AN Assembly language maybe. The problem is that I have upwards of 10 different processor families that I use and learning all of the very different variants is a recipe for confusion and chaos. Try comparing AMD SHARC with Atmel AVR32 and TI MSP430.
    – uɐɪ
    Oct 26, 2010 at 12:51
  • @Ian: Right. Ideally you should learn the assembly language of whatever arch you develop most for. For most people I guess this will be either x86 or ARM.
    – dsimcha
    Oct 26, 2010 at 12:59
  • 3
    "all serious programmers should eventually learn to at least read assembler" It's comments like these that got me started with this question. I think you are simply biased, sir. Although, I like what you said about leaky abstractions. That makes sense. On the other hand, these things don't make a whole lot of "real-world" difference in my arena. I'm still using the high-level abstraction, leaky or not.
    – Stephen
    Oct 26, 2010 at 13:24
  • 1
    @Stephen, you should try writing some assembler language.The 8-bit CPU's are not hard and trying to implement the same small thing in both 6502 (like the C64) and Z80 (like CP/M business machines) is actually a very educative experience due to some very basic design differences (index page versus registers).
    – user1249
    Nov 15, 2010 at 21:51
  • +1 despite the blatantly false All abstractions are leaky statement. May 8, 2013 at 16:39
7
votes

The bias is one of status quo. In the old days (1980s and earlier), C / C++ was pretty much a requirement for performance applications. That's changed but senior developers generally come from that old-skool background and view things in that context.

For actual development other languages are used - C# is a popular one, as is Java, while PHP and Python are popular for internal projects and it's always useful to have someone on hand with at least basic knowledge in that area in case you choose an open source PHP project for, let's say, your bug tracking system. However, job specs still seem to come from that standard template that was written 25 years ago.

2
  • 6
    "job specs still seem to come from that standard template that was written 25 years ago." You couldn't be more correct.
    – Stephen
    Oct 26, 2010 at 13:27
  • Congratulations, John!
    – Mark C
    Nov 29, 2010 at 2:26
6
votes

Much as I hate to post the obligatory Joel blog post, I agree with him here. C is the lingua franca of programming. I can't think of any high-level language that can't interface with it somehow. Because of that, C is still a popular choice for systems programming type stuff. You simply can't interface with some OS-level things without C.

Besides that, what do you plan to do when your high-level language isn't fast enough? Knowing how to write C is especially important when you're using a high-level, dynamically typed language like Ruby, Python, or PHP. But even Java and C# programmers need to drop down to C from time to time.

3
  • lol. Joels advice in the linked column: "You'd be better off ignoring what I'm saying here and instead building some kind of online software thing that lets other students find people to go out on dates with."
    – Stephen
    Nov 15, 2010 at 22:05
  • 3
    @Stephen: If you want people to really notice you, then get them either laid or paid.
    – Fred Nurk
    Jan 22, 2011 at 11:17
  • @Fred Great advice, lol.
    – Stephen
    Jan 22, 2011 at 13:52
6
votes

What a great slug-fest! (As they supposedly say: Is this a private fight, or can anybody join in?)

I was a professor, and what I found (after some trial-and-error) was that it was much easier to lead students through the intricate concepts of programming if they understood, at a base level, just what a computer was doing. Not in all the nitty details, but the basic principle, like what memory is, what instructions are, etc. What I like about C is it's close to the machine.

That's not to say other teachers came to the same place. They started off in the high-level language (BASIC :-) and went forward from there, with no obvious ill effects.

So bottom line, Stephen, you could be right. I wouldn't think so, but I've been wrong before.

4
votes

I guess this is progress.

Twenty years ago, the conventional wisdom was that you had to learn assembler in order to understand what you were gaining from higher-level languages like C (which is why I had to take an assembler class in college using VAX Macro; guess how useful that turned out to be upon graduating).

There's a superstition that because C is somewhat hard to learn and that it provides almost no abstractions (pointers and byte streams are pretty much it), learning it will somehow make you a better programmer or give you greater insight into how things work at the hardware level.

This is not (necessarily) true. Standard C doesn't get you any closer to the metal than any other 3GL (Pascal, Fortran, etc.). Some C implementations may provide hooks that give you greater access to some areas, but in general naked pointers are about as close as you get, which isn't close at all. You cannot directly access registers or status words, for example.

In the end, it all comes down to opcodes and addressing modes, so if you're really interested in how things work at the lower level, you'd be better served learning assembler over C.

By itself, learning C will not (necessarily) make you a better programmer. It will definitely give you an appreciation for actual string types and standardized container libraries, though.

2
  • I guess "appreciation" is one way of putting it. In my high school programming class, it was mostly just questions of "I need to use this function. How do I convert a LOLOMGCHAR* to a WTFBBQCHAR*?"
    – Katana314
    Aug 13, 2013 at 13:48
  • i think C was easy to learn. at least it was for me from just reading Kernighan & Ritchie . Dec 23, 2014 at 0:38
2
votes

A language is a tool. If you only have to write web pages and the like then I am sure that you can get away without having to learn C, in just the same way that if you only ever make plastic model kits you only need a sharp knife and glue, a spanner is not normally required.

I write code for embedded systems with highly restricted memory resources (the biggest I have done recently is 16kbyte and that was HUGE) In this market then C or assembler are the only options and any of the fluffy higher level languages just don't work.

4
  • 1
    That's great... But not everyone does that. The implication seems to be that people who aren't writing for embedded systems are just playing and not doing serious development - at least, taking your model analogy in the context of your embedded systems point. That's clearly not the case and it's possible to write large-scale production applications without ever touching C.
    – JohnL
    Oct 26, 2010 at 12:53
  • Of course it is possible to write large scale production applications without going near C. I wrote code for 10 years before I got to use C. I used PL/M, Pascal, ADA as well as assembler. These were easily as good as C for learning the underlying mechanics of the machine, and often better for producing error free code.
    – uɐɪ
    Oct 26, 2010 at 13:07
  • Great - though your answer above didn't give me the impression that you thought that way, hence my reply...
    – JohnL
    Oct 26, 2010 at 13:47
  • Do you have any experience with the Java engines targetting embedded usage?
    – user1249
    Nov 15, 2010 at 21:48
2
votes

In my experience, for a while C/C++ was a good buffer that segregated the good programmers from the VB6 coders. After doing five odd years of C/C++, I got a job working in VB6. I was amazed at the quality (or lack thereof) of the coders. They had little interest in the guts of the language, in design or about performance. Unfortunately, when the company moved to .Net, the C/C++ coders and the .Net coders were using the same tools. The VB coders were even worse VB.Net coders. The situation got worse when all development went to ASP.NET. Suddenly anyone who could drag and drop a control was a programmer.

In the job market, though, there was not much to differentiate the hard-core coders (ex C/C++) and the tourists.

As such, having C or C++ on your resume may help differente you from the riff-raff.

2
votes

Procoatively asked: Are you asking for confirmation that you do not have to learn C? If you learn pure C (not C++ necessarily) you will get a thorough understanding of the execution model of a computer. Especially about memory and allocation. This stuff also matters to people programming in higher level langauges.

For a PHP programmer its just less transparent how code is executed on the given machine. It might not matter for the PHP programmer since Network transfer is the bottle neck in the application, etc.

Plain PHP/Python/C# has a lot of abstraction layers between the language and the CPU. these layers are so thick that they do not allow you to look through them. When you learn C, there is a thin sheet between you and the CPU and the operating system. That does not make programming easier (and it might not even be better). But you are actually able to learn how the CPU works. Once you know the "intermediate" C, you can actually start to link that knowledge upwards to the higher level language. This is the immediate benefit that you will gain.

In my opinion a programmer should always spent some time learning different programming concepts. It definitely pays of to have a look at C, but also to have a look at even higher level programming languages such as Clojure, Haskell, Prolog.

You don't have to become a master in these, they will just teach you the lesson that "levels" of programming languages are not binary but there are a lot of levels. Get to know them, from top to bottom (Assembler). It will make you a better programmer.

2
votes

You need to know enough C to read code written in C, because of the vast amount of very important code written in the language. That's about all you will retain from going well through a thorough manual on the subject (I used Kochan's "programming in C") without actually having to code in the language, anyway. Should you ever wind up in a situation requiring you to use the language extensively, you will have a good base to build on. You probably want to study something like Duntemanns Assembly book if the machine is an abstacted black box to you. I also recommend Petzold's "Code".

Outside of that--basic literacy in C and basic familiarity with the underlying machine--you'd be best served spending your study time on the real stuff, like SICP, TCP/IP Illustrated or books on Concrete Mathematics, algorithms or data structure. The real stuff.

Spending a lot of time studying C while coding in PHP simply isn't worth the opportunity cost. There's more helpful things to learn. C really is just another language that you can learn well only though study and use, but can pick up when you need to.

Sweat the hard stuff.

1
vote

C is the language that is used to write other languages. It allows you to get as intimate with the CPU and other hardware as you like.

If you don't know C, you don't know how other languages achieve the results they do.

Abstraction is an important concept, of course, and not everyone needs to know how their framework of choice is achieving the results it promises. You don't need to spend 20 years writing C, or indeed thinking about what happens to your vtables when you use multiple inheritance, in order to write good code.

Now, you can drive a car without understanding how a 4-stroke engine works or indeed without being able to use a stick shift (manual gear box).

However, if you understand what is going on under the hood you will, from time to time, be able to achieve exceptional results that someone without that knowledge will struggle to replicate.

1
vote

C (and possibly C++) is the sea you are swimming in. The OS that will run your code is probably coded in C (and C++). So your native API to access OS services will be in C.

If you can do without knowing what is there below, there is no need to know C. However most programmers need to dive into lower levels at sometime in their lives.

It is also based on your specialization of development areas. For example a web developer who writes HTML, Javascript and some server side scripting may never need to know anything about C, but a distributed system or game developer will.

It never hurts to spend a few weeks learning something so fundamental for your profession.

1
vote

C has many advantages:

  1. C is a low level language.You can use c to develop kernel and driver.
  2. C is fastest language.Many power software be developed by c. For example: memcached,redis,nginx,apache,mysql etc.
  3. C is a cross-platform language. The program developed by c can run at every platform. Other cross-platform languages can not do this. Java,python,php etc can not run at iOS platform.
  4. C++ can not run at many embedded systems.

Not the answer you're looking for? Browse other questions tagged or ask your own question.