y1450
1 followers · 4 following · 1110 views
on the atlas — 38
- Variables and Mutability - The Rust Programming Language3 savers
- Programming a Guessing Game - The Rust Programming Language4 savers
- How can we develop transformative tools for thought?52 savers
- Validating References with Lifetimes - The Rust Programming Language4 savers
- Rust Iterator Cheat Sheet2 savers
- Traits: Defining Shared Behavior - The Rust Programming Language4 savers
- Generic Data Types - The Rust Programming Language1 savers
- Generic Types, Traits, and Lifetimes - The Rust Programming Language1 savers
- The match Control Flow Construct - The Rust Programming Language2 savers
- Defining an Enum - The Rust Programming Language3 savers
- Enums and Pattern Matching - The Rust Programming Language1 savers
- Attention is your scarcest resource | benkuhn.net23 savers
- High-speed intro to Bayes's rule - Arbital1 savers
- gruvbox-contrib/scss at master · morhetz/gruvbox-contrib1 savers
- Multiple SSH keys for different accounts on Github or Gitlab (Example)1 savers
- shell - How to go to the previous working directory in terminal? - Unix & Linux Stack Exchange1 savers
- How to organize CSS @ 9elements1 savers
- Flexbox - Codrops1 savers
- Common CSS Flexbox Layout Patterns with Example Code | Tobias Ahlin1 savers
- nothing stops18 savers
- Method Syntax - The Rust Programming Language3 savers
- An Example Program Using Structs - The Rust Programming Language1 savers
- Defining and Instantiating Structs - The Rust Programming Language1 savers
- Using Structs to Structure Related Data - The Rust Programming Language1 savers
- The Slice Type - The Rust Programming Language5 savers
- How to change color format in Firefox Dev Tools? - Stack Overflow1 savers
- colors - CSS variable calculation of HSL values - Stack Overflow1 savers
- Alexey Guzey18 savers
- June Huh, High School Dropout, Wins the Fields Medal | Quanta Magazine6 savers
- Simon Eskildsen - Sirupsen1 savers
- CSS Padding1 savers
- Control Flow - The Rust Programming Language1 savers
- Curius / Onboarding2621 savers
- Life is Short15 savers
- The Rust Programming Language7 savers
- Semantic Versioning 2.0.07 savers
- What is Ownership? - The Rust Programming Language5 savers
- Coolest Things I Learned in 2020 - David Perell5 savers
highlights — 165
n MOOCs, questions are typically presented in a very dry form, detached from context. In the mnemonic video the narrator would explain why the questions are important, and why the user will benefit from participating, as a seamless part of the overall narration. Done right – perhaps with appropriate music, and a sense of urgency or play in the narration – it would create a real sense of the stakes.
How can we develop transformative tools for thought?From our modern vantage point we know a vastly better system of numerals is possible, the Hindu-Arabic numerals. Hindu-Arabic numerals were, in fact, a great leap in the history of tools for thought. Could you, as a designer, have made that leap? What creative steps would be needed to invent Hindu-Arabic numerals, starting from the Roman numerals? Is there a creative practice in which such steps would be likely to occur?
How can we develop transformative tools for thought?Try designing more experiments that vary the values and lifetimes of the references passed in to the longest function and how the returned reference is used. Make hypotheses about whether or not your experiments will pass the borrow checker before you compile; then check to see if you’re right!
Validating References with Lifetimes - The Rust Programming LanguageActually, we don’t know either, because the if block in the body of this function returns a reference to x and the else block returns a reference to y!
Validating References with Lifetimes - The Rust Programming LanguageRelentlessly prune bullshit, don't wait to do things that matter, and savor the time you have. That's what you do when life is short.
Life is ShortIf life is short, we should expect its shortness to take us by surprise. And that is just what tends to happen. You take things for granted, and then they're gone. You think you can always write that book, or climb that mountain, or whatever, and then you realize the window has closed. The saddest windows close when other people die. Their lives are short too. After my mother died, I wished I'd spent more time with her. I lived as if she'd always be there. And in her typical quiet way she encouraged that illusion. But an illusion it was. I think a lot of people make the same mistake I did.
Life is Shortwhen you ask adults what they got wrong at that age, nearly all say they cared too much what other kids thought of them.
Life is Shortone byproduct of technical progress is that things we like tend to become more addictive.
Life is ShortAn example that will be familiar to a lot of people is arguing online. When someone contradicts you, they're in a sense attacking you.
Life is ShortAnd yet the bullshit you choose may be harder to eliminate than the bullshit that's forced on you.
Life is ShortBut if you consciously prioritize bullshit avoidance over other factors like money and prestige, you can probably find employers that will waste less of your time.
Life is ShortTo some extent you have to put up with the bullshit forced on you by circumstances. You need to make money, and making money consists mostly of errands. Indeed, the law of supply and demand insures that: the more rewarding some kind of work is, the cheaper people will do it.
Life is ShortIf you ask yourself what you spend your time on that's bullshit, you probably already know the answer. Unnecessary meetings, pointless disputes, bureaucracy, posturing, dealing with other people's mistakes, traffic jams, addictive but unrewarding pastimes.
Life is ShortHaving kids showed me how to convert a continuous quantity, time, into discrete quantities. You only get 52 weekends with your 2 year old. If Christmas-as-magic lasts from say ages 3 to 10, you only get to watch your child experience it 8 times.
Life is ShortA trait defines functionality a particular type has and can share with other types. We can use traits to define shared behavior in an abstract way. We can use trait bounds to specify that a generic type can be any type that has certain behavior.
Traits: Defining Shared Behavior - The Rust Programming Language. The good news is that using generic types won't make your run any slower than it would with concrete types. Rust accomplishes this by performing monomorphization of the code using generics at compile time. Monomorphization is the process of turning generic code into specific code by filling in the concrete types that are used when compiled.
Generic Data Types - The Rust Programming LanguageWhen you recognize situations in your code with multiple struct or enum definitions that differ only in the types of the values they hold, you can avoid duplication by using generic types instead.
Generic Data Types - The Rust Programming LanguageEvery programming language has tools for effectively handling the duplication of concepts. In Rust, one such tool is generics: abstract stand-ins for concrete types or other properties. We can express the behavior of generics or how they relate to other generics without knowing what will be in their place when compiling and running the code.
Generic Types, Traits, and Lifetimes - The Rust Programming LanguageThis catch-all pattern meets the requirement that match must be exhaustive. Note that we have to put the catch-all arm last because the patterns are evaluated in order. Rust will warn us if we add arms after a catch-all because those later arms would never match!
The match Control Flow Construct - The Rust Programming LanguageMatches Are Exhaustive There’s one other aspect of match we need to discuss. Consider this version of our plus_one function that has a bug and won’t compile:
The match Control Flow Construct - The Rust Programming LanguageThe match expression is a control flow construct that does just this when used with enums: it will run different code depending on which variant of the enum it has, and that code can use the data inside the matching value.
Defining an Enum - The Rust Programming LanguageEliminating the risk of incorrectly assuming a not-null value helps you to be more confident in your code. In order to have a value that can possibly be null, you must explicitly opt in by making the type of that value Option . Then, when you use that value, you are required to explicitly handle the case when the value is null. Everywhere that a value has a type that isn’t an Option , you can safely assume that the value isn’t null. This was a deliberate design decision for Rust to limit null’s pervasiveness and increase the safety of Rust code.
Defining an Enum - The Rust Programming LanguageWhen we have a value of a type like i8 in Rust, the compiler will ensure that we always have a valid value. We can proceed confidently without having to check for null before using that value. Only when we have an Option (or whatever type of value we’re working with) do we have to worry about possibly not having a value, and the compiler will make sure we handle that case before using the value.
Defining an Enum - The Rust Programming LanguageSo why is having Option any better than having null? In short, because Option and T (where T can be any type) are different types, the compiler won’t let us use an Option value as if it were definitely a valid value. For example, this code won’t compile because it’s trying to add an i8 to an Option :
Defining an Enum - The Rust Programming LanguageThe Option enum is so useful that it’s even included in the prelude; you don’t need to bring it into scope explicitly.
Defining an Enum - The Rust Programming LanguageThe problem with null values is that if you try to use a null value as a not-null value, you’ll get an error of some kind. Because this null or not-null property is pervasive, it’s extremely easy to make this kind of error.
Defining an Enum - The Rust Programming LanguageRust doesn’t have the null feature that many other languages have. Null is a value that means there is no value there. In languages with null, variables can always be in one of two states: null or not-null.
Defining an Enum - The Rust Programming Languagehe Option type encodes the very common scenario in which a value could be something or it could be nothing.
Defining an Enum - The Rust Programming LanguageThe Option type encodes the very common scenario in which a value could be something or it could be nothing.
Enums and Pattern Matching - The Rust Programming LanguageThen we’ll look at how pattern matching in the match expression makes it easy to run different code for different values of an enum. Finally, we’ll cover how the if let construct is another convenient and concise idiom available to handle enums in your code.
Enums and Pattern Matching - The Rust Programming Languagewe use the :: syntax with the struct name; let sq = Rectangle::square(3); is an example. This function is namespaced by the struct: the :: syntax is used for both associated functions and namespaces created by modules. We’ll discuss modules in Chapter 7.
Method Syntax - The Rust Programming LanguageThe fact that Rust makes borrowing implicit for method receivers is a big part of making ownership ergonomic in practice.
Method Syntax - The Rust Programming LanguageRust doesn’t have an equivalent to the -> operator; instead, Rust has a feature called automatic referencing and dereferencing. Calling methods is one of the few places in Rust that has this behavior.
Method Syntax - The Rust Programming LanguageMethods like this are called getters, and Rust does not implement them automatically for struct fields as some other languages do. Getters are useful because you can make the field private but the method public and thus enable read-only access to that field as part of the type’s public API. We will be discussing what public and private are and how to designate a field or method as public or private in Chapter 7.
Method Syntax - The Rust Programming LanguageWe’ve chosen &self here for the same reason we used &Rectangle in the function version: we don’t want to take ownership, and we just want to read the data in the struct, not write to it.
Method Syntax - The Rust Programming Languageethods can take ownership of self, borrow self immutably as we’ve done here, or borrow self mutably, just as they can any other parameter.
Method Syntax - The Rust Programming LanguageIn addition to the Debug trait, Rust has provided a number of traits for us to use with the derive attribute that can add useful behavior to our custom types. Those traits and their behaviors are listed in Appendix C.
An Example Program Using Structs - The Rust Programming Languageebug format is to use the dbg! macro, which takes ownership of an expression, prints the file and line number of where that dbg! macro call occurs in your code along with the resulting value of that expression, and returns ownership of the value.
An Example Program Using Structs - The Rust Programming LanguageYou can also define structs that don’t have any fields! These are called unit-like structs
Defining and Instantiating Structs - The Rust Programming LanguageRust also supports structs that look similar to tuples, called tuple structs. Tuple structs have the added meaning the struct name provides but don’t have names associated with their fields; rather, they just have the types of the fields. Tuple structs are useful when you want to give the whole tuple a name and make the tuple a different type from other tuples, and when naming each field as in a regular struct would be verbose or redundant
Defining and Instantiating Structs - The Rust Programming LanguageThe syntax .. specifies that the remaining fields not explicitly set should have the same value as the fields in the given instance.
Defining and Instantiating Structs - The Rust Programming LanguageThere is one Annie Dillard quote I hold central to my ‘consciousness cannon’, How we spend our days is, of course, how we spend our lives.
nothing stopsPutting the specifier :? inside the curly brackets tells println! we want to use an output format called Debug
An Example Program Using Structs - The Rust Programming LanguageIt’s also possible for structs to store references to data owned by something else, but to do so requires the use of lifetimes, a Rust feature that we’ll discuss in Chapter 10. Lifetimes ensure that the data referenced by a struct is valid for as long as the struct is. Let’s say you try to store a reference in a struct without specifying lifetimes, like the following; this won’t work:
Defining and Instantiating Structs - The Rust Programming LanguageA struct, or structure, is a custom data type that lets you package together and name multiple related values that make up a meaningful group.
Using Structs to Structure Related Data - The Rust Programming LanguageThe concepts of ownership, borrowing, and slices ensure memory safety in Rust programs at compile time. The Rust language gives you control over your memory usage in the same way as other systems programming languages, but having the owner of data automatically clean up that data when the owner goes out of scope means you don’t have to write and debug extra code to get this control.
The Slice Type - The Rust Programming LanguageThis slice has the type &[i32]. It works the same way as string slices do, by storing a reference to the first element and a length
The Slice Type - The Rust Programming Languagelet number = if condition { 5 } else { "six" };
Control Flow - The Rust Programming LanguageIf the padding property has four values: padding: 25px 50px 75px 100px; top padding is 25px right padding is 50px bottom padding is 75px left padding is 100px
CSS Paddingf the padding property has three values: padding: 25px 50px 75px; top padding is 25px right and left paddings are 50px bottom padding is 75px
CSS Padding