Suggested reading order and other questions - c

Based on recommendations from episode 57 of the StackOverflow Podcast, I have purchased "Structure and Interpretation of Computer Programs", "The C Programming Language", "Unix Programming Environment", and "Introduction to Algorithms". I'm wanting to improve my fundamental programming skills, contribute to some open source projects, and improve my future employment prospects. Is there a suggested reading order for the selected texts? Also, what particular subjects/sections from the books should I pay more attention to? Thanks.

If you already have a programming background you could get use from Cormen et al quite early. I found the audio lectures at http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-046JFall-2005/CourseHome/ helpful to go with it and you might also want to read the syllabus and prerequisites.
If you need more programming then either the C book or SICP can be used. I learnt C first and came to SICP later. I was happy with that approach -- I can't say which would suit you. The C book can just be worked through sequentially.
UPE probably needs a reasonable C background to get the best from it, though it has value for all programmers.
I'm not sure how much these help to increase earnings but I enjoyed them all and was a better programmer and IT professional for working at them
I'm sure others will have different and perhaps better, at least for them and perhaps for you, suggestions.

I've read these books except the Unix Programming Environment.
The C Programming Language (white book) is a good book to learn C.
Structure and Interpretation of Computer Programs (SICP), is a special kind of book. It's a book that you really have to study. It will teach you many programming concepts.
The three first parts of the book are a must read.
Building Abstractions with Procedures.
Building Abstractions with Data.
Modularity, Objects and State.
Introduction to Algorithms is a bit hard for self-learning but a good book.
I don't think you should study the books in any particular order. The important is to not skip the exercises.

Related

Practical examples for C practice?

I know several programming languages including Objective-C, Java, C#, and python, and C. However, I need to brush up my efficiency in C.
In most languages that happen to be high-level, object-based, and GUI-oriented, I create a few standard object-oriented examples to orient me to the language/framework. I usually create a "car" example where I model a car and allow the user to adjust the speed, watching the mileage increase.
However, something tells me this example is not as practical to carry over to C in a unix command-line setting. What are some good basic ideas to 'test myself' in a unix command-line based C setting?
Thanks for any input!
EDIT:
Thanks for the answers. My basic concern with the car example is that I shouldn't be attempting object-oriented in this environment, but rather do something that is more suited to the language. Thanks to Duck for the suggestion of recreating command line utilities.
Get yourself a copy of
C Programming Language (2nd Edition)
Recreate (for the umpteenth time) any of the standard command line utilities - cat, ls, touch, more, less, etc. Write a basic shell. These will exercise C and re-familiarize you with unix system calls.
try this: http://www.gowrikumar.com/c/
They provide puzzles and problems, have you spot them, and then you can check your answer. Might not be enough for what you asked for, but it might be a start?
You can write something similar with structures. Create a car structure and create functions that operate on the Car structure passed as a pointer (explicit this parameter). You can use conio.h or ncurses.h to do fancy console animation using timers. This can be fun and may provide some insight. You will also need to read keyboard input to increase/decrease speed.
Get "Advanced Programming in the Unix Environment" by W. Richard Stevens. The lectures and examples in this book are much more in tune, more realistic and practical to the type of work that is done in C. They show you the intent and purpose (and to a high the degree the philosophy) of the language.
That, IMO, will be better for brushing up your C (in addition to revisiting the oldie-but-goldie K&R book.)
I strongly recommend you go this route (in particular if you are coming from a UI, object-oriented world.) One world of caution: Do not try to do OO in C. It can be done, but that is not your immediate purpose. Learn how to code and model procedurally in C (in particular with examples tuned to its intended purpose.)

Do you have any experience teaching C to undergraduate students with the K&R book? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Has anyone had any experience in teaching programming in C to undergraduate students, who can be presumed never to have seen an editor before in their lives?
I might soon face that predicament, and was thinking of basing myself on the K&R "The C Programming Language" book. Has anyone had a similar experience? What are your ideas/recommendations? Is C the right language to teach undergraduate engineers as a first language?
K&R is not a book for programming beginners. It assumes that readers are familiar with imperative programming. Pascal or C++ programmers can start C with K&R; Java or C# programmers can with a bit of coaching on not having safeguards such as array bound verifications. But typical absolute beginners will take at least one semester to get anything out of K&R.
K&R has a very good compilation of exercises; don't hesitate to draw from them. You'll still need to provide more simple exercises and break down some exercises into pieces that are easier to chew. But as a course text, you need something with a much gentler progression.
If your undergraduates are anything like mine were, expect the first lab to be about logging in, firing up the editor, typing in a program, compiling the program, understanding the error message, repeat until the program prints “hello”. Prepare an environment that is as easy to use and locked down as possible. Give very detailed instructions (preferably tested on a 5-year old).
I recommend exercise 1 to be about typing in and running a hello world program (source code supplied on paper), exercise 2 to be about changing “hello world” to ”hello everyone”, and exercise 3 to be about typing in a program with a mistake (something simple, like a missing semicolon), attempting to compile the wrong program, and modifying the program until it works. If you have some really bright students, exercise 4 (bonus) can be about typing in and running a supplied quine. Getting your students to read a compiler error message is the most important thing for lab 1.
I've TA'd before.
Generally the less magic you give the students, the better. "It just works" is not an acceptable answer for engineering students. It's comforting, but there's no lasting value in it.
Most of them won't know what a shell or a compiler is, however. C is good in that it doesn't have much magic. I've not found a good intro to programming book yet, K&R can't be worse than the usual drek.
If given the choice, I would teach either Assembly or Scheme as a programming language to comp sci majors(software engineers, computer engineers, etc) in an intro course. For a more general audience, I would teach R.
I've taught rank beginners to program in c using K&R. But as a tutor, rather than in a classroom setting.
I love K&R, but it is very tightly written: you often have to read (and think about) each and every word to get the point. That's OK for experienced programmers (who were the audience for the book as far as I can tell), but in the wider population there are many people who won't sit still for that.
In a tutoring setting you can overcome that. You know where the critical details are hiding and can take the time to make sure the student "gets it" before moving on. That's harder to do in a lecture.
I'd suggest another book.
I, too believe that C should be taught as an Intro course to programming, because it's something in the middle, it doesn't have that much 'magic' in it which is associated with newer high level languages plus it has the low level stuff. Syntax wise too, it will prepare them with Java or C# in the future. But I'll suggest that before teaching them programming, train their logic first during the first 1/4 of the semester by teaching them some problem solving and basic algorithm. Even if they master the syntax, if they don't have good problem solving skills, then they'll have a hard time whatever language they use.
If you're teaching under Windows, this kinda fails. I suggest using a good beginners book, for C and then move on to K&R.
If you're teaching under Linux, I would advice a beginners book as well, there's plenty good books out there, take O'Reilly for instance.
And don't force them into IDEs or editors with a steep learning curve like Vim.
I'll add some good learning books later.
I have experience as a beginner in programming, studying independently (while working full time as a public school teacher). Last year I bought the book "Principles and Practice Using C++". With my PowerBook, it wasn't too difficult at the beginning, but then after a couple of chapters it started getting really hard, and I just dropped it. I have come to realize that book isn't easy to follow as a beginner (working independently).
Then in the fall I bought a netbook and began using Linux for the first time. Early this spring I started going through "The C Programming Language" within a Linux environment. A lot of things (emacs, gcc, gdb ... even how to execute a file, how to change permissions to make it executable, how to navigate simple bash commands), I had to work through trial and error, it was very slow.
I think that if you as an instructor can make those things easy to work through and fill the gaps that Kernighan & Ritchie assume the students have, then it should work. Once yoiu get past that other stuff, as a beginning student it's really nice to have something explained in a very clear and understandable manner. For me, it combines a well-written text with exercises. Definitely though, some of the students will require more support with the problems. Sometimes I spent a week just working on one problem and it was very frustrating.
Is C the right language to teach undergraduate engineers as a first language?
A Brief language comparison.
Basic
DIM A As String = "Hello"
DIM B As String = "World"
DIM C As String = A + " " + B + "!"
C++
string a = "Hello";
string b = "World";
string c = a + " " + b + "!";
C
char a[] = "Hello";
char b[] = "World";
char* c = malloc(strlen(a)+strlen(b) + 3);
strcpy(c,a);
strcat(c, " ");
strcat(c,b);
strcat(c,"!");
/* don't forget to call free(c); */
Now, which do you think you should be teach to folks who've never seen a text editor?

Need Help Understanding Compilers/HLL->Assembly

I am an electronics student and I have programmed mostly in Assembly. Last night I saw an amazing article that discussed writing a compiler in Ruby. What the author had done was use GCC to peek how the C translates to Assembly. That resonated a lot for me. I could finally see how the C program translated to Assembly.My question/request to the community here is: Could you show me resources that discusses the link between those two better? Should I be reading about compilers? Should I be learning System programming? I dont know what to do. I really want to be better at programming and learn this better. Thank you for your help.
Related:
Learning to write a compiler
Is it beneficial for a programmer to learn how to build a compiler?
Can someone tell me the very basics of how computer programming works?
and others...
There really are a couple things going on here. First thing you should look at is something like a compilers book. There are several old ones, like the famous Dragon book, that are very good. I just discovered another one today, through, from the same guy who wrote the Art of Assembly Language Programming, on How to Write Great Code. I've only read the sample chapters so far, but it looks very good and also seems to address just what you want without dropping immediately into the wonders of LALR(1) grammars and so on.
"Systems programming" is more about, well, programming systems. In a systems programming ouse, you learn about using various system calls and other stuff to build useful programs. You need to know that too, but it's a different track than "how it happens."
A computer organization book, like the one aaronis refers to, is more about how the program gets from the assembly language level to actual gates and such. It's also called "computer architecture", as the phrase was used when Amdahl, Blaauw, and Brooks invented the term: instruction sets, how they're implemented, and how you make quantitative choices in the design of the things.
The classic reference text on compilers is Aho and Ullman, Principles of Compiler Design, aka the dragon book. The current edition has a few more authors and an updated title....
Compilers: Principles, Techniques, and Tools
When I took a Computer Organization class they went through the low level details of how processors have come to be, how they process instructions, and how assembly is translated into machine code. Maybe a little lower than what you are looking for, but I think getting a glimpse of how this type of translation occurs from a higher level language to a lower level language is really neat. I think we used this book or one similar:
http://www.amazon.com/Computer-Organization-Design-Interface-Architecture/dp/1558606041
Another good resource is Alan Holub's Compiler Design in C.

Teaching myself C in 21 days

I've spent (on and off) the past two and a half years learning C, from books like the k&r. I soon came to the realization that I found the prose difficult to understand, etc. I read the "Teach yourself C in 21 days" book first, but I couldn't even understand it. Now that I have a fair knowledge of how to use the fundamentals of C (this doesn't include pointers/structures, but basic design) I was thinking of reading the Teach yourself C in 21 days again, from pointers, so I can start working on programs. I didn't finish the k&r because of its level of difficulty with it's prose, and some of the exercises. I know a score of people that didn't even use books to learn how to code. So, I'm asking, if anyone thinks is a good idea that I just read the 21 day book, and move forward from there, and read more advanced books like APUE or, expert C programming, and so on.
It's prose is simple to understand, and I really want to get into some projects, where I'd probably realize certain pitfalls for myself.
Could you give me any advice. I'm not in a hurry, but I'm eager to get things done!
K&R is the best book to learn C from, IMO.
I agree with Peter Norvig: It's not possible to proficient in anything in 21 days. All you're trying to do is get a feel for the syntax so you can start writing simple programs.
I think you need to start writing some simple programs as soon as possible. Try out what you know and get comfortable with that. Then read a new chapter and try that out.
Writing code brings it to life. Reading books is very dry. I sometimes read a book from start to finish to learn a new language, but that's only because I've learned so many languages by now that I'm not learning the concepts - just the syntax and the odd novel feature.
=== From my personal experience and IMO, you are doing it backwards. Start with Hello World! ===
When I am learning a new programming language, I don't just say I "will learn this language because I hear it is good to learn". I need to have a reason to learn the language. Otherwise if I don't have a reason to learn the language I will not learn or retain anything I read about the new programming language.
I learn by doing and that is why I start with doing the "hello world" example.
C is not the most user friendly language and does not have many "easy small programs" that you can implement and do something cool with... and that is why it is hard to get into.
And that is why I think you really need a good motivator to learn C.
Right now the current motivator you have is "I should learn C because people say it is good to learn" ... and I don't think that is enough of a motivator to learn C. One suggestion would be to write a GTK GUI application in C... that will teach you a lot about C and the end product will be something very concrete and cool to point to ( hence a good motivator ).
The fastest way to learn is to need to know it. If you've got a problem you need to solve, say, you need to calculate an optimal tournament order for your community's soccer teams, then you will be better motivated to learn how to solve the problem. You will end up encountering one difficulty after another as you learn, but they will always be of the form 'my program doesn't do x' rather than 'i don't really get x'. Each exercise of fixing each shortcoming will teach you new things about the language and how to use them. The added benefit of having a clear goal in mind, with many small successes along the way will keep you energized and provide positive feedback to your learning.
The K&R C book will provide you with just the right tools to approach a problem using C idioms.
If you need some generic ideas for problems to solve, try projecteuler.net, or search for related questions here on stack overflow
Gosh, 2.5 years seems like an awfully long time! I used to be an instructor with a commercial training company and our C course, which covered the entire language including "advanced" stuff like function pointers, only took 4 days! Which bits are you finding particularly difficult?
K&R is a great book (maybe it is all you need to earn C) all you need is some patience and hard work
Use those 21 days by doing the exercises in K&R.
Pick easy ones first. When you get stuck, you can ask Stackoverflow. ;)
The best way for you to learn C is to put in practice the topics you are learning.
For example if you are going through basic principles like looping and if statements, you can build yourself a little program that simulates the functionality of counting changes on a vending machine.
Once you move on to more advanced topics like pointers and data structures you can build a Logo like program. The user can input each step of the turtle's movement, and you can store that in a linked list. Afterwards you can perform pointer operations on your data structure by deleting, reversing, or adding nodes.
So the idea is to start coding to test what you learned. You will find that some of the time you don't really understand even though it seemed clear in the book. As a good programmer you will end up having to revisit the topics until you actually know it.
Teaching yourself C in 21 days is like teaching yourself handgun safety in 2 minutes. The results of either are undefined, except C lacks a safety or decocking mechanism.
In reality, its going to take the better part of two years to achieve any kind of definition of proficient. You'll gain this by shooting yourself in the foot, repeatedly, while learning from a determination to tackle practical problems using C.
It takes the better part of 9 months to discover blinking, while blinking is a very complex process, C is not always instinctual.
I think you have to use some libraries like GWT because we learn more when we see how to use the code of other people. And doing some UI is far more motivating than writing console apps. It's funier to manipulate Windows, Button, CheckBox than int, float, double (and not so much difficult).
First of all, if you have no programming experience at all, you can't learn a language in 21 days. You will need at best several months.
On the other hand, if you have programming experience, my opinion is that the best thing you could do is find a "cookbook", like the ones available here. I think Deitel had something like a C cookbook, you should visit their site and see. After you find a book like that, you have to start writing code, all sorts of code, to cover most of the problems that you could encounter while working on a project: memory management/data structures,input/output,networking,etc.
Good luck!

After K&R what book to use to learn programming in plain C? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
After The C Programming Language by Brian Kernighan and Dennis Ritchie, some of the books most favoured by beginners turn out to be ones best avoided, such as anything by Herb Schildt or even the O'Reilly Practical C Programming, and there doesn't seem to be much alternative to these. Otherwise most of the material available is about C++.
Besides K&R and the excellent C: A Reference Manual which I have already, what other books are the best to use for learning to code in C, (plain C89 and not C++), without learning bad practices along the way?
Peter van der Linden's Expert C Programming: Deep C Secrets
C: A Reference Manual by Harbison and Steele
It's not a tutorial book, but it's hands-down the best book on C (even over K&R in my opinion). Used in conjunction with K&R (or any other tutorial), you'll get a great foundation in C.
This explains why Schildt is bad. Some more criticism here.
Search SO for C resources.
I would be tempted to read Practice of Programming and Programming Pearls. Both are quite terse books and C orientated
K&R essentially covers everything you need to know about C, and even implements a few data structures that are commonly used. If you're using *nix and want to learn how to take advantage of the operating system, Advanced Programming in the UNIX Environment, Third Edition is a good reference/guide to common uses such as reading a file, creating threads, etc. Sample code is in C.
I'd say to eschew the books entirely. Pick a project, any project (although not too large), and implement it in C. There's no substitute for simply jumping in and doing it. K&R gives enough knowledge that you can begin stumbling along and gaining the experience that makes for true good learning.
I like Pointers on C by Kenneth A. Reek. I won't do so far as to say it's better than K&R but I certainly found it more friendly and easier to learn from. I started with K&R, but didn't really get a hang of C until I picked up this book.
Edit: I also just found out that the price of this book has skyrocketed since I bought it. So while my recommendation still stands as such, I cannot really recommend it at the current asking price. So if you can find a used copy or a copy at a library then it's worth getting, but at its current price there are other books that are basically just as good for a lot less money.
Expert C Programming is book I consider worth at least looking through once you've gotten the hang of C, although I'm hesitant to outright recommend it. On the plus side it contains a number of good tips and tricks and some very useful advice. On the minus side those tricks and pieces of advice are badly organize, buried among not so useful advice and half the book seems filled with lame jokes, asides and irrelevant (but occasionally amusing) stories. So I'd borrow it from the library, but not pay money for it.
But as you no doubt realize, you'll never really learn C until you write C.
Pick up your K&R book again, and this time do the exercises. Then compare your code with the code in K&R and see if it has similar elegance in the function interfaces and data structures. This isn't a book to read through quickly and go to the next book. It contains a lot of valuable information, and the exercises will help you to realize some of them that you probably missed on the first reading.
C unleashed.
Beginning C by Ivor Horton (3rd edition) from APress is a great introductory book on C programming. This book is very thorough and is not a reference book but a good tutorial from start to end on everything in the C language.
Beginning C by Ivor Horton (3rd Edition)
A great book to learn C is:
C BY DISSECTION The Essentials of C Programming by Al Kelley & Ira Pohl
Very easy to read wth lots of great programming examples.
The best textbook on C I have is C: A Software Engineering Approach by Peter A. Darnell and Philip E. Margolis. While it is (undeservedly) not as famous as other books, I found it very readable and it handles all the details K&R skips over.
It has two disadvantages though:
It is from 1996, so it does not cover C99. (This should be fine with you since you are interested in C89.)
It is quite expensive.
Edit:
Another book of interest is C Programming FAQs by Steve Summit. While I don't have this book in print, the accompanying web site helped me a lot in understanding the less obvious features of C.
I might also recommend reading C programs. Sadly I haven't done enough of this myself to recommend particular ones.
There are some brief but helpful reviews at (the Russian mirror of) the ACCU, for beginner's C and for advanced C.

Resources