LEARNING C THE HARD WAY PDF

adminComment(0)

Contribute to hatemBT/Template-learn-C-in-the-hard-way- development by creating an account on GitHub. Python is Learn Ruby The Hard also a great Way language. Learn Python The Hard Way Introduction: The Cartesian MAIN Dream Of C PREVIOUS Whatever I. Visit redelocidi.tk for a complete list of available publications. Learn C the hard way: practical exercises on the computational subjects you keep.


Learning C The Hard Way Pdf

Author:LUKE BUEHRING
Language:English, Indonesian, Arabic
Country:Lithuania
Genre:Technology
Pages:443
Published (Last):17.06.2016
ISBN:819-4-29211-619-9
ePub File Size:28.32 MB
PDF File Size:19.66 MB
Distribution:Free* [*Register to download]
Downloads:33789
Uploaded by: BRIGETTE

Learn C The Hard Way (LCTHW) is a practical book teaching real world useful C .. Zed A. Shaw, you'll get a professional quality PDF and hours of HD Video. Of course I learned it the hard way. If you can learn C while sitting on broken glass, scorpions in your underwear, and with your hands on fire. Zed Shaw is a pseudoscientist who claims that copying code examples from his over priced book is the best way to learn a language. Nowhere.

What I find to be really sad, is that despite the author's best intentions, this book is really lacking enough information to be a useful resource for a novice developer. At the end of this piece, I'll give some final thoughts. Part 1: The Introduction Now, let's begin ith the introduction. First, a quote from Descartes, then a paragraph with the insinuation that most programmers are somehow afraid of C, likening it to " While I'm certain there are many people who are in fact afraid of writing in C, I'm certain that their apprehension stems from inexperience and a lack of specific domain knowledge rather than emotional fear.

It's true that one must be more aware of what they're doing in C, than in higher-level languages. With greater power comes greater responsibility.

The higher-level languages to which a lot of aspiring C programmers are accustomed, such as Ruby and Python, provide abstraction layers that handle a lot of things for you.

In C, you have much more control over what your program is doing, and also much more potential for breakage. To the uninitiated: Keep in mind that both Ruby and Python are in fact written in C.

The author apparently feels that writing code in C is inherently dangerous, but that writing code in more abstract languages makes one inherently stupid. Perhaps he meant to say, ignorance? It's an ironic quote, considering the author has published two other works dedicated to higher-level languages: The C programming language's only failing is giving you access to what is really there, and telling you the cold hard raw truth.

C gives you the red pill. C pulls the curtain back to show you the wizard. C is truth.

Learn C The Hard Way

Why use C then if it's so dangerous? Because C gives you power over the false reality of abstraction and liberates you from stupidity. Shaw, "Learn C The Hard Way", Introduction I'm not going to say too much about the rest of this section, it's not terribly interesting.

Mainly the same sort of introductory filler you'll find in any "How-To" book. Part 2: The Setup Reading this section, I do agree with the last sentence in this block: You can write C code for Windows, that's not a problem. The problem is all of the libraries, functions, and tools are just a little "off" from everyone else in the C world. C came from Unix and is much easier on a Unix platform.

That's a matter of historical record. But to say that on Windows everything is a little "off", doesn't quite do it justice. I understand that the book is aimed at the uninitiated, but to put it that mildly is an understatement of epic proportions. When it comes to setup instructions, it doesn't appear that the author went to any length to describe how one's environment should be set-up.

In my opinion, second only to the importance of learning the language itself is knowing how to use it within your environment.

For Mac OS X, the author writes The author of a "How-To" book says, "Google it! The Winblows users are stuck with the empty promise of: For Windows users I'll show you how to get a basic Ubuntu Linux system up and running in a virtual machine so that you can still do all of my exercises, but avoid all the painful Windows installation problems.

There's still good 'ol Cygwin. BSD isn't even mentioned, and apparently the only installation methods for Linux are apt-get and yum. They are the worst tools if you want to be a good programmer because they hide what's going on from you, and your job is to know what's going on.

They are useful if you're trying to get something done and the platform is designed around a particular IDE, but for learning to code C and many other languages they are pointless.

However, this whole paragraph, like a lot of the opinions the author presents, is merely a fallacy. There are plenty of people getting things done all day long with IDEs, and as far as IDEs that support multiple programming languages, Eclipse comes to mind. Part 3: Getting Acquainted with the Compiler Finally, we start getting down to something concrete. Then prompts the user to invoke make to build it. Let me clarify. I am well-aware of make's implicit rules.

Those who've felt the need to pick on this point are either being really pedantic for which I congratulate you , or they're missing the point made later in the paragraph, in addition to the running "Jimmy Hoffa" joke -- which is an analogy for most of the "setup"-type instruction you would expect, that fail to appear in the author's book entirely or appear, confusingly later than the tools they correspond to.

Besides, what's the point of being a critic if I can't have a little fun poking a little fun at it along the way? Wait a tic Where's the Makefile? Am I just supposed to imagine it into existence? I find this to be really bad form on the author's part.

He should have started by waking the user through invoking the C compiler to build it, explained the steps in brief, etc. He then goes on to explain what a compiler warning is, etc. If I were a novice programmer reading this book, I would be completely lost as to how to build this "Hello World" program.

Part 4: Make is the new Python Even the title of this section is wrong on so many levels. There's absolutely no correlation between make and python. They're two completely different things. Even in an attempt to oversimplify for the purposes of explanatory imagery, why would write something so blatantly confusing? What if the reader has no experience with Python at all, and doesn't even know what it is?

The author is making an assumption here that not only is the reader a novice in terms of C, but Python also. C is a different beast completely where you have to compile your source files and manually stitch them together into a binary that can run on its own. Doing this manually is a pain, and in the last exercise you just ran make to do it. Now, we have a section about make and still no Makefile. Now, the author continues to say how using this non-existent environment of ours is really painful.

It appears he also forgot about the separation of responsibilities between the compiler, assembler, and linker in most toolchains these days. Quite an oversight for someone writing a presumably "modern" book.

The difference is, I'm going to show you smarter Makefile wizardry, where you don't have to specify every stupid little thing about your C program to get it to build. I won't do that in this exercise, but after you've been using "baby make" for a while, I'll show you "master make". Not to mention the fact that all the examples thus far have been broken, presumably to force the user to make a common mistake so that they learn from it, but this book's "benefit of the doubt" allowance is starting to run out.

Part 5: Formatted Printing So, finally printf gets introduced. The author fails, in my opinion to explain what it actually does. This has the reader using format strings before even explaining even briefly what a format string is.

This has become a repetitive theme in this book, and if I were a novice, I'd find it very confusing. The code the author presents here is pretty straight-forward. Keep in mind the declaration of main here. But I found the explanation a little tiring to read, and slightly confusing: First you're including another "header file" called stdio.

One of those is printf. Then you're using a variable named age and setting it to Next you're using a variable height and setting it to Then you use the printf function to print the age and height of the tallest 10 year old on the planet.

In the printf you'll notice you're passing in a string, and it's a format string like in many other languages. After this format string, you put the variables that should be "replaced" into the format string by printf. Shaw, "Learn C The Hard Way", Exercise 3: Formatted Printing So, in summary, printf takes something called a "format string," and some variables, gets the age and height of the tallest year-old on the planet, and replaces my variables.

That's a bit creepy. Part 6: Introducing Valgrind Let's recap. I don't know how to set-up my environment, this "Makefile" thing pulled a Jimmy Hoffa, and now I have to use this Valgrind thing, after I go download it and build it from source. While I think it's great the the author wants to teach the reader how to use tools that will help them find memory leaks, etc.

Part 7: The Structure of a C Program In this section, the author presents a simple program, and then breaks it down line-by-line. I'd have expected this a bit earlier on. This bit about the main function definition is just wrong: ex5. Again, the author is oversimplifying things.

But to be fair, I've never written a book about C. Part 8: Finally, format strings explained! Seems to me that the author has a penchant for delivering information a bit too late. It's in this section that format strings used by printf are finally explained, along with some sample code, and a brief explanation of data types which the author terms "variable types". Note the key phrase terminated by An array of characters need not be null terminated.

Remember these definitions, they will be important later.

Learn C The Hard Way

Here's an example from the standard that illustrates this difference. In this example, s is a string, while t is not, as it is not null terminated. You're damn right I am. The difference in this case can be very important. Further on in this bit, the author prompts the user to trigger a segmentation fault by passing an invalid pointer to printf, with no explanation as to what it is, or why it happens. Honestly, I find this to be a recurring theme in this piece. The author throws the reader a curveball without having even told them that a ball even exists.

The next parts of the book contains more of the same. Part 9: Data Types part 2 Now that the author is calling data types by the correct term, he's also again misleading the reader about what these types are.

Part 2: The Setup

This is also the first place with any mention of integer signedness. This is almost completely wrong: int Stores a regular integer, defaulting to 32 bits in size. This is why we have limits. Hell, I can have a machine with bit long, bit int, and bit short; and it would be perfectly standards compliant so long as I define the sizes appropriately in limits.

In the next sections, the author covers scope, the stack, and even Duff's Device. Talk about confusing for a novice, who'd be thinking by this point, "Wait Duff's Device Is that some new kind of beer opener? Even though you have no Makefile, you haven't found Jimmy Hoffa yet, and there's been hardly any explanation of how to invoke the compiler. So, I'm just supposed to poke in some code, go to my terminal, type this magic 'make' word, and expect a built and working program, right?

The latter parts of the book touch on using gdb, the linker, make finally in "Exercise 28" we get a Makefile , unit testing with some weird macros, introducing some over-engineered, poorly-written data structures, etc. Things like this and this and this would be enough to make a C programmer cringe For now, just keep in mind that this function is part of a larger example and is being interpreted out-of-context by the author. So, I'm going to play into that.

This function copies a string from from to to. Why is he picking on this one particular function out of all the others in the book? He writes: When people talk about problems with C, it's concept of a "string" is one of the top flaws. You've been using these extensively, and I've talked about the kinds of flaws they have, but there's not much that explains exactly why C strings are flawed and always will be.

I'll try to explain that right now, but part of my explanation will just be that after decades of using C's strings there's enough evidence that they are just a bad idea. Any loop that processes an invalid C string will loop infinitely or, just buffer overflow. All of these are important data structures and I think it is a good choice to get them right immediately at the beginning of learning a new language. Most of the exercises are typing over the code which is presented in the book.

Afterwards you often have to improve the code you just wrote. I think that this is a good book to get the basis of the c programming language. Also, the table of contents of this book was promising, as it seemed to fill in some gaps quite well that were left by Stroustrup's book, like macros, build systems, unit testing, etc.

So I went and bought the book and started to read it with quite the enthusiasm, but this enthusiasm was unfortunately eroded away step by step as I was going through it.

I must stress here, that I really wanted to like this book, but I can't say that I feel that way any more. The book starts pretty promisingly, as it introduces you to some of the basic C syntax, and then it gradually builds on previous chapters with some rather good and challenging extra exercises.

But as you are progressing through chapters, the quality seems to deteriorate. The first problem comes with misaligned if compared to the text or completely missing line numbers for code, which issue persists throughout the entirety of the book. Later, "misaligned chapters" and "misaligned exercises" appear as well.

Code quality also seemed problematic a few times, especially after reading R. Martin's Clean Code and R. Osherove's The Art of Unit testing. I was also wondering about the choice of topics and the amount of explanations presented from time to time, but that, I know, is highly subjective. So let's go into some specifics. The line number issue is pretty straightforward, so I'll just skip that and continue with "misaligned chapters and exercises".

At the end of each chapter there are some exercises that are meant to make the information mentioned in the chapter sink in better, and a lot of them does a pretty good job at that at first, but later some exercises start to require of you to use and do things that will only be explained in the next chapter. Here one could really wonder which of the two is unnecessary, as if you manage to figure out the solution, then why do you need the next chapter, but if you have a chapter for it later, why require something like that beforehand?

In an other instance, some highly interrelated topics types of data structures are fragmented because of some wedged in chapters. Code quality also seemed to be an issue sometimes, as it went against what is considered to be good coding practice nowadays, at least according to the rather logical views of Uncle Bob. He clearly stated, that code must be as easily readable and comprehensible as possible, but this rule seems to be violated frequently in this book. Some examples include ambiguous variable naming, incomprehensible name abbreviations, being "too smart" about code which is shorter to type, yes, but longer to understand , inconspicuous declarations midfile single line macro definition hidden between large functions , etc.

As mentioned before, I also had some issues with the topics themselves and the amount of explanations used. The title of this book says "Learn C the hard way", but interestingly enough only some part of the book deals with C itself, which I actually liked at first, but only at first. Initially, after getting through some necessary language basics, the book starts to introduce you to debuggers, makefiles, bash scripting, directory structures for development, programmer mindsets, unit testing etc.

But the problem with these are, is that the amount of explanation provided seems to be too short for most of the topics and the complete lack of figures in the book doesn't help either. Breaking the presented code down line by line will make one understand what the presented code does, yes, but it will not teach you how to write something, especially if design choices are not discussed at all.

A good example of this is makefiles. There are two chapters about it, but apart from knowing what the presented makefiles do, I honestly couldn't figure out why the makefiles were written the way they were, because no background information was provided at all. And this is just one example, but the same could go for algorithms, data structures, unit testing, etc. So the general consensus seems to be, that the author basically cherry picked certain parts from larger topics that made it possible to be able to progress from topic to topic, and then put these parts in the book with only short explanations that never go outside the boundaries of the presented code.

And this is where I think it mostly fails as a teaching book. I literally had to spend at least half the time reading external resources to get enough background information about all the stuff. A few helper figures could've helped here immensely, just as every other resource I found used them for a good reason. What is even more puzzling, is why only certain data structures and algorithms were discussed and why many others were simply mentioned in a few words directed to wikipedia basically or omitted entirely.

It must be stressed here, that a considerable amount of the book deals with these things, but what is presented here, is highly selective. So are these chapters needed at all in this fashion? Could these pages have been filled with better content like having more on makefiles, translation units, gdb, gcc flags, etc. Considering, that this book was meant to teach people, I think conveying information as smoothly as possible should be priority 1.

I honestly think that the basic concept around which the book was made is really good, namely trying to be a hands on manual for people who want to program using C, but the implementation unfortunately is not really good. If one has to constantly read immense amounts of outside resources, then what is this book trying to achieve really?

To whom would one recommend this book and for what reason? Is it a hands on manual for C programming? Not really. Is it a data structure book? Will you learn some neat compilation tricks? Firstly, probably yes. If you're selling way below the market price, there's something wrong with your BMW. But leaving that aside BMW M5s are not nearly not as easy to produce or copy as books.

I would appreciate someone telling the world "Don't download this, it's a bad idea. The likely thing that happens with the average C book is that you read the first 10 pages, can't grasp some point that the author is particularly bad at explaining, and wander off to watch a Youtube video or something. Now if your book is so engaging that it prevents this sort of attention wandering, that is a book where you can reliably present this argument. One example from my perspective are the Feynman Lectures on Physics.

I can read them for ages and ages without getting bored.Go back and look at the NEW macro in object. Extra Credit Assign the characters into numbers and then use printf to print them a character at a time. How might you accomplish this crazy hack? I won't do that in this exercise, but after you've been using "baby make" for a while, I'll show you "master make". It will NEXT work as a reference to complete your knowledge, and won't have any code for you to enter.

You need one argument.

Learn C the Hard Way: A Clear & Direct Introduction To Modern C Programming

The main difference, is that the use of C strings is abstracted away, hidden by a struct that also contains a length member. Instead of classes, you start with prototypes that have fields set, and then use those as the basis of creating other object instances. Starting at the top here's what you're reading, line by line line numbers are on the left so you can follow: