Why I Feel Learning C First is a Waste of Time

Pages: 12
Although the content of the post itself may not be the best laid argument, the topic title itself is still worth discussion in my opinion.

Personally, I think C is still a great useful language. I don't think there will ever be a time within the next few decades where C won't be used for newly written code. But, I think it is not a good idea to try to learn it as a first language.

The problem with learning C as a first language is that you have not been exposed to the idea of bad education, such as bad professors, bad books, bad online resources, etc. and don't know how to discern between reputable resources and resources that don't know why looping on EOF is bad.

The same can be said about C++ but personally I think the main issue with C++ is that it gets lumped with C. C may have simple syntax but the language and the way you use it are quite complex. I have studied C++ passionately for years and while I feel confident in my C++ abilities I feel highly reluctant to touch anything written in C for fear of breaking it.

The more complex a language, the more incorrect/incompetent a resource is able to be. The first language someone learns is an extremely important influence in their understanding of programming, and if the resource they use is incorrect, they will have a skewed or even superstitious view of programming.

You can find good resources to learn C with, but someone who has never learned any language won't be able to tell the difference between a good resource and a bad resource and probably won't even know there are bad resources.

I'm not saying other languages are immune to bad resources, just that some languages lend themselves to being easier to make good resources than bad resources, and that C is not one of them. Then again, C++ isn't either, primarily because it still gets lumped together with C.

I consider myself lucky to have learned C++ from the tutorial on this site. C++ was my first language, with Java being my second. I've already posted a thread where my friend in college has a bad intro-to-cs professor requiring him to write a linked list in C++ with binary search support, and I know that there is plenty of misinformation about C++. So, I am hesitant to recommend C++ as a first language, as much as I want to.

Now, if someone was really smart and aware of the fact that information resources can be bad, they might ask around and look up what resources are good and which are bad for learning C, and if they do that, they should have no problem learning C as a first language.

But you have to remember that most people who want to learn to program these days are young - I was only 11 years old when I expressed interest in programming and I got into C++ at around 15. I was not very aware of the world and still very naive (and lucky, as I said).

The other main group of people learning a first language will be those who take a programming course in college. College courses are notorious for teaching C incorrectly in classes that have C++ in the title and description. I have experienced it first-hand when I took a class "C++ in a unix environment" where the professor asked us to not use C++ despite showing us bad C++ tutorial slides from a presentation he didn't make himself.

Thus, I will not recommend learning C as a first language. A first language is too important to screw up by learning from a bad resource that you don't even know is bad. C, unfortunately, is too easy to mislearn. I may recommend C++ as a first language but only because I know how to provide good resources to learn from and advice about how to avoid bad resources. I can't do the same for C because I lack experience with C.

To be fair, though, I have yet to see any programming language which I consider to be suitable as a first programming language. So, you may consider my post as overly pessimistic.
Upon re-reading the original post at a better mental state, I realize that this isn't the greatest post (and the title doesn't even match it, it's only relevant to a small half-assed paragraph). I might just rewrite this in a new thread if I can scrap together some time one day.

Cubbi wrote:
If they are modern C programmers, it's not trivial.

Just to clarify, I was comparing C89 and C++. I haven't seen any examples of modern C, so I can't say much about it. Most C applications I see are written in C89, so I figured I'd just write about it.

ezchgg wrote:
Tbh that's pretty nasty. You could write global set/get functions in C as well, you'd just be polluting the global namespace though, would introduce type safety issues (at least from C++ perspective). If there is a difference i would say this was it:
That was actually an example of me telling beginners what NOT to do in C++. The struct implementation was clearly the superior one.

Abramus wrote:
I'm always surprised when I hear somebody's saying it's a waste of time to learn C.
This isn't what I was saying. I was trying to say that C isn't necessary to learn before tackling C++. C is a great language. Learn C if you want to learn C, however if you want to learn C++, then learn C++. C is not a prerequisite.

In order to be a competent programmer you must know it, period.
Wut? That's just silly. "In order to be a competent English speaker you need to learn Anglo-Saxon."

chrisname wrote:
Is no-one going to point out the fallacy of comparing object-oriented C and C++ code when C was not designed for object-oriented programming?
I was comparing the common usage of C and C++. (Based on when I see it)
Last edited on
I think Python is probably an ideal first language; even though I dislike the language, it has automatic memory management, a lot of included libraries, you can learn the syntax in a few minutes, and you don't have to write any boilerplate to get started. It also has a pretty good interactive interpreter which is important for some students (I personally have never liked using a REPL).

At my university, they teach Java first, so students are using classes before they even know what an object is. Students are writing all this stuff about classes and main functions before they know what any of it is. All they know is, they have to write a bunch of things that don't seem to do anything in order to make their program compile. With Python, you can just start writing code and the interpreter executes each line in exactly the order that you write them. When you learn about functions, you can start breaking your program up into functions, and when you learn about classes, you can turn some functions into class methods. The language naturally lends itself to learning to program in the most logical order.

After Python, they should teach C so that students learn how to do manual memory management. I don't think C should be taught first because introductory programming should focus on teaching concepts, but it is important to understand that garbage collection is only there to make things easier and not the way computers actually work. At some point you do need to know how memory actually works. Most courses have a vaguely-hardware oriented section and C should be taught in tandem with that. They could also teach at least one assembly language (my vote would be ARM) at the same time, especially to show how C is translated into assembly. On my course, they taught us AVR assembly and Arduino C(++, but we didn't create our own classes - we used Serial but we weren't told that it's a class object) in the first year, which I think was a good idea.

Then Haskell. At my university, functional programming is an elective module (although the professor who teaches it also teaches Data Structures and Algorithms, and in that module, he makes us write all our algorithms in a functional style even though we're using Java. I fully support that idea) but I think it should be mandatory. Functional programming will only increase in importance as clock speeds stabilise (already happening) and the focus switches to multicore.

Then Prolog, just so that after having their mental model of what programming is destroyed and reformed by Haskell, they can have their minds blown again by Prolog. I liken it to the programming equivalent of what LSD enthusiasts call "the thumbprint", in which a person consumes a thumbprint's worth of LSD crystals (equivalent to up to 1,000 normal doses) and completely loses touch with reality.

Finally, they can return to the world of mortals by learning C++, Java, C# or whatever, because realistically, to be considered a practical degree, they have to teach you a language you're likely to actually use. Most CS students aren't going into academia or anything cool, just code monkeying, so they're going to need more practical languages than just C and Python. Maybe those could be electives, instead of Haskell. Alternatively, they could teach these languages in between Prolog and Haskell so that students think they're safe, that Haskell was just one weird language that they'll never see again and they're back to the world where everything makes sense and code executes in order, and then BAM! Prolog.

I estimate that, using this method, CS courses could double or triple the productivity of their graduates (which is good, because they would probably also halve the number of graduates. But that would be good for us - fewer programmers means better salaries for the rest of us).

Avilius wrote:
I was comparing the common usage of C and C++. (Based on when I see it)

Still, you were comparing idiomatic C++ with non-idiomatic C.

The struct implementation was clearly the superior one.

Only if you don't need to control access to the values. C# has something called a property for that. It's used the same way as a member variable, but you can provide custom accessor and mutator functions

You can also implement your own properties in C++: http://pastebin.com/pn4dJfb9
Last edited on
Haskell and Prolog are awesome, but don't forget two more mind-altering experiencs: Forth and APL!
Isn't Forth just a stack-based language? I'm not really sure how writing in reverse is 'mind-altering'.
In C11, the non-elegant C code would be this instead:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#define DoTask(T) _Generic((T), object_t: ObjectDoTask)(T);
#define Output(T) _Generic((T), object_t: ObjectOutput)(T);

int main()
{
	object_t* object = CreateObject();
	
	DoTask(object);
	Output(object);
	
	DestroyObject(object);
	
	return 0;
}


Or something like that? I don't have a C11 compliant compiler to test unfortunately. Not that pretty from an implementer perspective but easy going if you're a user of the code. It provides a means of type checking and you can do some cool stuff with it.

Other than that, it comes with the usual C type pitfalls and macros.
Last edited on
LB wrote:
The problem with learning C as a first language is that you have not been exposed to the idea of bad education, such as bad professors, bad books, bad online resources, etc. and don't know how to discern between reputable resources and resources that don't know why looping on EOF is bad.


This is true with every subject and I would say the most fundamental skill to learn at college is how to do research. This is especially true with the fact of the internet being what it is. I actually think that a degree in computer science should go as low level as possible, simply because if it were only high level then the student might as well not even go to college.

A teacher who is well skilled in data-structures and algorithms has probably not been spending his time keeping up with modern language features. One of my teachers was absolutely horrible to sit through. Each class he would hand out printed code and read it to us line by line. If you got caught up in the fact that he was teaching us Win32 and MFC rather than C++ then you would miss the years of experience he had in writing supremely elegant code.

I think C is a little bit too low level for a first language. C++ is actually pretty good. It will probably be taught in an intro-to-computer-science class, and these classes typically start with "Your computer has a processor, memory and a hard drive. The operating system coordinates these things. It provides a stack of memory, and here is how you use it...". Moving on, C++ provides higher level functionality expected from a modern language.

But I would say the focus on which language is too strong. The second semester should be a barrage of languages. The ultimate goal should be to teach students what to expect from a language. This way, a student will be able to approach any language and say "okay, how do I declare a variable? How to I recurse through a directory? Oh, I don't need semi-colons, but I do need colons and tabs..."
I think C++ is not a good first language simply because it's a lot like C except more. It's hard to make good C++ software without understanding what's actually happening underneath all the syntactic sugar. You can cover it up all you want but when a problem arises that is potentially caused by one of those constructs that you don't immediately understand, the compiler isn't going to give you a simple and concise error message. C++ is quite infamous for it's complicated errors and how it can blow up in your face with so much as a single change.

Note that I'm not saying it can't be done, but it's definitely not an ideal language. I wouldn't recommend D or C either. Python, UnrealScript. Java, JavaScript, even PHP or Hack now adays... they're all more productive and easier to work with than C or C++ as a first language in my honest opinion.
C++ was the first language I laid eyes upon. All you need is time and a good book. I had a ton of ,"magic happens here" moments to get through assignments,but all I did was go back a few chapters and read. Plus copy and pasting compiler errors on google helped a lot lol.
I don't ever look at anything as being magic - instead, I just understand that some things work in ways that aren't important to me. I know I can always find out the details if I want to, but I don't need to.
So when you try and copy an iterator instance, then make a change to the construct that the iterator is associated with (depending on the construct), do you think it's a simple task to understand that the iterator is invalidated in certain cases?

Or even the idea that using std::cin multiple times with user input might not work as intended due to it getting caught up in a newline character left in the stream?

Or that NULL might not work with a pointer overloaded function as intended (which is carried over from C but still a problem in C++ to this day).

There's a huge list of pitfalls that are not user or newbie friendly. I think it's naive to say that just because you've become used to and familiar with those pitfalls, that they are easy to understand and that everyone can easily adapt to them.

EDIT: I feel like the older I get, the less I understand the English language...
Last edited on
Well I'm not saying its easy,hence why I said time is an important component. But you're right. If a person is only curious about programming, C++ isn't the best option.
Isn't Forth just a stack-based language?
What isn't?

C isn't what it used to be. In C of the past, you couldn't assign structs, you had to memcpy them, plus other things we'd now find intollerable. It was necessary to apply considerable discipline and experience to write clear, concise and efficient C. Modern C has taken a bit too much from C++ in my view.

C and C++ (pre C++11) share the same Virtual Computer, so the machine concepts are the same, but that doesn't make a good C programmer a good C++ programmer--they're different things.

If you want to learn C++, learn C++, not C.
Topic archived. No new replies allowed.
Pages: 12