I am a front-end developer who barely even see a file with .h
or .c
extension.
I know basic C syntax, I’ve learned it in Unreality but never was interested in such
low level programming because it was simply too much setup for simple things.
I am very interested in learning all aspects of Computer Science but I want to believe
I do not really have to know a specific language in order to understand most of concepts
in Computer Science. Yet when I start reading books and articles about fundamental
Computer Science concepts like Data Structures and Algorithm Design it seems that
I have to learn C, because all examples and even lessons are in C (and sometimes
Java).
My question is, is C as a programming language essential for Computer Science or
we just happened to have all of our resources in CS written in C? Can one learn
Computer Science without learning C?
4
I’m going to go against the flow here and say yes, you do have to learn C. I actually agree with the points in many of the other answers, but you make the very strong statement that
I am very interested in learning all aspects of Computer Science but I
want to believe I do not really have to know a specific language in
order to understand most of concepts in Computer Science.
(emphasis mine)
Well, operating systems and network stacks are two huge aspects of Computer Science, and all the dominant operating systems and network stacks are written largely in C. If you want to understand those, you should learn C. Yes, some schools do manage to teach their OS classes in Java, but it’s like reading Homer in English.
Besides, C is not that big of language. If you really want to learn all aspects of computer science you should shrug and say ‘meh’, ‘what’s one more language?’
2
For a very long time, during the height of computer science as a science rather than a vocation, there were a few limited choices for a language that ran on all the systems that all the different universities used.
By far, universities tended to use Unix systems. Conveniently, this was programed in C. One could start with learning C on any machine, and eventually get into the unix source code in C. At home, students could use a C compiler such as Borland Turbo C on Windows, or MPW on a Mac – it worked everywhere.
Pascal was another option, but that tended to have the problem that at a certain point in programming, it just wasn’t enough of a language to do what you really needed to do (programming an OS in pascal would be painful).
Some of the older school learned Fortran, but again, it wasn’t a powerful enough language in many cases to be able to teach higher level CS classes (AI theory in fortran? Doable but painful).
And so, for a long time C was the choice.
It isn’t the only choice and there are many colleges now that teach in other languages to gloss over some of the internals and learn higher level concepts without having to deal with the ugliness of memory management and the like. Some think this is good, some think this is bad.
So no, learning C isn’t essential to learning computer science. You can find many other books out there that teach computer science from Java or Python. Its just that for a long time, C was the choice and academic books move slowly.
2
I admit that one can get a well-paying job and be productive without ever touching C, but I highly recommend learning C for anybody who is serious about having solid understanding of computer science.
Although computer science is about concepts, which could be learnt irrespective of any specific programming language, there are fields which may be much better understood by learning C or by learning that field using C.
-
Algorithms and Data Structures. Standard C has almost none of these – having these already implemented in the language or in its standard library tend to be demotivational for students: “Why should I bother implementing something readily available?” Looking at a piece of C code, you immediately see its algorithmic cost, since everything in C compiles to a few machine instructions only. High-level languages (e.g. Perl or Python) often use advanced data structures under the hood of lightweight syntax. Code feels light, but it is not. You already need a great deal of knowledge to correctly reason about the algorithmic complexity of those code pieces. Therefore those languages are not as suitable for learning algorithms and data structures, and many programmers who was always living on high-level languages, tend to be incapable of dealing with performace problems, when they run into them.
-
Operating systems. Most operating systems are written in C. How do you want to understand process creation without ever calling
fork
? The abstraction layer of the Java VM is no help here. And just talking about it without ever creating a process is even worse… How can you write a software like Eclipse which can redirect the standard output into one of its windows? You need to understand OS-level concepts for that, and you can touch those directly in C only. -
Indirection. You cannot do C without dealing with pointers. Pointers force you to think on two-levels, and that stretches your abstraction skills.
There are also some technical advantages of C knowledge:
-
Cross-language interoperability. You want to integrate a great Ruby module into your Python project (substitute two arbitrary languages here). Chances are that the only way to do that, is through C, because both languages has a foreign interface to C.
-
Writing performance critical software. One cannot omit going low-level to do this.
I do not say, that every program should be written in C. But C can help you to knowledge, which is useful whatever language you program in.
1
I’m also going to go against the grain here and try to make a (slightly humorous) aesthetic case for C. While some people might call it “ugly” for different reasons, such as the lack of higher-level constructs like classes or its reliance on pointers, I find that it isn’t the case for me.
TL;DR: In my opinion, C is simple, good C is readable and there’s a certain joy to be found in banging bits.
C is simple
Standard C defines only a few basic types and mechanisms to create functions, pointers and arrays out of them. On top of that, there’s a small number of composition constructs to make more complex types out of the primitives (like structs and unions).
Notice how I described most of the language in two sentences. This means you don’t have to keep too many syntactic rules and forms in your head while coding.
Simple is beautiful.
C isn’t arcane
Unlike many higher-level languages, you would be hard-pressed to find a lot of weird, unintelligible symbols in C. In the C world, the main facility for both abstraction and “syntactic compression” is the function – semantically a very simple and self-explanatory construct. Good C style encourages almost poetic, readable beauty. To illustrate, let’s try to read the following snippet from the Linux kernel. Even without having grasp of the underlying data structures and implementation details, we can make a lot of sense of the following:
bool kthread_freezable_should_stop(bool *was_frozen)
{
bool frozen = false;
might_sleep();
if (unlikely(freezing(current)))
frozen = __refrigerator(true);
if (was_frozen)
*was_frozen = frozen;
return kthread_should_stop();
}
The middle of the function reads “in the unlikely event that current is freezing, ask the refrigerator if freezing actually happened”. Dr. Seuss couldn’t have written it better.
Readable is beautiful.
C is transparent
Unless a C statement includes a function call, you can generally get a very good idea of its run-time cost and side effects. C gives the programmer control and ultimately trusts him or her to do the right thing. We can get a picture of what happens when this (slightly reformatted for SE) snippet out of the implementation of strlen()
in the GNU C library runs, because every operator has well-defined semantics. There is no overloading in C.
for (char_ptr = str; ((unsigned long int) char_ptr & (sizeof (longword) - 1)) != 0;
++char_ptr)
if (*char_ptr == '')
return char_ptr - str;
For the purposes of “optimizability”, this property is great. Arguably, some higher-level languages make the concise expression of higher-level algorithms easier (like C++ with classes and overloading), but for the purposes C was designed for – acting as a portable assembler – C is ideal. Sometimes, upon successful execution of low-level code, a programmer might feel one with the machine, in a sense (or zero – it’s an implementation detail).
This isn’t to say other languages are bad, not “zen” enough or something silly like that, just that IMO C can be interesting in ways that many other languages have chosen not to be, for many valid reasons.
In my opinion, the three points presented above make manageable the creation of complex – yet efficient – systems, embodied in my mind by Linux. I find that this world appeals to my aesthetic sensibilities and I’d advise anyone considering C as his or her next target to consider these points. I feel that arguments about operating systems and whatnot are better supported by explicitly stating them because one certainly does not need to understand kernels in order to be a successful programmer, but one might find these fields compelling subjectively.
The programming language you use to discuss the science of computing is largely irrelevant to the task of learning the means and science of computing.
The (arguably) seminal work on Computer Science, The Art of Computer Programming, does not use any existing language to inform the subject. Instead, Donald Knuth chose to define a fictional computer and a fictional machine language (and an associated assembly language) in terms of which he discusses all topics.
Another highly regarded work on the subject, The Structure and Interpretation of Computer Programs, took a similar approach, devising a simplified dialect of the LISP programming language to act as its own context. This language is what we know now as Scheme.
Yet another very good work on Computer Science, The Elements of Computing Systems (which is actually equal parts Computer Engineering and Computer Science, and very brief), takes the more fundamental approach of teaching digital logic, from which it builds the machine, the tools, and the language, before teaching elementary Computer Science.
So, no, C is not necessary for an understanding of Computer Science. What matters is your understanding of the core concepts of algorithms and their application.
I started a career in programming by learning vb3 from the manuals that shipped with the floppy disks it came on. I learnt some java and was able to produce some respectable programs but it wasnt until I studied C at university that I felt that I really understood what was happening “under the hood”. I now work only with .net and never really worry about pointers, invalid addresses or overflows – but I understand them, this informs the decisions I make on a daily basis and some of the old school stuff is still there in modern interpreted languages, flags, bit wise operations, Boolean logic, all powerful tools and very efficient.
Learn C. It will stand you in good stead. I kept a copy of the c programmers handbook for years and read Kernighan and Ritchie from cover to cover. Doesn’t matter what language you end up working with Understanding C will definitely help.
Can one learn Computer Science without learning C?
The answer is Yes. I have my degree in CS and was not required to learn C, but rather Java. At least in my school, the emphasis was on learning Object Oriented Programming, with some teachings on Assembly Language, Data Structures and Database Design.
10
It really depends on what you want to do with what you’re learning. It’s definitely true that a lot of algorithms are given in C, or descendent thereof. However, over the years I’ve seen more C++, C#, and Java examples. What CS is meant to teach is a general understanding of computing, and therefore how to pick up or create a language appropriate for the task at hand.
However, there are still a lot of people whose first and last language is some variation of C or Java, and not all of them are going to have the training to understand any-given language that a CS degree provides. Even some CS graduates have trouble with programming. So you may need to have a good enough understanding of those languages that you can communicate with them, depending on your career path. If you plan to stick to academia, then you’ll have even more language barriers to content with, especially in interdisciplinary areas (where people use prolog, lisp, haskell, mathematica, etc.)
If you’re really going to learn “all aspects of Computer Science” (ambitious plan!), you’d have to deal with several different assembly languages, and at least one HDL (and practice coding on a netlist level in it).
And as a higher level step to approach these truly fundamental things you’d have to pick up something like C or Pascal, its unavoidable. Skipping steps on a ladder of abstraction is counterproductive.
Anyway, I doubt this question even worth asking. After all, C is just a tiny language. You could have learned its basics in a shorter time than you wasted reflecting on whether you have to learn C or not.