Тёмный

Fast F#: Intro to Options 

Fast F#
Подписаться 2,2 тыс.
Просмотров 663
50% 1

In F# we don't use nulls to encode the absence of value, we use the Option type. Let's learn how to create instances of Option and work with them.
=== Contact ===
Email: hi@fastfsharp.com
Mastadon: mastodon.sdf.org/@fastfsharp
Twitter: / fastfsharp
=== Tags ===
Tags: #fsharp, #dotnet

Наука

Опубликовано:

 

13 фев 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 15   
@thethreeheadedmonkey
@thethreeheadedmonkey Год назад
The reason null is called a billion dollar mistake, is not that it is a bad idea by itself, but rather that it causes a lot of developers and code to fall into a pit of failure rather than a pit of success. Option types make that pit a pit of success instead (as Scott Wlaschin likes to say), since this is explicit. It's definitely more important to consider this for more high level languages than the low level ones. Low level languages have the benefit of having a quite limited feature set and quite little abstraction, forcing you to think things through (but slowing down your development velocity, generally speaking). In high level languages, abstractions need to be intuitive or encoded, especially as the code base grows larger and more complex. It's very interesting that this kind of thing is built into a language like Rust now. I think it's a cool notion, and I'm sure we'll be seeing less nulls in the future in general just because it's harder to reason about than many would like in a growing system.
@FastFSharp
@FastFSharp Год назад
Emphatic agreement. I think null is unnecessary in high-level languages, especially ones with automatic memory management. Note I did not say a GC. Rust is an example of automatic memory management without a GC. I'm hoping we see more languages take an approach like rust where the type system precludes the need for GC. I don't want to be dogmatic and just say that "Null is bad." I'm hoping that people develop a more nuanced view of language design and don't fall into dogmatism.
@thethreeheadedmonkey
@thethreeheadedmonkey Год назад
Not that I noticed it in this video (or other videos), but if you are on Windows, there is a pretty cool tool you can use if you have a powerful GPU on your computer, for extremely powerful noise reduction called Nvidia Broadcast. So if you have to record on a noisy day, and you're on Windows, and you have one of their supported GPUs, it's a powerful (free) tool to help make that less of a problem.
@FastFSharp
@FastFSharp Год назад
Thanks for the tip!
@AlexeyRaga
@AlexeyRaga Год назад
Null was pronounced "a billion dollars mistake" not by "some people" but by Anthony Hoare, the "creator" of the "null" himself, in his "public apology". In which he said that "null" should never been implemented, and that it was implemented not because "it made sense in some contexts" or had another "big idea" behind it, but "because it was easy to implement" :) He also said that he had no idea that anyone would ever use it.
@FastFSharp
@FastFSharp Год назад
I think my main point with those comments is that Null is not necessarily a mistake. In some contexts it is. I think Null is perfectly valid in some scenarios.
@JustinSkeen
@JustinSkeen Год назад
I like the way it's implemented as an explicit type. It would be nice if eventually it had an overloaded syntax to allow something like "let cValue = aValue + Some 1" and also knowing that "let dValue = aValue + emptyValue" would make no sense.
@FastFSharp
@FastFSharp Год назад
I'm not sure I follow? F# does allow some overloading but it's often frowned upon because it can obfuscate what is actually happening.
@JustinSkeen
@JustinSkeen Год назад
@@FastFSharp I was thinking of this a little too simple. It might make sense for simple types that have math semantics (numeric types). In the example above I was envisioning the "inference" as seeing integers all the way therefore it would know you could add two optional integers to each other without needing to write the "unpack the value" code. I am letting myself fall into the trap that "None" operates the same as null does for other languages. In some languages adding null to another type makes the result null (or causes an exception). But for a value type my second example would actually be valid because adding "lack of value" to an existing value would just be the original value. In any case, this is more complex than I was originally thinking because Option can take on any type.
@thethreeheadedmonkey
@thethreeheadedmonkey Год назад
I think you still need to add some tags to your videos, if you want better reach. Especially if you want to reach people who might not have looked at F Sharp before (probably your target audience with this series).
@thethreeheadedmonkey
@thethreeheadedmonkey Год назад
I'd at least throw in FP or functionalprogramming.
@FastFSharp
@FastFSharp Год назад
Noted. If you think of good tags, let me know. I'll add the Functional Programming ones, even though I don't emphasize the Functional style of composition.
@thethreeheadedmonkey
@thethreeheadedmonkey Год назад
​@@FastFSharp Sometimes you have to think a bit more broadly to pull in an audience I think. To newbies, who might be the best target for this series, they might not even know what "Functional style of composition means" - but they might have heard of functional programming, and they might be interested in F# as an excellent language to start learning that in. I agree it's not necessarily the most accurate description as far as tags go, but tags are for "human related algorithms", and then you have to forgo accuracy for impact sometimes (though I would be hesitant to add too many, especially if they reduce the accuracy or correctness).
@JackoCribbo
@JackoCribbo Год назад
Option.bind would be a good follow up, Even more I hope you go over collections functions like tryFind tryHead tryTail choose Avoiding null reference exceptions gets all the spotlight but to be honest it's these patterns/functions that Option enables that I miss most going back to null.
@FastFSharp
@FastFSharp Год назад
Tomorrow I plan to introduce the Map collection and Map.tryFind which is why I had this video first 😊😊
Далее
Fast F#: Intro to Active Patterns
25:21
Просмотров 1,4 тыс.
Fast F#: Intro to Classes
22:23
Просмотров 852
Fast F#: Intro to Interfaces
22:01
Просмотров 765
Fast F#: Intro to .NET Generic Collections
22:41
(Simple) Reverse Shell
44:58
Просмотров 493
Fast F#: Intro to Maps
18:06
Просмотров 789
Fast F#: Mapping Domain to Indexes
23:59
Просмотров 995
Fast F#: Abstraction Addiction
29:00
Просмотров 1,3 тыс.
Fast F#: "Clean" Code Chat
53:16
Просмотров 4,5 тыс.
Fast F#: Anonymous Records
17:02
Просмотров 568
Fast F#: Read-Only Struct Wrappers
20:37
Просмотров 823
S-Pen в Samsung достоин Золота #Shorts
0:38
Best mobile of all time💥🗿 [Troll Face]
0:24
Просмотров 2,7 млн
iPhone перегрелся, что делать?!
1:01