{
  "$type": "site.standard.document",
  "canonicalUrl": "https://deterministic.space/learn-programming-jump-in-at-the-deep-end.html",
  "path": "/learn-programming-jump-in-at-the-deep-end.html",
  "publishedAt": "2017-09-02T00:00:00.000Z",
  "site": "at://did:plc:x67qh7v3fd7znbdhauc45ng3/site.standard.publication/3mjcd2t6afe25",
  "textContent": "There are many different ways to learn something;\none that I enjoy from time to time is what I'd call the \"jump in at the deep end\":\nLook at the solution to a problem and study each of its details\nuntil you understand all the concepts.\n\nThis is in contrast to a tutorial-style learning\nwhere you learn one thing after another and gradually build more complex things.\nI like the \"deep end\" approach\nbecause it's a very personal learning style.\nIt often gives me a way to\ndiscover interesting aspects of things myself,\ntry to find out how parts work together,\nand play around with the material\nuntil I think I've got how it works.\nAnd while the road to understanding might be full of little frustrations and missing knowledge,\nI find it a very rewarding exercise.\n(Or maybe I'm just one of those people who like to geek out about neat concepts.)\n\nRecently, I came across this task:\nCount the individual words in a given text.\nThe solution I found seemed like a good \"deep end\" problem to me.\nIt's short and yet full of different concepts.\n\nHere's what I'd write (in Rust):\n\nIt's just 8 lines!\n(You can [play with the code here][playground].)\n\nAnd here are the concepts you should study to fully understand what's going on\n(in no particular order;\nI tried to add a lot of links):\n\n[playground]: https://play.rust-lang.org/?gist=1c48ef7279a947fcaba9e59ea2673386&version=stable\n\n- [Functions][]: fn count_words\n- [Modules][] and [imports][]: use std::…\n- [Strings][] and [characters][]: &str and ' ' are guaranteed to be UTF-8\n- [Slices][]: views into/references to memory and, in Rust, their lifetimes: the &strs in the hash map are slices of the input text\n- Iterators: split returns a type that implements [Iterator][]\n  - [fold][] (a.k.a. reduce): A core part of functional programming ([more information][wiki-fold])\n  - Iterator: a [trait][]\n- Map data type: [HashMap][]\n  - [Hashing][]\n  - [Generic data types][generics]: Split<'a, P>, HashMap<K, V>\n- Rust's [entry API][]: A view into a map with the ability to transform/add items\n  - Where is the entry API defined? [RFC 216][], [RFC 509][], [RFC 921][]\n  - [Enums][]: enum Entry { Occupied(…), Vacant(…) }\n- [closures][]: |x, y| { … }\n- Implicit return, last expression in a block gets returned: { …; map } returns map\n  - [statements and expressions]\n- Mutable vs. immutable [variable bindings][]: mut map\n- [References][], [pointers][], [dereferencing][]: thingy and &thingy\n- [Integer sizes][]: usize\n- Built-in operators: [+=][]\n\n- - -\n\nNote that most of these concepts are not special to Rust.\nI've just written this in Rust because it's the language I currently use the most in my free time,\nand also because it's a language that exposes you to a lot of interesting concepts.\n\nJust for comparison,\nhere's the same in JavaScript\n(play with it on [JSBin]):\n\n[functions]: https://doc.rust-lang.org/1.20.0/book/second-edition/ch03-03-how-functions-work.html\n[modules]: https://doc.rust-lang.org/1.20.0/book/second-edition/ch07-00-modules.html\n[imports]: https://doc.rust-lang.org/1.20.0/book/second-edition/ch07-03-importing-names-with-use.html\n[strings]: https://doc.rust-lang.org/1.20.0/book/second-edition/ch08-02-strings.html\n[characters]: https://doc.rust-lang.org/1.20.0/std/primitive.char.html\n[slices]: https://doc.rust-lang.org/1.20.0/book/second-edition/ch04-03-slices.html\n[Iterator]: https://doc.rust-lang.org/1.20.0/book/second-edition/ch13-02-iterators.html\n[fold]: https://doc.rust-lang.org/1.20.0/std/iter/trait.Iterator.html#method.fold\n[wiki-fold]: https://en.wikipedia.org/wiki/Fold_(higher-order_function)\n[trait]: https://doc.rust-lang.org/1.20.0/book/second-edition/ch10-02-traits.html\n[HashMap]: https://doc.rust-lang.org/1.20.0/book/second-edition/ch08-03-hash-maps.html\n[Hashing]: https://en.wikipedia.org/wiki/Hash_function\n[generics]: https://doc.rust-lang.org/1.20.0/book/second-edition/ch10-01-syntax.html\n[entry API]: https://doc.rust-lang.org/1.20.0/std/collections/hash_map/enum.Entry.html\n[RFC 216]: https://github.com/rust-lang/rfcs/blob/a7cd91048eea3d7ae83bec20446e62bad0c45381/text/0216-collection-views.md\n[RFC 509]: https://github.com/rust-lang/rfcs/blob/a7cd91048eea3d7ae83bec20446e62bad0c45381/text/0509-collections-reform-part-2.md\n[RFC 921]: https://github.com/rust-lang/rfcs/blob/a7cd91048eea3d7ae83bec20446e62bad0c45381/text/0921-entry_v3.md\n[Enums]: https://doc.rust-lang.org/1.20.0/book/second-edition/ch06-01-defining-an-enum.html\n[closures]: https://doc.rust-lang.org/1.20.0/book/second-edition/ch13-01-closures.html\n[statements and expressions]: https://doc.rust-lang.org/1.20.0/book/second-edition/ch03-03-how-functions-work.html#statements-and-expressions\n[variable bindings]: https://doc.rust-lang.org/1.20.0/book/second-edition/ch03-01-variables-and-mutability.html\n[references]: https://doc.rust-lang.org/1.20.0/book/second-edition/ch04-02-references-and-borrowing.html\n[pointers]: https://en.wikipedia.org/wiki/Pointer_(computer_programming)\n[dereferencing]: https://doc.rust-lang.org/1.20.0/book/second-edition/ch15-02-deref.html\n[Integer sizes]: https://doc.rust-lang.org/1.20.0/book/second-edition/ch03-02-data-types.html#integer-types\n[+=]: https://doc.rust-lang.org/nightly/std/ops/trait.AddAssign.html\n[JSBin]: https://jsbin.com/lahovadamo/1/edit?js,console",
  "title": "Learning Programming Concepts by Jumping in at the Deep End",
  "updatedAt": "2017-09-02T00:00:00.000Z"
}