Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: John Arundel

No description

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on, test-driven introduction to Go that builds a real bookstore application from scratch, perfect for absolute beginners who want to learn programming through practical, friendly, and deeply engaging examples. 【Book Arc】 - **Opening (~0%–10%)**: Starts with the simplest "Hello, world" program and introduces core concepts like variables, values, and basic data types (strings, ints), establishing the foundation for the bookstore project. - **Early (~10%–23%)**: Moves into structured data with structs, teaching how to group related information (title, author, copies) into a single Book type, and introduces function parameters and type checking. - **Early (~23%–32%)**: Introduces conditional statements and the panic function, then pivots to test-driven development—writing tests first, deliberately inserting bugs to validate tests, and using descriptive test names as documentation. - **Middle (~32%–48%)**: Covers creating importable packages (moving from main to books package), refining tests as specifications, and using the go test command for automated testing. - **Middle (~48%–end)**: Explores slices for managing collections of books, including slice literals, indexing, and the len function, while continuing to build out the bookstore's functionality. 【Key Takeaways】 - **Variables and literals are the building blocks** (Early): Assigning values to variables allows programs to change behavior dynamically, unlike fixed literals—essential for handling varying bookstore stock across branches. - **Structs group related data into one unit** (Early): Declaring a Book type with Title, Author, and Copies fields simplifies passing complex data to functions, replacing unwieldy multiple parameters. - **Type checking catches common mistakes** (Early): Go's compiler detects mismatched types (like passing an int where a string is expected), saving developers from subtle runtime bugs even when the true error is argument ordering. - **Tests are executable specifications** (Early): Writing test functions with descriptive names like TestBookToString_FormatsBookInfoAsString documents expected behavior and serves as living documentation for the codebase. - **Validate tests with deliberate bugs** (Early): Inserting a known-incorrect implementation (like returning an empty string) verifies the test actually detects failures, ensuring test reliability before writing the real code. - **Test-driven changes follow a red-green cycle** (Middle): Update the test to expect new behavior, watch it fail, then modify the function to pass—this confirms both test and code remain correct through changes. - **Packages make code reusable** (Middle): Moving functions from main to an importable books package allows other programs to use them, while main remains the only package that compiles to an executable. - **Slices manage collections safely** (Middle): Using []Book slices with len() to check length before indexing prevents panics, and slice literals offer concise ways to initialize book collections. 【Reading Tips】 - **Skim the early "Hello, world" sections** if you have any programming experience—they're essential for true beginners but move quickly into more substantive topics. - **Deep-read the testing chapters** (around 29%–42%): The test-driven approach is the book's core philosophy, and understanding the deliberate-bug validation technique is crucial for the rest of the book. - **Pay close attention to struct and slice syntax** (Early and Middle): These are the most common data structures you'll use, and the book's examples with Book types are directly applicable to real projects. - **Complete the GOAL exercises** rather than jumping to solutions—the hints and solutions are there to support learning, but the hands-on practice is where the understanding sticks. - **Take away the "tests as docs" mindset**: Even if you don't use the gotestdox tool, naming tests as behavior sentences will improve your testing practice across all future Go projects. 【Coverage Limits】 The excerpts cover roughly the first half of the book (through slices); later chapters on pointers, methods, and validation are mentioned in the introduction but not detailed in this guide.
Page 9
rtantly, an excellent teacher / communicator. —Luke Vidler A fantastic example of good technical writing. Clear, concise and easily digestible. —Michael Duff...
View in text
Excerpt 2
both values contain the same kind of data, namely string. 2. Data and types In the previous chapter we did some interesting things with string data, but is t...
View in text
Excerpt 3
act, let’s again break down the problem into smaller stages. Logically, if BookToString contains a bug, we want the test function to panic and stop the progr...
View in text
Excerpt 4
o books_test.go, since it’s about testing the books package. We’ll change its first line to: package books_test Now, we need to make a few changes to the tes...
View in text
Excerpt 5
u have more than one CPU in your computer, which you almost certainly do, then Go can put them all to work running tests concurrently, which makes sense. We’...
View in text
Excerpt 6
quite similar to the corresponding slice literal, isn’t it? The only difference is that instead of a comma-separated list of elements, we have a comma-separa...
View in text
Excerpt 7
rnsFalseWhenBookNotFound(t *testing.T) { t.Parallel() catalog := getTestCatalog() _, ok := books.GetBook(catalog, "nonexistent ID") if ok { t.Fatal("want fal...
View in text
Excerpt 8
l problem here is that it’s possible to create a Book value that is invalid, whatever we decide “invalid” means in this context. Right now, one way that we’v...
View in text
Tags
AI categories
Programming LanguageGoEducation
go
Publisher: Bitfield Consulting
Publish Year: 2025
Language: English
File Format: PDF
File Size: 1.7 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…