“Code” 2nd Edition(charlespetzold.com) |
“Code” 2nd Edition(charlespetzold.com) |
So I imagine any online retailers where you might be able to preorder technical books. If you are not adverse to doing so, it can probably be pre-ordered in the coming months on Amazon, as well.
[1] blackwells.co.uk
We would read the book create a “clean room” implementation of a computer with Minecraft redstone.
It’s great fun! He was overjoyed when we got our first 1-bit memory cell.
As Alan Kay famously said "People who are really serious about software should make their own hardware". No need to develop a whole computer, just getting your hands dirty with more basic electronics than consumer hardware will make you a much more complete technician.
there is a hair rising line in that book in italics! almost like in a horror book like exorcist or dracula.
'turn the book on its side. can you see it?, its counting'
hair raising stuff. thanks mr petzold.
He needs to write more books, that is his Gift and Calling.
PS: Andrew Tanenbaum's Structured Computer Organization makes a very good followup to Code.
There's other books out there, and Ben Eater's website, that indepth show how to construct processor, gates, store "memory", and so on.
https://www.networksfromscratch.com/
It’s nowhere near done, but I’m steadily working on it.
It goes really well with Elements of Computing Systems (2nd ed) [2] which I kind of think of as a "lab manual" where you get to build a computer from first principles.
[1] https://www.amazon.com/Code-Language-Computer-Hardware-Softw...
[2] https://www.amazon.com/Elements-Computing-Systems-second-Pri...
Code is more high level, Nand2Tetris and Elements is project based but covers some similar territory.
He goes: electricity, relays, logic gates, circuits (like adders), CPU, RAM …
It’s been awhile so I might have missed a step or two. You’ll come away knowing how we used electricity to get from lightning bolts, to pocket computers. You will not come away with a programmable machine.
It’s not a book about implementing a particular computer - it’s more about giving you the rough thought process about how it actually works at the level of electricity and wires, and how this gets built up into something that actually calculates stuff.
It’s the first book that took me from “computers are mystical magic” to “computers are understandable magic”.
While I understand many “get started programming” books/tutorials put an emphasis on getting coding asap, I really had to stop and learn about computers before I could start coding in a well rounded way (and that’s coming from a WebDev, who doesn’t even have to deal with low-level stuff too often!).
Thank you Mr. Petzold!!!
Reading it, I felt like I actually understood how computers worked, right down to the “electricity going through wires” level and lower, and how that builds up to if-then statements, etc, in a high-level language.
Obviously everyone's experience will be different but I think of a CS education more of treating computers like an abstract machine, not a physical one.
There are excellent books for novice Linux programmers, but unfortunately, nothing compared to Petzold's clear and direct presentation.
.
There is also a companion website that is under construction that already has a delightful amount of interactivity, showing how binary switches, relays, and gates work:
Also: i found a book i always was too scared of starting to read (because i didn‘t want to feel like the biggest idiot trying to read it): „The Annotated Turing“. When i looked at it again after having read „Code“, i saw it was also written by Petzold. The way he wrote „code“ i know, that this will be great. I am very excited to read it when i have a few hours to fully block for it.
I think it's especially good for people like me who work in software development but don't have a computer science degree or background. Going from scratch and the very foundations of telegraphy all the way through to what opcodes really are and how code actually works in memory was an eye opener for better understanding what coding really is.
We can't just all sit at the top of the tower and wonder why is it behaving irratically! Please support by purchasing the book.
My first semester in college, I took a class in semiconductor physics. That started with the PN junction, to diodes, to transistors, to gates, to flip-flops, to clocking, to registers, adders, etc.
Later on, this made learning microprocessors straightforward, then assembler, then C, etc.
I suppose it would have been faster to go straight to programming, but I am happier knowing how it works all the way down.
I never got the Z-80 kit but I eventually got a computer with DOS, which had QBasic, where I learned to code by modding GORILLA.BAS and NIBBLES.BAS. What a weird language, there was AND and OR, but not NOR, XOR, NAND and others...
It also partly inspired my first efforts at building a scientific calculator (which would never be quite finished).
I definitely recommend it for folks who want to build context on the lower levels of computers, as a start into understanding CPUs, binary/hex, and other parts of how we tricked sand into thinking with lighting.
https://bookshop.org/books/code-the-hidden-language-of-compu...
Its definitely a bit more more expensive (~$37 vs $32) than ordering it via links in post.
All you have to do is add a '0' to the front of each ASCII sequence to make them 8 bits instead of 7 bits, and then they will be UTF-8 encoded.
I swear this is the first new blog I've added to my RSS feed reader in over a year.
http://www.charlespetzold.com/blog/2021/08/Screw-You-Microso...
no M$-lapdog, he. I learnt my Win16 from the first edition of "Programming Windows" and would have learnt my modern UI from the newest edition if MS hadn't been so busy throwing the bathwater out with the Windows Phone baby that I lost heart.
But it is useful for a lot of people who don't know how a computer really works.
I finished my Electrical and Computer Engineering undergrad in 2008 and have been a software dev ever since.
You won't learn anything new if you had computer architecture and digital logic classes. But it's an excellent refresher. And so well written that it reads more like light fiction than a technical deep dive.
"In a famous 1907 paper on relativity, Hilbert's friend Hermann Minkowski would coin the word Zaumreit or spacetime."
Zaumreit literally translates to "bridle riding" and is probably a play on words, Raumzeit means spacetime. This has puzzled me for over a decade now. How does this even happen?
I'm guessing the author remembered the word incorrectly and wrote it down that way. It's not hard to transpose two letters when you don't know the language.
So I'm really glad there is a second edition and I'm wondering if there is a new story.
- why is little-end / big-end a thing?
- why is volatile memory called volatile? and why can't we just keep that data around?
- what can a 64-bit computer do that a 32-bit computer can't?
- what do people mean when they say "code is data"
- what's an instruction, really?
- how did people program computers before they had screens?
- how did people program computers before they had keyboards?
- why is it called 2's complement?
And others that I can't recall right now. It's a fantastic book and I recommend it to everyone who is the slightest bit interested in how computers work.
- The terminal was completely foreign to me. Why is it structured so? How are permissions set? Octal?!?!?!
- Why do I have to specify a type in a programming language?
- What/why are all these special characters used in programming?!
- Why is a program structured in the way it is? What are the levels of abstraction working in a given program?
- What happens when I run/compile my program?
I would also say that learning a little bit of C also really helped illuminate computers for me. Not only in the sense of how they work, but also why programs use their current syntax. For example, for developers who look at Javascript for the first time seeing parenthesis, colons, curly brackets, etc all make an initial sense: they seem familiar. However, to somebody first diving in all of these characters seem totally arbitrary! Having gained a sense of how computers worked and then a very basic introduction into low-level programming, suddenly these high level languages seem much less arbitrary.
The teaching style in this book is so unbelievably good that even if you know all the ins and outs of a computer you want to read on because he explains everything in a way that you wish that you would have come up with yourself.
I suspect I have a completely different mental model than them - just a completely different casual understanding of it. I find it hard to imagine how they must see the modern world. It must seem like magic!
Note that I’m not at-all speaking about intelligence here. Just knowledge.
Anyway: for that person, I think that if they read ‘Code’, their entire understanding of the world would change, which is sort of amazing.
Had several teachers who utterly refused to provide that, repeating "it'll all make sense eventually." Well, it did, after I got better teachers.
I had spent many hours on BIX and CompuServe and maybe GEnie helping other Windows programmers get their start.
So I like to think that in a small way I contributed to Charles' success in educating a generation of Windows programmers.
Remember, friends, always pass it forward.
Consider creating a child process in GNU/Linux:
fork();
Vs in win32’s asinine API:
CreateProcess( NULL, // No module name (use command line) argv[1], // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE 0, // No creation flags NULL, // Use parent's environment block NULL, // Use parent's starting directory &si, // Pointer to STARTUPINFO structure &pi ) // Pointer to PROCESS_INFORMATION structure )
And in the end it turned out that it’s not worth programming windows any more. Just use Qt, Java or the awful web technology of the day and you’ll probably be better off than with whatever MS is recommending.
Do you have any suggestions in this regard?
And why the apostrophes in two's complement and ones' complement are in different places.
A few of the points made:
* Fork is no longer simple. Fork’s semantics have infected the design of each new API that creates process state. The POSIX specification now lists 25 special cases in how the parent’s state is copied to the child [63]: file locks, timers, asynchronous IO operations, tracing, etc. In addition, numerous system call flags control fork’s behaviour with respect to memory mappings (Linux madvise() flags MADV_DONTFORK/DOFORK/WIPEONFORK, etc.), file descriptors (O_CLOEXEC, FD_CLOEXEC) and threads (pthread_atfork()). Any non-trivial OS facility must document its behaviour across a fork, and user-mode libraries must be prepared for their state to be forked at any time. The simplicity and orthogonality of fork is now a myth.
* Fork doesn’t compose
* Fork isn’t thread-safe
* Fork is insecure
* Fork is slow
* Fork doesn’t scale
Etcetera e.g. O_CLOEXEC, FD_CLOEXEC, EFD_CLOEXEC, EPOLL_CLOEXEC, F_DUPFD_CLOEXEC, IN_CLOEXEC, MFD_CLOEXEC, SFD_CLOEXEC, SOCK_CLOEXEC, TFD_CLOEXEC, DRM_CLOEXEC, FAN_CLOEXEC, UDMABUF_FLAGS_CLOEXEC
Edit: Good discussion both pro and against the paper here: https://lwn.net/Articles/785430/
First of all the name CreateProcess is obviously much more readable than fork. When I want to create a process, I usually want to run some function in the new thread which the windows version takes as arguments, alternatively fork copies the entire god damn process (what?) and I have to choose what to do based on the return value. The only reason the performance of fork is not abysmal is because the underlying operating system has to implement some sort of copy on write optimization but that just makes the performance characteristics of the program less transparent.
Like you said, "learning a little bit of C" would probably cover most of the things you listed. It sounds like you're a web developer.
This is it. It’s not going to tell you some deep technical details about how modern processors work, but it’s an extremely well-written introduction to low-level computer concepts that any moderately intelligent person can follow with no prior specialist knowledge, which is rare among nonfiction books. But still, it’s a popular science book, not a thorough technical treatise.
Also, probably a lot of people read it before university. I read it at age 16 or so and learned basically my entire framework for understanding what a computer is and does. I doubt someone with a rigorous computer engineering degree under their belt would learn anything specific, but it’s still a fantastic piece of writing and you might enjoy seeing a good explanation from first principles of how everything fits together.
Really he explains how that works too. It's reasoning from first principles at its finest. I wish school curricula were so well-designed.
The one I remember dearly was CS2110 at Georgia Tech. Most undergrads shuddered when they heard of that course and tried to avoid it, but it legitimately opened up my eyes to how computers "really" work. The class started all the way from logic gates, to building your own 8-bit APU using those logic gates (in a simulator), to writing some assembly code, to programming a gameboy game, to implementing your own malloc. And the continuation of that course, CS2200, was great too, which started with using logic gates and basic APUs (the kind you implemented yourself in CS2110) to build a primitive CPU pipeline (in a simulator as well).
I cannot ovestress how useful that understanding (no matter how basic it was) ended up being later on in my career, despite me doing mostly webdev for the first 5 or so years out of college. It basically turned my knowledge from "i know how to write code" to "I understand what I am actually doing on all levels of the stack (even if that knowledge is rather simplistic for the lower levels of that stack)". Came in pretty handy when I discovered a bug in one of the early versions of the TypeScript transpiler as I was writing my webdev code. Pretty certain I would've been completely stumped by my code not working if I didn't have an intuition for digging in that direction (which i definitely wouldn't have had, if it wasn't for that class).
Everything in that class was building up so well off what was learned earlier in the class, I was wowed. I actually felt like i understood how those things were naturally "discovered" for the first time back in the day. Basically, it was the difference between "here is a formula, here is what it does, here is how you should understand it" and "here is what you know, here is a concern you might want to think about next, oh congrats, you just 'discovered' this well-known concept following the same train of logic that led to it being originally 'discovered'".
My computer science degree included courses on microprocessors, circuit design, logic, system architecture, etc. and I think that most rigorous CS programs would also include these.
"Project 4 is written in the computer’s assembly language, and projects 9 and 12 (a simple computer game and a basic operating system) are written in Jack—the Java-like high-level language for which we build a compiler in chapters 10 and 11."
I think this is unnecessarily infantilizing. There are a great many very complex things in the modern world, and people must employ abstractions for most of it.
I think with the rise of multi form factor computing, there is more basic literacy about the nature of computers these days. People don’t think that a phone god makes their phone work and a laptop god lets them work on their document.
> I think this is unnecessarily infantilizing. [...] people must employ abstractions [...]
"Magic" to me means "does not (appear to) obey laws of cause and effect".
When the phone doesn't work after you install App X, do you attempt to remove app X? Why would restarting the phone help the situation? If none of this is logical, you're just following the 16 step Apple Fixit Checklist, good luck... it might work... but if you miss something what happens? You're just back to the start and run the checklist again... or call the ~~witch doctor~~ knowledgable friend.
Now I won't say there's no magic in understanding computers. There certainly are cause and effect mechanisms that are too arcane for ordinary mortals to be familiar with (even like "don't build the project inside a directory that has a space in it" never mind "don't put a colon or slash in your filename").
The point is: "magic" does not have to mean infantilizing.
Complex chemistry and materials engineering feels ‘like magic’ to me. I know I could understand it with enough effort - but I don’t understand it now. I’m sure my view of everyday things would change if I did.
The way you think of dogs is probably not very different from the way many people think of computers.
Lets take something I know nothing about: Industrial chemistry. That still seems less mysterious to me than dogs, because I know that I could find books about industrial chemistry at whatever level of detail I wanted. But dogs--not so much, beyond a rather superficial level.
Of course modern computing devices are absurdly complex and intricate machines all the way from silicon to software, but the basic mechanism is easily grasped by children. For all their complexity, computers are still just programmable calculators.
That's correct, right up until someone tells a computer to beat a 9-dan Go master, but not how to do it.