12 ms·
Learn C The Hard Way
- newcguy 15y agoI know a fair amount of C. But I am still looking forward to this book as I hear that LPTHW taught something to even intermediate level people. Besides the exercises are usually good and would like to solve them.
- ctdonath 15y agoI look forward to the content. As a beginning C++ instructor I find there is something lacking between the truth of the language and the conventions for presenting it. Nobody, AFAIK save for the truly hardcore student, has nailed it.
- zedshaw 15y agoGot any feedback on the things students get wrong? My experience is they fail to grasp memory management, pointers, functions as pointers, linkers or just how a program actually runs. If you've got others I'd love to hear them.
- forensic 15y agousing gdb?
- palish 15y agoOne of the first programs I tried to write in C++ (my first language) was a chess game. I eventually hacked it together, but it wasn't pretty. The hardest part for me was learning the patterns necessary to do anything, and specifically to do it remotely well. For example maybe one of the exercises could be some kind of board game, where you demonstrate how you translate "the ideas" into "the C code"? For example just because you know that a Knight can move two-plus-one spaces doesn't mean you have any idea where that code should be inserted into the program's structure, or how to write it in such a way where you avoid overrunning an array. (The naive solution would crash when the Knight tries to move off the board.) Translating ideas -> C code was easily my hardest task when I was first starting out.
- nikcub 15y agodedicate some later chapters to ramping the reader onto assembler, the stack (and smashing it) and instructions there are a lot of C devs who don't understand what it is their code is producing, and how an application and memory are managed
- palish 15y agoWhile this is important, it probably shouldn't be in beginner C book. I understand all of it now, but had no idea about the stack or the x86 instructions, etc for years. I was still productive, and wasn't hindered. The details can come later. Even big details like "how it works at the low level". The most important part is to keep things fun; LPTHW was fun. For me, mucking about in assembly wasn't, and that sentiment seems like it might be common among new C programmers. Assembly has a way of slowly steamrolling your motivation.
- eliben 15y agoMy experience as an interviewer showed that in addition to the things you listed, people often fail to grasp binary representation of numbers in a computer at all. This most often comes up when people are asked to do some binary manipulation of numbers, i.e.: unsigned u = 19; unsigned v = u >> 1; "v" is now 9, and to really understand it one must grasp how numbers are represented in binary under the hood. People also fail to understand strings: char* s = "string literal"; To some, it's absolutely opaque that the first byte "s" points to contains 0x73, and that represents "s" in ASCII.
- irahul 15y ago> "v" is now 9, and to really understand it one must grasp how numbers are represented in binary under the hood. Correct me if I am wrong, but I don't think C guarantees anything about the binary representation. Depending on the architecture, `v` can have different value.
- bad_wolf 15y agoIf 19 is represented differently in binary on your platform than (leading zeros)10011, you are already quite screwed. You might be thinking of character representation for the later example.
- irahul 15y agoNo, I was thinking binary 19. Does C say the implementation is going to be 1s complements, 2s complements or whatever? Is there anything that says, for example, it can't be BCD?
- justincormack 15y agoYes even though this is exactly why people want to use C now, to get exact binary behaviour.
- spc476 15y agoC allows differences in how negative integers are represented (at least, C89 did---I'm not sure about C99 as I don't have the standard in front of me). There are three different ways to represent negative numbers in binary, sign magnitude, one's complement, and two's complement (these days, most computers are two's complement). The upshot is that you might end up with two type of zeros (sign magnitude, one's complement) or an unequal range of negative numbers (two's complement has one additional negative number) and taking the absolute value of an integer may not be possible for some values (given a 16-bit integer on a two's complement system, you cannot get the absolute value for -32,768, which is a valid integer on such a system).
- rpearl 15y agoAs a teaching assistant for a class (http://www.cs.cmu.edu/~410/ http://www.cs.cmu.edu/~410/) where students write a whole lot of code in C, please introduce the address-of (&) operator and explain how to obtain pointers without using malloc(). Do this before the concept of the heap is ever introduced at all. Be careful when explaining the compiler and how a program actually runs. I've found that a lot of student problems come from "the compiler is magic" when it really isn't (maybe related to my other surprised comment below, about how people "don't get C"--they attribute too much magic to the compiler.) Maybe even emphasize that every piece of C code can be translated in a fairly easy fashion to a pretty small amount of assembly. For the preprocessor, emphasize that it is a solely textual replacement, with no symbolic evaluation. Explain why: #define FOO BAR + BAZ or #define MAX(x,y) (((x) < (y)) ? (y) : (x)) will go horribly wrong (the first in 5*FOO, the second in MAX(x++, y++)).
- sausagefeet 15y agoI find it is much more helpful, when teaching C, to avoid the word 'address', and call (&) the pointer-to operator. Thinking of pointers as numbers (which the address-analogy does) tends to be harmful for newer C programmers because they want to treat them like numbers.
- palish 15y agoThey are numbers (either 32-bit or 64-bit). Nothing more, nothing less. I don't understand why you wouldn't want to think of them that way. For example... const char* current = "ohai thar"; const char* end = current + strlen( current ); assert( end >= current ); size_t bytecount = (end - current); (size_t is an unsigned type, so if 'end' is less than 'current', it will overflow. If you want to allow for that, use ptrdiff_t.)
- sausagefeet 15y agoNo, they aren't numbers. The standard is quite clear on this. Consider old DOS architecture where you had a section and offset. Your code is also not well-defined C. C only lets you perform subtraction between two pointers in the same block, this code is at best implementation defined and worst undefined (I can't remember).
- signa11 15y agoimho, please do have a look at "expert c programming" it is quite nice. the conversational style of the book makes it very enjoyable to read.
- synacksynack 15y agoThe arrow operator and identifiers with leading underscores seem to be glossed over or skipped fairly often in education. It's intimidating to look at code that uses them if you don't know what they are.
- palish 15y agoIdentifiers with leading underscores? I use those for member variables... (this makes more sense in C++ without the arrow notation.)
- __rkaup__ 15y agoMaybe he's referring to how identifiers with leading underscores followed by a capital letter are reserved in C++ (I'm not sure if they are in C)...
- palish 15y agoOho. Followed by a capital letter? Interesting. I always thought that "all identifiers with a leading underscore were reserved". I just consciously ignored it, and have never had a problem in years. But I was also always using member variable names like "_children", "_childCount", etc, not "_Children".
- __rkaup__ 15y agoIn fact, here's a reference: http://msdn.microsoft.com/en-us/library/e7f8y25b(v=vs.80).aspx http://msdn.microsoft.com/en-us/library/e7f8y25b(v=vs.80).as... (It's in a "Microsoft Specific" block but says it's part of the ANSI C standard.) It applies to C, and it also applies to identifiers staring with two underscores.
- spc476 15y agoThe C Standard reserves identifiers starting with a leading underscore for the system implementation (C standard library, Posix libraries, etc). They aren't meant for use by user code (or rather, you can use them, but they might conflict with system defined identifiers).
- sausagefeet 15y agoIn my opinion the thing that many new C developers have trouble with is how large the gap between what their implementation does can be from what the standard says. I think newer C programmers are used to languages that specify a lot more than C does. Try It And See is generally not a useful response for a C question.
- ctdonath 15y agoThe first problem is the notion of absolute precision and detail required to do even the simplest task. The next is how syntax relates to such notions. Then comes mapping the syntax to the task. If they don't grok variables at this point, they're not going anywhere. A lot don't. Above all is the imperative of completion: if they don't make it work somehow, it doesn't work period. I'll try to salvage their work, tell them what to fix, and accept resubmissions - but if it doesn't work, it inherently won't pass the low bar for success.
- sandGorgon 15y agoI'm not sure if this is going to be pure C or a mix of C/C++, but if you're sticking to pure-C, here's a chapter idea: using containers in C. This is the big selling point for C++ : the convenience of STL. In all the projects that I worked, it was one of the important reasons to choose C++ over C. Yes, this focuses less on the language itself and more on the ecosystem around it, but I figured if you have an entire chapter dedicated to "make", then this makes sense as well.
- deleted 15y ago[deleted]
- JoshTriplett 15y agoI've watched and spoken to a large number of beginning C and C++ programmers (and beginning programmers in general) during their first terms of programming in university. I've noticed a few common problems, and I think they all stem from not understanding the details of how a program runs on a real machine: - The concept of a variable, and variables changing over time, seems quite difficult for people to grasp even when explained a few different ways. "x = 5" followed by "x = 12" proves quite mystifying, and "x = x + 1" even more so. People seem to have the most success with the idea that declaring a variable "int x" creates a location x which can hold an int, and you can put things in that location. - Pointers actually don't seem to trip that many people up initially, once they get to that point. However, I don't think people actually understand exactly what they do, so much as memorize the rules for dealing with them. The same idea of a location to put something applies here too. - Any case where the same function gets called more than once often ends up tripping people up; this applies particularly to recursion, but it can happen even when just calling the same function several times. In particular, this often interacts badly with people's understandings of variables. People need some understanding of scope. - Combining several of the above, it would help to have clear explanations of the interactions between pointers, locations, and functions. Bonus for explaining what goes horribly wrong if a pointer refers to something that goes out of scope. That concept requires understanding several different pieces of C and putting them together.
- cubicle67 15y agoI was taught C at Uni, but this was after having done a semester of x86 assembly language so we already had a good grounding in pointers, how addresses work etc. This was our textbook http://oreilly.com/catalog/9780937175231 http://oreilly.com/catalog/9780937175231
- lhnz 15y agoWhen learning a new language, the syntax and exercises which explore this come to me fairly quickly. The difficulties are (a) learning the best way of structuring large blocks of code using the new syntax and tools, and (b) for new programmers: understanding how to convert conceptual rules in my head into algorithms. If you set out to only teach the language syntax and paradigms you are leaving a beginner with a lot of extra work before they can start or contribute to meaningful projects. This is the reason that people learn so much from reading other people's code in open-source projects: most writers skim over trying to teach the most fundamental skill of programming. I do believe it is possible to teach practicalities in addition to theory and if you attempt to do this, you will be doing a lot more than most writers have done in the past.
- ctdonath 15y agoToo often we think of C in terms of commands. C is a matter of _operators_. Consider "=", say in the statement y=1+x=3; Why and how this works is foreign to most beginners. Likewise (ok, this is C++ but the point remains) cout<<1+x; Isn't a command to display 1+x. The output is the result of inserting the computed value into couture. There is a semantic difference. Groking operators early is key to understanding C well.
- nikcub 15y agoI always had an idea of a 'for programmers' series of books for those who know how to program in one language (say, C++, Java or PHP) and wish to pick up a new language eg. 'python for programmers' would not need the first half of it dedicated to explaining strings, loops etc. and could get straight into it from a programmers perspective - a bit like K&R. You could then dedicate more content to explaining philosophy, design decisions, internals, history, politics (learn all the in-jokes ;)), etc. this would also be a good format to learn new paradigms, eg. 'functional programming in scheme, for programmers'
- udoprog 15y agoIndeed, I currently get turned off by most books I pick up, simply because they start out on a too basic general level. If you however dig a little deeper you can usually find stuff that isn't too tutorialish. Like http://www.c-faq.com/top.html http://www.c-faq.com/top.html which has been an extremely solid resource for me.
- zedshaw 15y agoI'm hoping to make this book ramp up faster than LPTHW, since I'm assuming people have either read that book or know one programming language already. However, I'm also a big proponent of practicing the syntax even if you think you're an expert already. It just makes things way easier later on.
- rpearl 15y agoDo people really think C is some mysterious, inscrutable language? "To many programmers, this makes C scary and evil." Is this actually true for people? I find C code generally very easy and straightforward to understand; there's not any magic behind the scenes, like there is in any language that's more "high level" than C.
- ramidarigaz 15y agoMany of the friends I made in my CS classes were terrible with pointers. I never really understood why they didn't grasp pointers, but it was a major stumbling block for them in C/C++
- alderssc 15y agoI would hazard to guess its due to two things: 1) a lack of understanding about how the machine works, and in particular the way the memory is organized; and 2) lack of explanation of why anyone would need to use pointers. Introducing pointers in the context of a linked list, or explaining call-by-reference would probably help make things more concrete.
- younata 15y agoI have friends who had to take an intro to C++ as their first (and only) programming class. I heard them talking about passing arguments to functions as "call by reference" many times, and it was obvious they had no idea what they were talking about, just regurgitating what the instructor said.
- daxelrod 15y agoFor me, the indirection of pointers was one of the fundamental CS concepts that required real effort to understand. Before that point, I had never clearly separated the concept of a variable and its value. It took a huge conceptual leap to think about a variable that didn't hold a value, but rather, the location of a value. It took some serious mental gymnastics to deal with pointers n-levels deep. Mind you, this was actually Perl references, not pointers, so I didn't even have to try to comprehend doing math on them. After a while, of course, it became second nature. My favorite aspect of CS is that every so often, I run into a wall of conceptual understanding that requires completely changing how I think in order to move forward. Have you never had moments like this, or were they just different topics?
- Sapient 15y agoHaving read a fair bit of LPTHW (though I had no actual interest in the language), I am really excited about this. One of the best things about LPTHW was the context it was written in, and if LCTHW is written in the same way, it should be a really awesome read!
- zedshaw 15y agoThat's the idea, although I'm going to assume you know how to use at least one programming language, and probably redirect total newbies to LPTHW if they don't. That should make it easier to ramp up in C and then do cool useful stuff with it.
- Sapient 15y agoThat's awesome to hear. I actually know a bit of C, but it has been years since I used it - so this book seems like a good one to read to 'reboot' my C skills. I'll definitely be waiting anxiously for you to finish. Good luck!
- getsat 15y agoWhy is %d used to interpolate an integer into a format string? I don't recall seeing this done for any reason before. I hope Zed actually covers how dangerous format strings can be if not handled properly. Format strings are still (hilariously) one of the major exploitation vectors in C-based applications today. Edit: According to Wikipedia, %i and %d are synonymous. Sorry for the confusion.
- zedshaw 15y agoIt's not for the type, but for the output. The 'd' means "decimal" output. For example, you can do %x to "hexadecimal" output, and %o for octal. Of course, there's some complex interplay with what type you hand that function. As for how "dangerous" it is, yeah it's not going to rape your family, it'll just crash. So I'll be showing people how to prevent it.
- arkitaip 15y agoZed, your level of productivity is truly inspiring. The best of luck to you.
- mkramlich 15y agoI think the level of self-promotion and/or other-people-promoting-him is the key factor. Not really the supposed productivity. I know many people who get a lot done, both for day jobs, for contract work, as a hobby, as entreprenurial ventures, etc. but 99.9% never hits the front page of HN on a regular basis like Zed's activity seems to. Which doesn't lessen what he does and his skills, but it does pull back the camera a bit to put it into a broader context. Not everyone self-promotes to the same extent as Mr. Shaw, or has other people promote them.
- zedshaw 15y agoI personally have no idea why this stuff hits this site that often. Take this for instance: It is a half-finished manuscript that I announced in a tweet to people who follow me on twitter and asked for it. Already at the top of this set of comments is a dickhead saying he's such a bad ass 'cause he's changed "half a million lines of C code" and he thinks I'm not writing the book correctly because I'm being too low level. He gets all of this from three exercises and three paragraphs in the introduction. Frankly, I consider hackernews kind of irritating and not useful as a promotional tool. It amounts to about 5% of my traffic for 1 day at best, and I only have to be here because if I'm not answering the petty little idiots who troll here then the rumors spread through my professional circles. In other words: I could live without this kind of promotion, so it's definitely not "self-promotion".
- hp 15y agohey, I was just idly chattering about C and the way people in general often approach it. Not intended to be a review of an unwritten book or imply that you plan to approach it in any particular way. I am a bad ass of course. But I thought it was relevant to the comment that I've written a lot of C.
- drivebyacct2 15y agoIt should say "Learn C and make the hard way".
- zedshaw 15y agoOh, there's a lot more tools on the way. C is one language that you could spend whole books on just the tools.
- irahul 15y agoMay be a good idea to mention some of them. `valgrind` and `lint` comes to mind. On second thoughts, `lint` can be dropped; compiler warnings are good enough for a beginner(in fact, good enough for experienced programmers; subjective).
- JoshTriplett 15y agoThe original lint tools seem entirely superseded by modern compiler warnings. On the other hand, a whole new class of static analysis tools exist now, such as Sparse, Coccinelle, Frama-C, and in the proprietary world Coverity.
- briandoll 15y agoI'm very excited to see Zed working on this. This exercise-driven tutorial format seems efficient and practical, but what makes this really stand out is Zed's approach to the overall goal. I greatly appreciate an 'opinionated' programming book. I've probably heard more debates on formatting and style for C than any other language.
- mhm111 15y agogood pic <a href="http://www.f55d.com/vb/index.php/>منتديات http://www.f55d.com/vb/index.php/>منتديات اغاريد الشوق</a> thanx alot its seems so refliction
- derleth 15y agoIsn't "C For Programmers" essentially "HOWTO Use Pointers"? Is there another really complicated idea that C has which most of its heirs do not have?
- palish 15y agoStrings, and why strlen(s) != the number of letters in a string (UTF-8). Why a string must end with a 0 byte. Binary shifting numbers, especially signed numbers. Memory management; it's fun for the whole family, and more than just knowing how to allocate memory and store a pointer to it. Some other points that I'm sure I'm missing.
- Jach 15y ago> Why a string must end with a 0 byte. Unless it's a pstring or you're working with assembly, other language, etc. But yes there is a lot to learn with C you don't necessarily get with higher level languages in most cases.
- mhm111 15y agogood pic <a href="http://www.f55d.com/vb/index.php/>منتديات http://www.f55d.com/vb/index.php/>منتديات اغاريد الشوق</a> thanx alot its seems so refliction
- alnayyir 15y agoI have the "learncthehardway.com" domain, waiting for Zed to stop being so insanely busy so that I can do the hand-off. :)
- cmina 15y agoTruly looking forward to this book!
- pbreit 15y agoHas anyone actually used "Learn Python the Hard Way" in a beneficial way? I started it several times but never got very far and just learned Python from other sources. I didn't really care for the approach.
- irahul 15y agoWas it your first book? If not, you weren't in the target audience from what I make out of the contents of the book. For people who already know programming, the official tutorial is the fastest and the best way to start: http://docs.python.org/tutorial/index.html http://docs.python.org/tutorial/index.html
- tomrod 15y agoYes. I found it useful maybe 70% of the time--more than most texts. The critical factor, IMHO, is clarity and conciseness of writing. Zed does a good job with this (I didn't know his name until this thread, BTW).
- gregjor 15y agoI'll be interested to see how this compares to K&R, which not only teaches the C language but also C idioms and the reasons for using them. K&R is still one of the very best programming books. Every other C book I've read is inferior. Peter van der Linden's "Expert C Programming" is the only book on C besides K&R that I've learned anything from. Good luck, I'm all for more programmers understanding C but I wonder if the wonderful days of programming close to the hardware are ancient history. "[P]eople are deathly afraid of C thanks to other language inventor's excellent marketing against it." Maybe, but I think the raison d'être for C is not apparent to programmers who started with Java, Python, or Ruby.
- irahul 15y agoK&R won't work for someone beginning programming. This book is specifically targeted towards teaching programming to programming virgins. The examples and exercises K&R uses will be very hard for beginners. When it builds a recursive descent top down parser to read the declarations in English(and vice-versa), that will be totally lost on the beginners. K&R wasn't written for beginners and I doubt it will work well for a programming beginner - should be fine for someone who already knows programming in some other language.
- gregjor 15y agoI knew time-shared BASIC before learning C in 1978. I was definitely a beginning programmer then, still in high school. Many (probably most) of the programmers I know from the same era learned programming from books that would be dismissed today as too hard for beginners. In the preface to the first edition Kernighan and Ritchie wrote: "This book is not an introductory programming manual; it assumes some familiarity with basic programming concepts like variables, assignment statements, loops, and functions. Nonetheless a novice programmer should be able to read along and pick up the language, although access to a more knowledgeable colleague will help." Of course that was before the internet, when access to a "more knowledgeable colleague" was harder to come by. In 1978 the only other languages someone would know were Fortran, BASIC, COBOL, Pascal, assembly language, etc. Chapter 1, A Tutorial Introduction starts at the same place Zed's book starts: hello world. Looking at it now I don't see any reason my 13-year-old son (who knows a very little bit of Python) couldn't learn C from K&R with me explaining things here and there -- the same way I learned C. The recursive descent parser doesn't come up until the end of chapter 5 (out of 8), right after quicksort is implemented with pointers to functions. By then the reader has built up some skills and presumably developed enough curiosity to refer to other books for more explanation of sorting and parsers. For me those were Knuth's "The Art of Computer Programming," especially the third volume with all of the great example code which I busily translated to C. If you think K&R is too hard for beginners consider how many programmers learned programming from the badly-typeset and somewhat inscrutable "Pascal User Manual and Report" (1974). That was the programming 101 text used at the local university when I was there.
- auston 15y agoGo Zed! I'll buy this when it's ready for payment!
- tdignan 15y agoIt must be nice to be so established as Zed Shaw such that all it takes to get to the top of HN is a couple C exercises. It's almost like if a mathematician could get publicity for talking about addition and subtraction. With that said, when I first saw Learn Python The Hard Way, it immediately reminded me of the time I spent reading K&R2. Its exercise rich style is what programming books are lacking these days. K&R2 taught me how to program.
- seagaia 15y agoI hope this book will show lots of new C programmers the beauty of pointers in hand-holdy detail ('cause that's the level needed, I feel). Maybe basic stuff about VM, so all the pointer operations make sense (everything is a byte at some offset etc.). At least I didn't fully appreciate C until I understood some of the underlying concepts. Looking forward to reading this!
- hp 15y agoOhloh says I've changed at least half million lines of C code (https://www.ohloh.net/accounts/rhp/positions/total https://www.ohloh.net/accounts/rhp/positions/total) Play me a tiny violin ;-) What kinda bugs me is that whenever people go to teach C, they make out like it _has_ to be a low-level exercise, as if writing in C suddenly means you can't use abstract data types or object-oriented style or name your functions properly or have Unicode support. For example, people teach libc string APIs like scanf() and strtok(), which should almost never be used. (See http://vsftpd.beasts.org/IMPLEMENTATION http://vsftpd.beasts.org/IMPLEMENTATION for one take.) Instead, use http://git.gnome.org/browse/glib/tree/glib/gstring.h http://git.gnome.org/browse/glib/tree/glib/gstring.h or write your own like http://cgit.freedesktop.org/dbus/dbus/tree/dbus/dbus-string.h http://cgit.freedesktop.org/dbus/dbus/tree/dbus/dbus-string.... If you're going to display user-visible text, you are pretty much required to link to GLib or another Unicode library, since libc doesn't have what you need (unless you want to use the old pre-unicode multi-encoding insanity). Don't use fgets() and other pain like that, use g_file_get_contents() perhaps, or another library. (g_file_get_contents is in http://developer.gnome.org/glib/stable/glib-File-Utilities.html http://developer.gnome.org/glib/stable/glib-File-Utilities.h...) You need help from a library other than libc to deal with portability, internationalization, security, and general sanity. Maybe more importantly, a library will show you examples that in C you can still use all the good design principles you'd use in a higher-level language. I told someone to "use a string class" in C recently for example, and they said "C doesn't have classes" - this is confusing syntax with concepts. C requires more typing and more worrying about memory management, that's all. It doesn't mean that all the best practices you know can be tossed. There's a whole lot to be said about how to write large, maintainable codebases in C, and it can even be done. It's not something I would or do choose to do these days, but it can be done. One other thought, two of the highest-profile C codebases, the Linux kernel and the C library, have extremely weird requirements that simply do not apply to most regular programs. However, a lot of people working in C or writing about C have experience with those codebases, and it shows.
- alf 15y agoC shouldn't be used for anything other than low level programming these days. There are other higher level programming language that would make your job a whole lot easier. Some programmers, like me, are stuck maintaining legacy C application code, but I wouldn't wish that fate for new programmers looking to learn C as another tool in the belt.
- helwr 15y agoI learned C the hard way by taking this course, motherfucker http://www.cs.columbia.edu/~jae/cs3157/2009-1/syllabus.html http://www.cs.columbia.edu/~jae/cs3157/2009-1/syllabus.html http://www.cs.columbia.edu/~jae/papers/3157-paper-v2.2-camera-final.pdf http://www.cs.columbia.edu/~jae/papers/3157-paper-v2.2-camer...
- anonymous742 15y agoActually, that looks like a pretty easy way to learn C; a whole semester on it, beginning with things like using ssh? With instructors and TAs? But ooh, Columbia, so you know it's hardkore.
- JoshTriplett 15y agoWhen I first learned C, I did so under DOS, an environment in which you could declare a pointer to video memory, make a magic call, and start drawing graphics. I found that a memorable way to learn pointers. Sadly, doing that in the modern world requires quite a bit more setup.
- zedshaw 15y agoHmmmm, I wonder if you could do that in a similar way...
- cubicle67 15y agoThat's how I was taught assembler. One of our first assignments was to draw a circle on the screen. Second was an etch-a-sketch like drawing programme where you controlled the pixel via kbd. We used int 10h[0] a lot [0] http://en.wikipedia.org/wiki/INT_10H http://en.wikipedia.org/wiki/INT_10H
- angrycoder 15y agoYou can do something similar now using SDL. In fact, unless you are blitting bitmaps or using additional libraries, it is the only way to get stuff on screen. SDL gives you a pointer that corresponds to the video memory and you stick colors into it. Here is a tutorial for using SDL for 'old school' graphics programming: http://sol.gfxile.net/gp/ http://sol.gfxile.net/gp/ Of course this would require the student to install SDL and write a makefile to link it all together. I feel that is something worth covering though, since most books just do a bunch of hand waving when it comes to linking external libraries.
- JoshTriplett 15y agoWhen I said "quite a bit more setup", I had SDL in mind. :) Yes, you can get a raw pointer to a graphics buffer via SDL, but in addition to the extra setup to get a window, you have to make extra calls (such as SDL_Flip or SDL_UpdateRect) to make your changes visible.
- antirez 15y agoThis is how I learned C as well (demo coding), and a book like that makes a lot of sense IMHO: learning C with computer graphics. Now this would probably be SDL based, but as long as the user receives the initial help to get started with a simple Makefile and the calls to get a window, it will be a lot similar to the old times of int 10h. Cheers, Salvatore
- rgrieselhuber 15y agoMy wish came true. :-) http://apps.ycombinator.com/item?id=1727617 http://apps.ycombinator.com/item?id=1727617
- DannoHung 15y agoThe biggest problem with C is not the language C, for it is a small and mostly simple language with a few warts (I'm looking at you, pointer syntax), it is the ecosystem into which you are thrust when you first use it. That is, the ecosystem of, "What can I include without dicking around with compiler and linker settings, which I do not care to learn very well because I am just starting?", and the ecosystem of, "Why are all these standard libraries full of functions that all the documentation tells me not to use?", and most importantly, the ecosystem of, "Oh, this looks like a nice library that would make my life easy, (and later), wait, why isn't my program working on this other machine? I copied the binary over? Wait, what's this about a missing so? Oh, that's the library I installed, wait, how do I put it the same directory? Oh my god so many configuration settings! Wait, why can it still not find the library? It's right there now! What's LD_LIBRARY_PATH? LD_LIBRARY_PATH is bad? Why doesn't -R work? Oh, that's only for Solaris? What's the equivalent for friggin' Linux?! Ah, rpath, wait... it's trying to find the ABSOLUTE path? UGGARRHGHGHAAHHHH! Okay, finally, $ORIGIN... now let me just put that in the make file like they said I should.... AHGHGHGHGHGHGHHHHHHHHHHHHHHH!!!!!!!" Which is to say, the ecosystem of fucking ratholes that have built up over 40 years of poor tool design that cannot be corrected now due to historical precedent.
- orp 15y agoC++ has the same issues. To add another example, binary only distributions (e.g. some commercial software) bring their dependencies with them, meaning that you have to use roughly the same environment (compiler version, stl) to use them. Libraries work a lot better in VM languages.
- anacrolix 15y agoIn addition, C++ has a whole pile of other problems too.
- exDM69 15y agoIt doesn't take a VM language or an interpreted lanugage to get libraries working well. Take a look at Haskell's Cabal system and Hackage package library. It works pretty good and doesn't use a VM. With C and C++, you'll have to use your operating system's package management to get all the important libraries (or build them by hand from Git sources, etc), then have a build system that configures the build environment and searches for all the libraries and other dependencies. It's not as nice as using a dedicated tool for this, like Gem and Bundler in Ruby but usually you get the job done - unless you work on Windows and don't have a package manager.
- swindsor 15y agoThe problem with C isn't C. It's shitty C programmers. Learn how the language works, follow good patterns, and expect some bumps in the road. Most of the time, though, you can use a different higher level language, and be a happier and less stressed programmer
- raniskeet 15y agoHow about having a webpage with recommended libs for newbies to use? Sort of like NodeJS modules page.
- leon_ 15y agoI'm skeptical that it will be an alternative to K&R 2nd ed but nonetheless I'm interested in the result.
- megamark16 15y agoI asked and Zed delivers: https://twitter.com/#!/megamark16/status/71183280287920128 https://twitter.com/#!/megamark16/status/71183280287920128
- mikeocool 15y agoOh man, totally looking forward to this. It seems like so many programmers are kind of afraid of C because it's reputation and avoid learning it because they're language of choice is 'more productive.' Which is really unfortunate, I've found having a good amount of C is hugely beneficial to understanding what's going on under the hood when you're using a higher level language, even if you rarely actually program in C itself. Plus even if you do primarily program in higher level languages, it's a great tool to have in your belt when you need to fix a bug in a library whose bindings you're using in higher level language, or when you legitimately do need to eak a little more performance from a particular piece of code. Also, love that the book starts by teaching you how to use make as well, so many C books gloss over the tools.
- tomrod 15y agoNice! Where's the rest?
- emehrkay 15y agoI jokingly made this suggestion to him on twitter. He posted a few "assignments" and we (I assume it was more than myself participating) posted pics of our console output. This guy loves to program
- deleted 15y ago[deleted]