No video

Domain Modeling Made Functional - Scott Wlaschin

  Рет қаралды 66,827

NDC Conferences

NDC Conferences

Күн бұрын

Statically typed functional programming languages encourage a very different way of thinking about types. The type system is your friend, not an annoyance, and can be used in many ways that might not be familiar to OO programmers.
Types can be used to represent the domain in a fine-grained, self documenting way. And in many cases, types can even be used to encode business rules so that you literally cannot create incorrect code. You can then use the static type checking almost as an instant unit test - making sure that your code is correct at compile time.
In this talk, we'll look at some of the ways you can use types as part of a domain driven design process, with some simple real world examples in F#. No jargon, no maths, and no prior F# experience necessary.
NDC Conferences
ndcoslo.com
ndcconferences...

Пікірлер: 80
@tullochgorum6323
@tullochgorum6323 6 жыл бұрын
Best argument I've seen for using a functional approach for line-of-business projects. Most developers think of FP as a specialised technique for scientific or mathematical programming. This presentation blows that out of the water. Pity there's such a small audience for these ideas.
@h3rteby
@h3rteby 5 жыл бұрын
Functional programming is actually becoming big in the frontend/web world! React and Vue, the two most popular frameworks, are both based on functional programming concepts, and Immutable.js is quite popular too. I think many frontend developers would be ready to switch to a typed pure functional language, to get the guarantees that they offer.
@leonk6950
@leonk6950 4 жыл бұрын
@@h3rteby the problem with react and vue is that while they are based on immutability and functional reactive stuff, they Do not have the type-System benefits. A Good type System is imo at least half the value of FP. Bucklescript/REASONML are most likely the things that could make it more popular, altough i strongly dislike reasons Syntax, and some of their compromises make it Hard to recommend for doubtful people (separate Operator for floating point Arithmetic for example). Elm and purescript are where it's at, but purescript can be very complex very Quickly because its based on the math heavy type System of haskell, while Elm can *feel* very limiting, as it requires an immense Shift in how you See pretty much everything in your code
@h3rteby
@h3rteby 4 жыл бұрын
@@leonk6950 True, they're a stepping stone though. When you know React/Redux/Immutablejs, then Elm doesn't look so alien anymore. I've actually been using Elm in production for over a year now :)
@georgH
@georgH 3 жыл бұрын
@@h3rteby I call them "gateway" languages, as I started learning React, I figured that Redux was good to manage the state, then learned Elm and ended with Haskell (so far). I had studied Miranda in university, in early 2000s. I was marveled at map, filter, fold, and at the theory behind, but the Haskell ecosystem was nowhere near as good as it is today. However, it made enough impact in myself to make me feel bad since, as typing loops and having to use Java again (java generics just had come out and were not widespread) looked so archaic and low-level...
@dbarless
@dbarless 3 жыл бұрын
I think the audience is a lot larger than you realize
@GloriousAssam
@GloriousAssam 5 жыл бұрын
It's always a relief to find your talks. Most speakers on these topics are PR time wasters, sent on a day trip from the office, meme slides, surface level devs, or being funny. Thank you.
@opentrail
@opentrail 4 жыл бұрын
another top talk from Scott. Absolute clarity. Functional demystified and concrete understandable examples. Recommend his book. I've used Java for 20 years or more and wondered why I've always had an awkward love-hate relationship with it. This is another aha moment.
@zurvey
@zurvey 6 жыл бұрын
Wow. This is great stuff; I'll be watching this more than once. In fact, I just bought his book. These days every new "innovation" that any object-oriented language rolls out is actually something functional programming has been doing for years. That's object-oriented language designers confessing to us all that functional programming really is the better way forward. So why not stop with the OOP bandaids and just go ahead and embrace FP?
@FilipCordas
@FilipCordas 4 жыл бұрын
To be honest f# has been taking stuff from c# for a while now, it's not oop only taking stuff from functional especially when it comes to performance.
@januszwrobel
@januszwrobel 4 жыл бұрын
@@FilipCordas What features do you have in mind? Specifically, what OOP features do you have in mind that have been ported to F# after coming into C#?
@FilipCordas
@FilipCordas 4 жыл бұрын
@@januszwrobel​ Janusz Wróbel Well I am thinking about all the new stuff that comes with Roslyn. Struct refs Spans...
@januszwrobel
@januszwrobel 4 жыл бұрын
@@FilipCordas That's all good, but not sure it has anything to do with OOP specifically. it could as well be considered a feature of F# as of C# - it's a .NET feature. You might see a lot more blogs advertising these features in the context of C#, but that's simply because C# is more popular. I somewhat agree with you in the sense that not all the innovation is taken from old functional concepts - some are new addons to .NET CLR. They are not OOP concepts though.
@FilipCordas
@FilipCordas 4 жыл бұрын
@@januszwrobel This is why F# will never be used on large scale people that use it care more about if something is oop than the underlying thing. Yes Spans refs are OOP because they are just a workaround to make classes more performant you don't need them in procedural programming. They are just a product of Roslyn being written in c#. I think that when it comes to performance functional languages do have a problem because it's not that you can't write performant code it's just that you need to think about it way too much.
@jg9193
@jg9193 5 жыл бұрын
This talk changed how I write code
@markovujanic
@markovujanic Жыл бұрын
I'm blown away with this talk. I bought the book from Scott and hope to help me think more about Domain Modeling
@tommedcouk
@tommedcouk 5 жыл бұрын
Great stuff, shows how f#’s design fits in so nicely with DDD - really useful thanks
@hynjus001
@hynjus001 6 жыл бұрын
Excellent talk, especially after that previous one earlier in the day. The intimidation factor of F# has been slashed completely. Now to somehow work out how to integrate f# gradually into the c# company I work for...
@EternalDensity
@EternalDensity 5 жыл бұрын
You know he has a series about that topic on his blog.
@MaksimShamihulau
@MaksimShamihulau 10 ай бұрын
Thank you very much! How beautiful Functional Programming is! I wish I had begun my programming journey as a functional programmer rather than starting with OOP.
@heldersribeiro3676
@heldersribeiro3676 6 жыл бұрын
I like the more relatable names at 7:08.
@statequest
@statequest 6 жыл бұрын
This is so helpful - even though I don't use a functional programming language.
@yavoratanasov2513
@yavoratanasov2513 5 жыл бұрын
Great video :). I like to see future videos with real projects for example simple blog tutorial. How to code reuse without inheritance, how the code be open for extension. In OOP you inject interface. Here i have pattern matching but all the cases are in the function. if i add new type i should change the function itself. If i have 20 types the function becomes very large. With real project like blog things and fp patterns will be more understandable.
@AkosLukacs42
@AkosLukacs42 5 жыл бұрын
Hi, you can check out his site at fsharpforfunandprofit.com
@uthoshantm
@uthoshantm 5 жыл бұрын
I wish some F# features to be added to C#. Like declaring new types out of existing types, or the let keyword to ensure immutability of sub expressions. This seems feasible...
@nanvlad
@nanvlad 4 жыл бұрын
In C# instead of let you may write a const keyword when you're declaring a local variable
@rushikeshmhatre8195
@rushikeshmhatre8195 4 жыл бұрын
Scott - You are awesome. I am in lov with your presentation :) superb !!!
@AlfredSYoung
@AlfredSYoung 4 жыл бұрын
works great with typescript :)
@dinoscheidt
@dinoscheidt Жыл бұрын
Not really. Null.
@CoredusK
@CoredusK 3 жыл бұрын
Blew my mind.
@rohits79
@rohits79 7 жыл бұрын
Great presentation and content...
@wasabigeek
@wasabigeek 3 жыл бұрын
Loved this presentation, one question though: in the final example where ContactInfo can be one of 3 choices, does that mean any caller that wants to use ContactInfo must now be able to handle all 3 types (I'm especially curious about the "pair" type EmailAndAddr), or is there some magic in functional languages that makes this easy? I'm more used to OO so it felt like this was one of the areas where a shared interface / encapsulated behaviour sounds nice.
@DryBones111
@DryBones111 Жыл бұрын
You'd have to pattern match the new cases, however, FP does have a trick to reduce the amount of code you have to write which is composition. The code which actually does something with some contact info will not be in the same function that's doing the pattern matching, so really all you have to do is some light plumbing (in the form of pattern matching, deconstructing and function application). Ths pair type would simply be like a tuple deconstruction instead of a single value. There is a duality between data and behaviour, by making it easier to extend one, you make it harder to extend the other.
@444haluk
@444haluk 3 жыл бұрын
I am unfortunately bounded to Python and C++, however I am gonna try my best matching this approach in Python and C++ and pass this message whoever I talk to that writes codes. Thank you.
@lacigoldude
@lacigoldude 5 жыл бұрын
Great talk as always!
@adityaavs
@adityaavs 5 жыл бұрын
Great, very informative talk!
@MajeureX
@MajeureX 2 жыл бұрын
I'm about halfway through the talk. Very interesting so far. I can see how this would be useful for starting a new project. But can functional DDD be of use to an existing non-functional project? Could functional DDD be used to reason about and/or validate a complex project written in C#, for example? Could I either generate a function type spec from the exist class design, or could I create functional type spec from my mental model of the system and validate it against the actual code?
@comarnicolodi
@comarnicolodi 5 жыл бұрын
Great talk, ive learned a lot of stuff!!!
@centerfield6339
@centerfield6339 2 жыл бұрын
The "Product" equivalency is sometimes made explicit for no reason e.g. Microsoft's use of the term "SKU".
@nitinsharma4593
@nitinsharma4593 5 жыл бұрын
Excellent talk !
@UnicornLaunching
@UnicornLaunching 5 жыл бұрын
He's the real hero.
@jinlongzhu1979
@jinlongzhu1979 3 жыл бұрын
Such a great video
@ratherbyexploring4898
@ratherbyexploring4898 2 жыл бұрын
So where does the business logic live? separate powerpoint slides? can someone explain the filesystem or namespaces or something in f#
@jwj410
@jwj410 6 жыл бұрын
Excellent
@Dynitios
@Dynitios 6 жыл бұрын
19:31 "Glue things together like lego" 🤔
@quorkquork
@quorkquork 5 жыл бұрын
You've been doing legos wrong if you didn't glue them.
@stanislavzemlyakov5442
@stanislavzemlyakov5442 5 жыл бұрын
Mr. Business?
@Yetipfote
@Yetipfote 5 жыл бұрын
There's only one difficulty I see with the Single Variant type and avoiding invalid state by design: initial state. If you provide the user with a fresh modal in which he can enter a customer, the fields `email`, `firstName` etc. are *supposed* to be empty. This is an unwanted state when saving the user later but it is a *wanted* initial UI state. Both domains, UI and business logic, overlap at that point and produce a problem. Can someone help me on that? Help is very much appreaciated!
@yifanwang4906
@yifanwang4906 5 жыл бұрын
You probably don't want use same type for representing both UI and domain state. For UI you probably needs an Optional for email under Profile type, so that you can represent it in the first place and then let user type it. Then you can validate this type and return an Either, and Profile has a non-empty Email field there.
@Yetipfote
@Yetipfote 5 жыл бұрын
@@yifanwang4906 Ha! That was exactly what I came up with after days of thinking!! :D
@user-tx4wj7qk4t
@user-tx4wj7qk4t 7 ай бұрын
​​​@@yifanwang4906this is definitely not correct. In this kind of situation you would want to differentiate between your state management states and your local UI state. If it's a form or some kind of user input, you would have a local UI state that contains the state locally being modified. Your state management would have something like "initialState and setState" with only setState containing your model. You then pattern match on these states in the UI and the UI decides it's initial state if the state is initialState. Basically you need to separate the idea of a domain model from the state of the application as well as separate this from the UI state. This becomes especially obvious when you try to get information from the backend and are forced to have "loading, success, failure" states that clearly have nothing to do with your domain model. It's the same thing with initialstate and setstate
@ryanjackson0x
@ryanjackson0x 6 жыл бұрын
I wouldn't compare union types with interface implementation. They're more like enums (from the points raised here at least).
@sabirove
@sabirove 6 жыл бұрын
no. these are a fixed set of "sealed" interface or abstract class imlementations and can have different field sets. enum is the fixed set of singleton instances of the same type.
@jvcmarc
@jvcmarc 5 жыл бұрын
yeah but enums can't have their own data like unions
@yifanwang4906
@yifanwang4906 5 жыл бұрын
The point of algebraic data types is to having sum type and product type at the same time. So that you can modeling kind of domain type without stretching. Say you have a type is Payment, and Payment could be CreditCard(no: Long, cvv: Int) or Cash(amount: Double) or just FreeCoupon(id: UUID). In so these three kinds of payments are all under same interface/type so that use can accept them in a function parameter, and handle them case by case like a switch statement. In exchange, you don't have to force them to expose same properties(which is unnatural and stretching), and eventually makes your code simple and straightforward.
@kianchristoffern
@kianchristoffern 2 жыл бұрын
18:50 The 'functional design of CardGame' has almost exactly the same flaws as the slide with object oriented Contract from earlier?? Horseraddish, I say
@tomislavhoman4338
@tomislavhoman4338 3 жыл бұрын
"| types" look like sealed classes in Kotlin and "* types" as data classes
@jinekLESNIK
@jinekLESNIK 6 жыл бұрын
35:44 Why not to throw an exception? Why anything invalid reflects to valid "nothing"? Is "nothing" a valid value for EmailAddress? why?
@przemysawkrowinski9235
@przemysawkrowinski9235 6 жыл бұрын
I would say that this is "createEmailAddress" and not "validateEmailAddress”. You will most likely validate the email at some other place. Especially, since a missing email is not a very exceptional situation - we expect that something like that will happen.
@jinekLESNIK
@jinekLESNIK 6 жыл бұрын
If you validated it in another place what is the point to validate it here? Just put that validated result, no need for additional check, right? I know it's not right, that is called information lose. If you do A=B/C you expect DivideByZeroException in case of C was 0. Otherwise blue screen/money lose/rocket out of the orbit/other unpredictable things will happen. Here is exactly that situation, exception should be thrown if developer who called this code passed wrong argument.
@X9SecretAgent
@X9SecretAgent 6 жыл бұрын
In DDD all the logic should be within the domain. This allows the code to be written in a way that it doesn't care if you're using it on the web or a desktop GUI. It doesn't care if you store it in a RDMS or NoSQL.
@jinekLESNIK
@jinekLESNIK 6 жыл бұрын
So? How does DDD prevent us from using exceptions?
@unlimited071
@unlimited071 6 жыл бұрын
You could introduce a different return type. For example: Either where the method explicitly tells you that it can either return an Email instance or, for example, an Error instance. Note that Error is NOT an exception. Exceptions should be for really excepitional cases, cases that you are not prepared nor know how to handle. An incorrectly formated email is not such a case.
@gyawimovement9164
@gyawimovement9164 3 жыл бұрын
The yellow foot phenomenologically delay because lake gully tour toward a divergent farm. polite, free fish
Domain Modeling Made Functional - Scott Wlaschin
51:35
NDC Conferences
Рет қаралды 28 М.
F# for C# programmers - Scott Wlaschin
1:00:01
NDC Conferences
Рет қаралды 69 М.
7 Days Stranded In A Cave
17:59
MrBeast
Рет қаралды 95 МЛН
This Dumbbell Is Impossible To Lift!
01:00
Stokes Twins
Рет қаралды 36 МЛН
ROLLING DOWN
00:20
Natan por Aí
Рет қаралды 11 МЛН
Kind Waiter's Gesture to Homeless Boy #shorts
00:32
I migliori trucchetti di Fabiosa
Рет қаралды 15 МЛН
The Business of Domain Modeling with Scott Wlaschin
1:10:19
Tech Conception
Рет қаралды 2,9 М.
Thirteen ways of looking at a Turtle -  Scott Wlaschin
1:04:42
NDC Conferences
Рет қаралды 34 М.
Reinventing the Transaction Script - Scott Wlaschin
1:01:04
NDC Conferences
Рет қаралды 16 М.
Domain Modeling Made Functional - Scott Wlaschin
49:02
DevTernity Conference
Рет қаралды 2,4 М.
Functional Design Patterns - Scott Wlaschin
1:05:50
NDC Conferences
Рет қаралды 295 М.
The Functional Programmer's Toolkit - Scott Wlaschin
1:05:51
NDC Conferences
Рет қаралды 69 М.
Why Isn't Functional Programming the Norm? - Richard Feldman
46:09
7 Days Stranded In A Cave
17:59
MrBeast
Рет қаралды 95 МЛН