liveBook · Manning

Input normalization

As explained in Learn Go with Pocket-Sized Projects

Input normalization is the transformation of incoming values into a consistent representation before further processing.

Input normalization transforms incoming values into a consistent representation before validation or further processing. For a word game, converting guesses to uppercase lets the program handle mixed-case input uniformly. section 5.1.3

Normalize a word-game guess

Replace direct rune conversion such as `[]rune(string(suggestion))` with `splitToUppercaseCharacters(suggestion)`. The function applies `strings.ToUpper` and returns the result as a rune slice, turning `Go` or `go` into `GO` before validation.

Listing 5.17 game.go: Split characters
// splitToUppercaseCharacters is a naive implementation to turn a string 
// into a list of characters.
func splitToUppercaseCharacters(input string) []rune {
    return []rune(strings.ToUpper(input))
}

Inspect the small Go helper that centralizes uppercase conversion and rune splitting, making later support for other writing systems easier to add. section 5.1.3

Test normalization and the validation boundary separately:

  • Add a focused test that verifies mixed-case input becomes the expected uppercase rune sequence. section 5.1.3

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Defines a small uppercase-conversion helper and recommends focused tests, while stopping short of broader writing-system support.
Examples
Normalizes `Go` or `go` to `GO` with a Go helper returning uppercase runes.
What it assumes
Assumes familiarity with Go strings, runes, functions, and table-driven tests while demonstrating normalization from a direct conversion.
What you can do after
Build it from scratch by centralizing case conversion, passing normalized runes to validation, and testing the transformation.
How it connects
Connects input normalization to input validation, rune handling, and testing.

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.