Actually, reading through Essential C, it hasn't really been updated for C99 since it uses C89 declarations:
C takes the middle road -- variables may be declared
within the body of a function, but they must follow a
'{'. More modern languages like Java and C++ allow you
to declare variables on any line, which is handy.
Oh, memories. I took CS107 in 1996, which was apparently the date this handout was written. Nick was my academic advisor, and his CS108 (which was C++ at the time) was one of my favorite courses of all time. Bunny World...
Maybe I'm just a grumpy old programmer, but I feel like kids these days are missing out on something important by learning to program in a language that doesn't require them to truly grok memory management.
Most often, in general purpose programming, you don't need burden of managing memory manually. Things just go fine with a good runtime.
And that is what I think beginners should be introduced to - how to write code, how to frame algorithms in your mind and convert them into lucid code. Python does all of this wonderfully. It hides all of the internal details and exposes just the part that is needed for sometime writing a computer program for the first time in their life - simple statements which do simple things.
There is no need for a beginner to understand memory management at all. Trying to understand what is code or how algorithms work is more important to build that mental capacity IMO. Pardon me, but it does seem that just because you had to undergo the pain of trying to understand pointers, memory layout and allocations, you want everyone to go through the same experience as well.
Show me a Haskell programmer who doesn't understand memory management. You are grumpy, and I am older, but all memory is managed.
I recently ran into someone that was teaching a Python boot camp and they were forcing the students to use VIM instead of PyCharm, and in their words, "using a text editor requires them to memorize apis".
They didn't know about type inference, rename, extract method or navigate to declaration. I view it as the same bias, the attitude doesn't encourage people to use the best tools for the job because we suffered in the past. How about we go back in time and teach young selves how to write code than actually use 2TB of main memory and 128 cores using a dev environment that can scale to millions of lines of code.
As an undergraduate senior in the CS program at the University of Washington, I can definitely attest to memory management giving the majority of people a really hard time in our required C course. I've only talked to one other person in my cohort that likes programming in C, and unsurprisingly they don't have any trouble with the finer points of it at all.
Most of my classes were taught in Java, but I took care to also learn and do a lot of work in C++. I've also played around with disassembling various binaries (especially code actually written in assembly, like DOS games). Teaching myself to manually track the state of the stack, and see how it was used in function calls, was eye-opening in a way similar to learning manual memory management.
I recently started a graduate course that originally required C++. My only exposure to C++ basically went through the fundamentals of the C part without getting to any of the ++.
Is there something similar to this for C++? I understand that C++ is a much larger language and I'm definitely not looking for something comprehensive, more of a solid overview of a workable subset of the language. Enough to be productive, produce reasonably modern idiomatic code that can be improved or expanded in the future.
In the end, the graduate course ended up using Python, but I'm still somewhat curious about modern C++.
In a similar situation, I constructed a crash course using a combination of Accelerated C++, for succinctness & idiomatic C++, and Statistical Computing in C++ and R, for language features relevant to my graduate field.
Great little resource on C programming and data structures. I had a lot of fun going through the problems presented in the Linked List and Binary Tree sections [1].
Does anyone have any recommendations for a document like this that describes how NOT to write C? Like the security issues and tricks to avoid the pitfalls?
"the compiler "promotes" the smaller type to be the same size as the larger type before combining the values." Values smaller than int are always promoted to int.
"Promotions do not lose information -- they always convert from a type to compatible, larger type to avoid losing information." This isn't true when a signed type is promoted to unsigned.
It seems that the author didn't read the C language specification.
Thanks for this! I've been searching for something like this for a while. So I'll add it to my bookmarks. As I'm currently using Beej's Guide to C to learn and this one looks a bit nicer. Also it's by stanford so that's cool.
The last link to "the great tree-list recursion problem" is an awesome assignment for thinking about pointers. (Though not really in any way representative of useful code.) Still fun to do after 20 years of writing C.
If you're looking for something quick, then a Brainfuck interpreter shouldn't take longer than an afternoon, and a simple one will be a couple hundred lines. Optimising it though, can be more difficult and is one of those things you can keep working on for ages.
If you're looking for a challenge, a JSON parser is a more involved project, especially if you implement your own HashTable structure for storing things.
If you want something to be proud of at the end, then you could always try your hand at glitch art. Grab an image file, read it, manipulate it, and output it again.
CS50 [0], if you're just getting started. It's Harvard's entry course to Computer Science, free, and covers most of the knowledge a beginner needs to get started.
I'm not sure of any. I do a bunch of embedded C code. I find a lot of C code tutorials are algorithm / datastructure focused. Which is ok to learn. You should definitely feel confident in implementing data structures / algorithms in C. But I'm not sure of any good tutorials which teach you how to engineer C programs. There is no "one true approach" but you definitely need to take "a" approach to constructing C programs. You need to have really good convention about how to do various things and how to compose your software.
Also C unit testing is often rare. I ended up writing my own framework (which I open sourced, but am neglectful with maintenace) with the idea you can run tests on embedded devices. Meaning it only relies on pretty vanilla C and has no memory allocation.
But, definitely incorporate unit testing in your C coding experience. It will help focus you on not falling for the evils of the language
When i was about 13 or 14 years old, i read Brian Kerninghan & Dennis Ritchie's "The C Programming Language". This book (by the language creators) is a classic and does an excellent job of explaining the C language. I learnt C by reading that book and experimenting writing code.
It is a very good book and it should be easily available.
[+] [-] CalChris|8 years ago|reply
Modern C [1] covers C11 and was mentioned before. However, it weighs in at 300 pages rather than Essential C's 45.
[1] http://icube-icps.unistra.fr/img_auth.php/d/db/ModernC.pdf
Actually, reading through Essential C, it hasn't really been updated for C99 since it uses C89 declarations:
[+] [-] bangonkeyboard|8 years ago|reply
[+] [-] bstrong|8 years ago|reply
Maybe I'm just a grumpy old programmer, but I feel like kids these days are missing out on something important by learning to program in a language that doesn't require them to truly grok memory management.
[+] [-] agnivade|8 years ago|reply
And that is what I think beginners should be introduced to - how to write code, how to frame algorithms in your mind and convert them into lucid code. Python does all of this wonderfully. It hides all of the internal details and exposes just the part that is needed for sometime writing a computer program for the first time in their life - simple statements which do simple things.
There is no need for a beginner to understand memory management at all. Trying to understand what is code or how algorithms work is more important to build that mental capacity IMO. Pardon me, but it does seem that just because you had to undergo the pain of trying to understand pointers, memory layout and allocations, you want everyone to go through the same experience as well.
[+] [-] sitkack|8 years ago|reply
I recently ran into someone that was teaching a Python boot camp and they were forcing the students to use VIM instead of PyCharm, and in their words, "using a text editor requires them to memorize apis".
They didn't know about type inference, rename, extract method or navigate to declaration. I view it as the same bias, the attitude doesn't encourage people to use the best tools for the job because we suffered in the past. How about we go back in time and teach young selves how to write code than actually use 2TB of main memory and 128 cores using a dev environment that can scale to millions of lines of code.
[+] [-] d-crane|8 years ago|reply
[+] [-] khedoros1|8 years ago|reply
[+] [-] ryanatallah|8 years ago|reply
[+] [-] zeugmasyllepsis|8 years ago|reply
Is there something similar to this for C++? I understand that C++ is a much larger language and I'm definitely not looking for something comprehensive, more of a solid overview of a workable subset of the language. Enough to be productive, produce reasonably modern idiomatic code that can be improved or expanded in the future.
In the end, the graduate course ended up using Python, but I'm still somewhat curious about modern C++.
[+] [-] lost_vegetable|8 years ago|reply
[+] [-] smnplk|8 years ago|reply
[+] [-] michaericalribo|8 years ago|reply
[+] [-] banned1|8 years ago|reply
https://www.amazon.com/Advanced-C-Programming-Styles-Idioms/...
[+] [-] bstrong|8 years ago|reply
[+] [-] mypalmike|8 years ago|reply
"Effective C++" by Scott Myers
[+] [-] imwally|8 years ago|reply
[1] https://github.com/imwally/cmuck
[+] [-] reacharavindh|8 years ago|reply
[+] [-] mmjaa|8 years ago|reply
https://www.amazon.com/Expert-Programming-Peter-van-Linden/d...
Every C programmer should have this on their bookshelf!
[+] [-] Vindicis|8 years ago|reply
[+] [-] tempodox|8 years ago|reply
Also, consider looking into MISRA C guidelines. They contain many related tips.
[+] [-] nwellnhof|8 years ago|reply
"the compiler "promotes" the smaller type to be the same size as the larger type before combining the values." Values smaller than int are always promoted to int.
"Promotions do not lose information -- they always convert from a type to compatible, larger type to avoid losing information." This isn't true when a signed type is promoted to unsigned.
It seems that the author didn't read the C language specification.
[+] [-] ateesdalejr|8 years ago|reply
[+] [-] akkartik|8 years ago|reply
[+] [-] mountaineer|8 years ago|reply
[+] [-] shakna|8 years ago|reply
If you're looking for a challenge, a JSON parser is a more involved project, especially if you implement your own HashTable structure for storing things.
If you want something to be proud of at the end, then you could always try your hand at glitch art. Grab an image file, read it, manipulate it, and output it again.
[+] [-] oweiler|8 years ago|reply
[+] [-] oweiler|8 years ago|reply
[+] [-] thegabez|8 years ago|reply
[+] [-] shakna|8 years ago|reply
[0] https://www.edx.org/course/introduction-computer-science-har...
[+] [-] keithnz|8 years ago|reply
Also C unit testing is often rare. I ended up writing my own framework (which I open sourced, but am neglectful with maintenace) with the idea you can run tests on embedded devices. Meaning it only relies on pretty vanilla C and has no memory allocation.
But, definitely incorporate unit testing in your C coding experience. It will help focus you on not falling for the evils of the language
[+] [-] flavio81|8 years ago|reply
It is a very good book and it should be easily available.
[+] [-] O_H_E|8 years ago|reply
[+] [-] aynlaplant|8 years ago|reply
[deleted]