58

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.

toniedzwiedz
  • 1,353
Stephen
  • 2,199

15 Answers15

110

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.)

Frank Shearar
  • 16,751
70

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.

12

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.

7

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.

dsimcha
  • 17,284
7

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.

JohnL
  • 1,890
6

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.

Mike Dunlavey
  • 12,905
6

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.

Jason Baker
  • 9,653
4

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.

John Bode
  • 11,004
  • 1
  • 33
  • 44
2

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.

uɐɪ
  • 2,981
  • 1
  • 18
  • 17
2

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.

wirrbel
  • 3,068
  • 2
  • 23
  • 34
2

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.

naftalimich
  • 433
  • 3
  • 9
2

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.

dave
  • 2,466
1

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.

Bill Michell
  • 1,990
1

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

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.