C# Corner MVP ft. Bohdan Stupak
4K views
Nov 9, 2023
Join us on December 9 with Bohdan Stupak to learn Using Span in C#. ABSTRACT Span is a C# 8 feature that allows improving the performance of C# code almost with no effort and without sacrificing its readability. In this talk, we'll take a more detailed look at it AGENDA • Overview of Span internals • Some code examples in C# • An example in F# LEARNING OBJECTS: • Why Span is needed • How it is structured • How you can use it in C# code • A bit about F# support C# Corner - Community of Software and Data Developers
View Video Transcript
0:30
all right hi everyone welcome back to c-sharp corner live show as always i'm your host
0:55
Stephen Simon and we are back with another episode of C Sharp Corner MVP show and for this episode
1:01
I'm really excited we have someone who's joining us all the way from Ukraine he works on C Sharp
1:11
JavaScript and F Sharp I mean when I just went through his C Sharp Corner profile and he works
1:19
on F Sharp I've not seen many people working into the field of F Sharp and it would be very interesting
1:24
to know on what different kind of projects he works and uh and how did he get into this f sharp
1:31
thing but before we go in and invite our guest to the show today if you are someone who is joining
1:36
us for the very first time we do this c sharp corner mvp show every once wednesday at 7 30 p.m
1:41
uh indian time zone and 9 a.m eastern time zone and uh apart from that on thursdays we do ask
1:49
many things shows tomorrow we're going to have uh bob who is who has been at microsoft for more
1:54
than 25 years and we're going to talk about sql server edge to cloud and you can just bring in your
2:00
questions uh in that event too uh then on friday we have growth minded show that's why mahesh
2:05
who is the founder of c sharp corner he goes and talks about how you can go ahead and move in your
2:09
carrier i think the last episode we talked about the full stack and in this episode we're going to
2:15
talk about react versus angular versus blazer and all the c-shap guys right so you guys love it then
2:22
one of the very exciting shows that we run on saturday's weekends that's by david mccarter
2:28
that's rocking the code world dot net dave he has some really exciting guests coming in and he's had
2:34
uh kate and all those big guys in the in the industry of dot net and even just not in dot
2:42
and even on the cosmos tv and all that stuff so he brings really nice guests on his shows too
2:49
so having said that uh without any further ado let me go ahead and invite our
2:54
guest uh hi both and welcome to the live show uh thanks stevens thank you for having me it's
3:00
a great pleasure to be here uh thank you so much for accepting the invitation boden uh i was just
3:06
looking at your profile you come from ukraine so what time is it over there
3:09
It's 4 pm now. Even it just starts since the beginning of the evening
3:16
Okay, that is a word. I know you often go and contribute on C-chop platforms, you have written many articles, you are very active on forums
3:26
But still, I will ask you to give a little introduction about who you are, what you do, and what kind of stuff a little bit about you
3:33
little bit about you. Basically now I'm the .NET developer in one of the
3:39
companies you know I can't name the business details due to some NDA
3:44
restrictions but on the technical side which I guess the more interesting for
3:48
all of you my listeners is we're doing a lot of different things we are leveraging
3:54
GraphQL for our API we're doing elastic search for full text search which is also
4:01
also quite inconvenient. Also, we're trying to space out some bits of performance
4:05
because it's quite high-loaded projects. We're doing some microservices which communicate via RabbitMQ
4:12
Lots and lots of stuff, lots of ground to cover. Also, maybe some stuff that I'm looking forward
4:19
to explain more in details in new C Sharp Corner articles. That's very important
4:27
And also, when I look at your content on C Sharp Corner
4:30
the articles you have written you cover a very big ecosystem you not just talk about dot net or c
4:36
sharp you also talk about uh a cooking angular with typescript right you also talk about building
4:42
auth and point with go and aws lambda i mean then there you go with the co programming language
4:48
then definitely you work on f sharp and all that stuff so how did you go ahead and learn and work
4:53
on so many different frameworks at the same time uh you know to be honest always uh the main
5:00
specialization for me was C-sharp but I love to try new things and also I guess
5:05
the main point is all those new things are somehow making a better developer of
5:09
you. For example I'm really really fan of F-sharp and I think it's really really
5:17
helped me to become a better developer and better C-sharp developer. So you know
5:22
at the beginning I was believer that F-sharp will take as big notion as Scala
5:27
for JVM, but unfortunately it didn't happen, but it changed the other way. If you follow the novel
5:33
C-Sharp 8, C-Sharp 9 features, you can see that almost all of them, such as pattern matching or
5:39
record types, take the past from F-Sharp. And the thing is that basically all those functional
5:45
approaches are trying to get traction in mainstream development, and that means that a lot of
5:50
passionate developers who are looking how to improve their code, how to better write their code
5:56
they look into F-Sharp and they get some valuable insights. For example, one of my articles
6:03
in the C-Sharp Corner was refactoring string into a specific type, and it was the case of primitive
6:09
obsession, which is basically object-oriented smell. But once I'm noticing my code, because I
6:14
So I was starting to think how I would model that with N-sharp
6:18
So basically all the stuff that I try, all those new libraries, approaches, techniques
6:25
they basically helped me to become a better C-sharp developer. Yeah, definitely
6:31
Some of your articles have been really appreciated by the other community members
6:35
People like to go ahead and read your article. And pretty in-depth, you know, just go ahead and write it
6:40
You also come up with some code samples. There's an explanation. There's a conclusion coming up, so definitely articles are written in a very wise way and
6:49
people definitely appreciate it in the community. So having said that, Boran, what are we actually going to talk today
6:54
I mean, what are we going to learn in the next 30-35 minutes
7:00
So today we're going to talk about Span of T. It's the family of value types that allows
7:06
you to allocate less unmanaged heap, which in turn allows to improve performance
7:10
Relatively, this is a novel feature on one hand, because I've seen quite a few people using it in their code bases
7:19
But on the other hand it quite a old feature because it was introduced in C Sharp 7 and now C Sharp 8 and C Sharp 9 Still I think it will useful for a lot of developers uh to know what it is and how to use it they call it yeah quick question before you go ahead and
7:39
start your presentation and with your demos uh uh i have been i've been taking interviews for very
7:44
familiar people we even had this dotnet conference recently it went for two days uh i have not seen
7:49
many people talking about this topic like people don't really discuss about it so so why is it that
7:54
you chose this topic to go ahead and talk about today? I guess there are a couple of reasons why people don't talk about this topic
8:02
because I guess one of the reasons that people are expecting some more
8:07
some bigger improvements, some more major concepts, and this looks like a quite small feature
8:13
The other thing, I guess, why people don't talk about it much
8:17
is because, you know, in day-to-day job, You don't always consider the performance
8:23
You don't always do some heavy benchmarking. You know, day-to-day job is more about working with business requirements
8:29
But one of my points is to show that you don't necessarily
8:33
to write some performance critical code in order to use this feature
8:37
because it's relatively easy to use it. I'll show you later. That definitely makes sense
8:43
I'm really excited for your sessions. You can go ahead and start sharing your screen and put it in the live stream then
8:49
oh sure sure let me share my screen uh finally share it let me ask you a quick question did you receive your c-sharp on every
9:00
ticket uh i'm not sure i hear the question properly i said did you receive your c-sharp
9:08
for that mvp kit oh no i believe i didn't oh why why is that well just we'll just follow up and
9:18
we'll just send it to you i think it might be okay also you're a mvp from uh september 2020 right so
9:24
that that's scheduled for april 2021 all right that makes sense then all right i'll i have your
9:30
screen into the live stream now and the next segment is all yours
9:35
So Stephen did a really really great introduction so let's just jump straight to the business. So as you already know my
9:48
talk is using Spanty to improve their performance of the code. And basically
9:53
Spanty is the family of value types that write in C sharp 7.2 and it allows to
9:59
represent your contiguous regions of memory in allocation-free fashion. We'll discuss later what this means and how it helps us
10:09
So the first thing is some sort of disclaimer. You know you can find a lot of material in the internet how to work with managed heap
10:17
how to allocate less on managed heap, how to do some heavy performance optimization with
10:22
memory heap. But my experience tells that if your goal is some unspecific performance improvement, like just make my application run faster
10:32
In such case, I suggest you first looking at the duration of your I.O. calls, because my experience tells this is the part that tends to be the slowest
10:42
However, if you exercise all your options with I.O. calls, for example, you use batch and you use cations, etc., etc.
10:50
or if your goal is specifically to reduce the memory footprint of your application
10:55
then you might consider to locate less on the managed heap. And one of the options that might help you with this is the SPAMPORT
11:05
which today I'm going to talk about. So, at first, let's get back to some basics
11:11
Recall some really basic stuff. You know that managed heap data is stored there quite critically
11:19
which leads to quite slow access. And another point is that once you are done with your variables on managed heap, they get garbage collected
11:30
And garbage collector is heuristic, which in turn also requires some resources
11:35
and which also suspends threads while it performs garbage collection, which also may bring to more performance penalty
11:43
But there are also some advantages you can allocate quite a lot on managed heap
11:48
It has a relatively big size. Stack, on the contrary, as you all know
11:53
is last-in-first-out data structure, which means that once you use the variable
11:59
you just pop it out of the stack, which means that it has fast access and it doesn't require
12:04
any garbage collection. But the downside is that it has a relatively small size
12:11
So you can't allocate quite a lot on stack, and you have to be careful with that
12:15
And always that means that you need to benchmark your code in case you doubt whether you should or shouldn't allocate
12:25
on stack. Now, basically, there are two ways to allocate on stack
12:29
One of them is using the value types, which could allocate on stack in some scenarios
12:34
And another is using stack log and unmanaged memory. Those of you who have worked with unmanaged memory
12:43
that is quite tedious process. Here is the example of code that manually allocates memory and stack
12:53
and it works with a managed memory. And I personally, I doubt that this is a human readable code
13:00
I mean, definitely somebody can produce this code to deliver some performance improvements in some
13:07
critical regions of your application, but I really doubt that this code will be supported
13:14
and will be changed easily. And one of my points on my presentation is to show how Span really
13:22
allows you to work with those regions of memory, manual, and stack in more convenient fashion
13:29
Here's the slide that tells it that really Span of T can help you with that
13:34
At first, let's have a look at the internals of span of T in order to better understand
13:41
what it is, how it works, and how it's structured. You know that there is a mantra that reference types are allocated on heap, whereas value
13:51
types are always allocated on stack. But technically, value types aren't always allocated on stack
13:58
Depending on circumstances, they may be also allocated on heap. For example, when those instances of those types are boxed
14:06
Or for example, when they are parts of larger reference types. So in C-sharp 7.2, a ref struct modifier arrived
14:18
This modifier allows you to mark your type, to mark your struct
14:24
So it will be always, always allocated on stack. It can never, never escape on the managed heap
14:32
But in turn, it brings some limitations to you. Here they are listed
14:37
I'll mention a few of them. For example, you can see that ref struct can be boxed
14:42
It can implement interfaces, because once you custom the simple interfaces, it again leads to boxing
14:49
It can be element type of an array. It can be captured.land expression
14:54
It can be a field of reference It can be field of non struct struct And some other limitations are listed also here
15:06
Another concept you have to master before you dive deeper into the span of T is ref returns
15:14
As documentation reads, a reference return value allows a method to return a reference to a variable
15:21
rather than a value back to a color. I'll be honest with you, this definition really doesn't communicate much to me
15:31
So what I'm here for is to look at some code, which will explain what all this means
15:39
So as you can see, here's the class Artistor, which basically just encapsulates an array
15:45
of musicians. These are some musicians that I deeply enjoy. And also it exhibits two public methods
15:52
One of them returns the second artist of the collection in the traditional fashion, we adjust the return
15:58
Other uses the novel ref return feature also to return the second artist
16:04
Also, there is a property AllArtists, which is just comma separated list of those items in the container
16:12
So, now let's call those methods. Here you can see we create this artist store and we return an artist via a traditional method
16:21
Then we try to assign new value to this variable, to the variable artist
16:25
Here it is Henry Kahl. Then we examine the original array. Basically, now we see that inside the original array, values are left unchanged
16:35
Because we changed the value of the artist, not the reference to it. Now let's have a look at the second example, when we use returns in the artist by ref
16:45
Here we use the novel ref return. We get the artist, then we assign Frank Zappa to it
16:50
Then we examine all artists again, and we can see that again it is left unchanged
16:56
So at this point you may be wondering what's the difference between
17:02
novel ref return and just the traditional method. And here is what is the third example after
17:10
Now again we call return single artist by ref, but now we use ref modifier near the caller and
17:17
and near the var keyword. Then we assign a new value of Valentin Silvestrov, this artist reference
17:24
and once we examine our original array, we can see that this prominent Ukrainian composer is now on the list of musicians that I enjoy
17:33
So basically we got the reference, we changed it, and we changed the original value because we have worked with the reference
17:40
Now, with that said, we can now finally have a look at the sketch
17:45
of implementation of SPAN . So the first thing that you might notice is that SPAN is a ref structure
17:54
So if you remember the first slide where I mentioned that SPAN allows you to work with
18:01
this contingent regions memory in allocation-free fashion, here's what it means. Here's why it is in
18:07
allocation-free fashion because SPAN is a ref structure, which means that it can't be allocated
18:14
on heap at all, it will be always allocated on stack. But in turn it leads to some downsides
18:20
because as I've already mentioned, refstructs have a lot of downsides in order to be sure that they're
18:26
allocated just in stack. So again, refstruct can be boxed, it can't be part of a class, because
18:36
class is not refstruct, and so on, so on, so on. It leads to some limited, it narrows down the scope
18:42
of usage, but still, as I'll show you, it's quite a useful feature. Another thing that I ask you
18:49
to notice is that we have indexer. You can see this public indexer, public ref t, this, and index
18:57
which basically says that you can access the elements of span by index. So this is contiguous
19:03
regions of memory, which basically means that this is arrays, and the crucial operation for array is
19:08
accessing by index. And the main point here is that this not just
19:13
accessing the value by index, but it's accessing the reference due this ref return feature. And basically in order to access, you just
19:21
use the reference to the pointer, which is the reference to the beginning of the
19:25
array. And index is just the offset from the beginning of the array
19:33
So that's pretty it. That pretty explains what span T is and how it's
19:38
implemented. Now, let's have a look at this Panoft in action. The first our task and the first our
19:45
demo for today will be to rework the existing code base, which converts Linux permissions to
19:51
the actual presentation. You know the .NET Core is here for a while, but to be honest, I'm a
19:58
a Windows guy, and I believe that a lot of my fellow listeners are also Windows guys
20:08
So here are the rules, what actually we call it to us, and the rules are the following
20:15
Basically we will have the three blocks of three characters, and the actual representation
20:20
is the three digits, each of them is the sum of permissions inside the block
20:26
all those digits get concatenated. Let's have a look what are those digits. So you can see that
20:33
for read permission is 4, for write permission it's 2, for execute permission is 1, and if we
20:39
have no permission, it's 0. Now let's have a look at the example. Here you can see the string. It is
20:47
broken down into three blocks. First is read, write, and execute, which stands for 4 plus 2 plus 1
20:56
This is seven. Another one is just read and execute, which is four plus one
21:02
This is five. And the last one is just write, which is basically two
21:07
Then we can continue those numbers, and we get 752. Now, when you know the rules, let's jump to the code
21:19
And also, not just jump to the code, but also run some benchmarks
21:23
So we've already set our... build configuration to release. And we'll start the benchmarks because it's quite a consuming process
21:35
So, wow, that went quite unexpectedly. Let me check if I can somehow fix this
21:51
It's really really really unexpected. Let me see if I can start it from the debug
22:03
Oh, I see I see. Let me reload the studio. I terribly, terribly
22:10
apologize for that small inconvenience. I hope we can combat this. In case we
22:18
We won be able to combine this I just dive through the code and you will have to believe me that the code with the span of T runs faster But I hope that we won have to do this
22:36
So yeah, benchmarks are running, and while they are running, we can finally examine the code
22:43
So basically we have two files of interest here. One of them is symbolic utils 2, which is the
22:50
traditional representation. And the other one is symbolic utils, which will be our worked
22:57
representation. So what are the points of interest here? Here we accept string input, and then we call
23:05
symbolic utils permission, which is class, we call static method parse, which accepts string input
23:11
So let's get back to the implementation. You can see that this is some sort of static factor
23:20
which accepts strings. It validates that our string input conforms all the
23:28
needed requirements that are needed for a string to be actually a Linux
23:33
permission. If it's not, we fail. Otherwise, we call a private constructor, which
23:38
again accepts string, and in the private constructor we assign the parameter to the private value. Nothing fancy. Again, as you can see, this is a string
23:52
So now, once we have constructed the valid business object, we just call the method getOctal representation of that object
24:04
Here is nothing fancy. I guess the main point of interest here is that we just call the substring
24:10
of that original value. Now let's have a look at the reworked implementation
24:22
Now on the surface it looks pretty similar. Now again we call the static factory and we call the
24:29
manual geological representation once we construct the instance. But here is the fun part. Now parse
24:36
accepts redondely span of char. So remember in the beginning I mentioned that span of t is not
24:44
just a value type, it's a family of value types. And one of the members of this family is redondely
24:51
span, which basically signals that you don't modify the input. You just use it for your own reasons
25:00
And the thinking here is that, as you all know, string is the array of characters basically
25:06
So instead, working with the array of characters, which is just the contiguous region in memory
25:11
you work with the red-only span of characters, which is the same representation of contiguous
25:18
region of memory, but in allocation-free fashion. So now we accept this parameter. We call the
25:27
private constructor, which again accepts red-only span of char, and we assign it to private value
25:34
which again is redondellist point of char. So once we calculate the octal representation
25:41
we again calculate the substring of this private field, but now with the slice method
25:47
So it's basically the same, but instead of substring, we just use the slice method
25:52
So I hope our benchmarks are done at this point. And you can see that redondellist point is a bit
26:00
faster really. It allowed us to save like half of nanosecond and it also allowed us to reduce the
26:08
consumption in the generation zero of managed heap, which is quite obvious because we work now
26:16
with the reference structure. And I won't lie to you that this is like something groundbreaking that
26:23
will make your code rocket fast. It's quite a modest performance improvement, to be honest
26:29
But on the other hand, look how simple it was. We just replaced the array of strings with the read-only span of strings
26:37
or, excuse me, array of characters with the read-only span of characters
26:43
So my point here, and the point I wanted to show, that this is quite a low-handling fruit that you can easily apply to your code
26:52
and it won't sacrifice any readability. It won't sacrifice your productivity. And with this, you can still gain some performance improvement, even though it's quite modest performance improvement
27:05
Now, with that said, let's get to another example. In the previous example, we worked
27:12
at the array of characters, but in the same fashion, we can work with the arrays of other types
27:17
So here's the code I've taken from sp.net pipelines. The task of this code is to convert
27:27
buffer into unsigned integer. And the trick here is the data in buffer may be in different
27:33
memory segments because basically it drives over the network. So let's break down what this code
27:40
does and let's start from the very, very end. As you can see in the very, very end, we just use the
27:47
text span variable, we try to parse it with the parser. If we fail, we just throw the exception
27:53
If we succeed, we're golden. So now let's have a look how this text span is populated
28:02
If the buffer has only single segment, which this flag suggests, then we just take this first
28:09
segment and we are assigning to the text span. Otherwise, things are more complicated. We manually
28:17
allocate 128 bytes on stack with the stack-locker braille. Then we craft the span byte based on
28:28
that data manually allocated into the variable of destination. After that we call the buffer
28:36
copy to method, and we copy to the destination. The thing is that copy to iterates over each
28:42
segment of the buffer and copies that into the span. After that, for the case when the buffer
28:50
length is lower than 128, we just slice the destination from the beginning to the length
28:57
of the buffer into the text span. So things are pretty similar, pretty simple, and the thing is
29:03
that we are manually allocated data on stack and still this code looks quite readable and quite easy
29:11
to digest. And also the last example I wanted to show is the F-Sharp support for this noble
29:21
family of value types. Again, let's just jump back to the studio, to the same code example
29:29
but a couple of comments ahead. So the thing is that the F-Sharp is the first-class .NET
29:36
citizen. And you know, the thing is that when you read the articles about the .NET stuff
29:43
you always see just C-sharp examples and you get the feeling that C-sharp basically is the
29:50
only option for that. However, that's not quite true. And we can check out how this feature is supported in R-sharp
29:59
too, and how it is really, really useful. So we have, oh benchmarks are running, great
30:07
So we have two same implementations that we have already seen, and here is the third implementation
30:16
On the surface, it looks quite the same. Again, we have struct symbolic permission 3
30:22
which again calls parse, and then after we get the valid business object, we again do parsing
30:28
However, things get pretty interesting here. Now, instead of calling the private method convertBlockToOctal, we call this new helpers convertBlockToOctal
30:42
Here in the C-sharp code you may think that this is just another C-sharp class, which
30:50
also leads to another point. In fact, this is not C-sharp class, but it is the F-sharp module that is declared in a separate assembly
31:04
So my point here is that if you want to try F-sharp, you don't have always just to rewrite all your code base at F-sharp at once
31:15
Furthermore, if you start some greenfield environment, you still don't have right all your code in F-sharp
31:24
Because C-sharp and F-sharp code are basically interoperable. And I know some guys who basically enjoy some impure interaction with input-output in C-sharp because it's more convenient
31:38
However, their domain, their core logic is purely functional F-sharp logic. and people really, really benefiting from those functional approaches of F-sharp
31:49
without sacrificing the convenience of working with mutability in F-sharp. So, now let's have a look at the convert-block-to-actile method
32:01
The syntax is quite tertiary, but it does pretty the same as it does its C-sharp counterpart
32:09
as well, it just accepts red-only span of char. And there are really, really no problems with just
32:17
accepting red-only span of char, the same fashion as C-sharp does. So, which basically means that
32:25
red-only span of char and red-only span of T in general and span of T in general is also supported
32:31
in F-sharp. Here, also, a couple of points of interest. Here, in F-sharp, you don't declare
32:38
classes and structs in convenient to C-sharp guys fashion. Instead, you just use the types
32:45
and you denote whether it's a class or struct via this attribute. And also one fun point here is this
32:53
while keyword, which allows you to declare the field later. Here it's to assign the field later
33:04
here it is assigned it later. It allowed me to save some bits of performance, which in turn will
33:10
allow me to show the benchmark result that I'm really, really proud. So I hope the benchmarks are
33:17
done. Yep, they are done. So here you can see that again, read-only span is a bit faster than the
33:24
original implementation like 0 nanoseconds and also it allocates less Now let have a look at the implementation with the sharp helper Here are some pros here are some cons The pros are that it really really fast It way faster than its C counterpart
33:44
Even it's way faster than C-sharp code that uses span of T
33:50
However, there's also a downside which says that we allocate quite a lot
33:59
This is because we declare this helpers type, which in turn uses all those permissions
34:07
For the demonstration purposes, I've increased the numbers of block in order to get better
34:14
difference in the performance results. However, it's still really, really fast. And if you're on top and you think that F-Sharp is something for some couple of computer scientists
34:25
that it is not practical language. Here's the numbers that show the opposite
34:30
However, still, another point is that once you try some performance improvements
34:35
still you have to benchmark those improvements in order to be really sure
34:39
that they have in your case. So now, once I've showed you this example, let's jump to the conclusions
34:51
So, as you have seen in my presentation and in my code examples, using SpionT is the improvement
35:03
is the change that is really easy. It doesn't sacrifice the productivity, it doesn't sacrifice the code readability
35:09
However, it still allows you to get some performance improvement. And I think that is really great
35:16
And here I listed some things that you might consider when you decide whether you should
35:20
use span of t. So you should use it if a method accepts an array of data and doesn't change its
35:28
size. Also, if it doesn't modify an input at all, then you might consider using redown with span of t
35:36
as in one of my examples. Another consideration is when your method accepts string to count some
35:44
statistics to perform some synthetical ysis, long story short, where it doesn't modify string
35:50
Then instead of string, you should accept predominantly span of char. And the last point, if you return a short array of data
36:01
Now the keyword, again, here is short, because as I mentioned in my slides
36:07
you can't allocate a lot on stacks, so you have to be careful with that
36:12
However, if your return array is short, you can return span of t instead of array
36:17
with the help of the following construct, which says stack a log of t and the size of your
36:24
contiguous region of memory. And here's the limitation that t should be value type
36:31
Now, with that said, I'm really thankful for your attention, thankful for giving me the possibility
36:39
to share some of my insights here. And I guess I'll stop sharing my screen at this point because
36:46
on the presentation. That was an amazing presentation, Boren. You started with very basic what is Span D, some features
36:57
You also had some demos coming up. Quick question. I mean, for instance, I could in C-sharp, right
37:05
And at what instance I should go ahead and start using F Because in the program in the demo any presentation you were talking about C and F very simultaneously and it did say that there are some developers who like to use f sharp and c sharp at the same time so what is the case scenario i should be using f sharp i guess uh the
37:26
experience uh tells me that one of the things where f sharp is really shine shines is domain
37:34
modeling because the sharp tab system is quite more advanced than C-Sharp and it allows you really
37:41
to model your domain in a better way. And as I mentioned in my presentation also, you know
37:48
when you practice DDD, for example, you know, your domain is free of all the external dependencies
37:55
of the databases, so on and so on, and it allows you to make your domain functional
38:04
So my point is that one of the things that really shines is domain modeling
38:10
Also, you know, there was some fun point which I mentioned in my serious way in one of my
38:17
articles and mentioned as a joke with my coworkers once they asked me what is the spin with functional
38:24
programming, why isn't it so popular? And I asked them, you know, guys, do you enjoy Linque? And they
38:30
said, oh, yeah, yeah, we really enjoy Linque. And I answered, oh, this is the functional programming
38:34
for you guys. And this is one of my points that I wanted to show, that when you work with the
38:40
collections in F-Sharp, it allows you to work in a really more declarative fashion, and functional
38:46
code to be more declarative, which is also quite beneficial for the visibility of the code
38:52
that that definitely goes when to use f sharp and it clears the you know the entire uh functionality
38:59
of f sharp we have a few questions coming up from the mvp's and from the internal channel
39:04
i'm gonna read it i okay i'm gonna just change the format this is too big to
39:09
add this better it says is it possible for something like param spanty to ever be a thing
39:14
in C-sharp. I don't know what that is, this is a question for you
39:19
Oh, to be honest, I've never really considered that. I'm not sure whether it's possible
39:26
because of the limitations that have struck with themselves, and also because params are
39:33
some thought of like array of the arrays. So basically, if you compare to this is Pantito
39:40
array then params is like real arrays but I guess we can have a try you know
39:46
yeah sure let me share my screen again and let's have a try let's look at some
39:59
of the of these implementations and let just try to say runs only spawn the chart
40:10
and here it says that programs must be a single dimensional array oh you can see
40:16
this is the thing that I've already mentioned that you know basically it
40:21
becomes an array of arrays so that's why compiler doesn't let you
40:29
you see the demo too, it coming up right at the moment in the live show that that's pretty cool
40:34
All right. So yeah, you can keep your screen. I just dropped it from the live show
40:40
All right. Yes. OK. There's one more question. I think that's the last one I'll take
40:44
I know we already running out of time OK this one How can I create a memory I don know the T from a span T Uh to be honest I never worked with the memory of T so I not prepared to answer
41:01
to this question right now. Yeah. But if someone who, uh, who's ever asked it from the internal channel, I think if you
41:07
just go ahead and simply Google it, right. And I think Microsoft has made a very good documentation out of it on how you can actually
41:12
go ahead and do it. Right. if you go to even this panty documentation in the in the recommendation somewhere you'll find someone
41:19
doing it and i think i did saw it the other day i was preparing for this live show i did see this
41:24
question coming up in the forum that people were definitely asking it so just go ahead and just
41:29
check some of the microsoft documentation you will find it under the recommendation i mean
41:34
if not the recommendation you'll find it somewhere if you just go through that link so but that's one thing and i don't know why people do ask this question at all so it's okay
41:42
all right but then uh before before we go ahead and end this question and this live show right
41:48
one one quick question apart from all this technical stuff we have been doing it for the
41:52
past 40 45 minutes okay is uh uh we do know you code you are a programmer you're you're a software
41:58
engineer and all that stuff what do you do apart from all this when you get free time what are your
42:02
hobbies what do you like to do other than this uh you know to be honest uh you don't click pictures
42:12
No, the thing is, as you can infer from my code examples that are really passionate about
42:20
the music, and this is one of my passions, and also I try to find to play musical instruments
42:29
like guitar sometimes. But the thing is why I found the question funny, because you answered what I do in the
42:35
spare time from coding, and one of the things I tried with the music is actually to program
42:41
the music. you know super collider and once i tried to program the music with the super collider so
42:49
i guess the programming programming is such a passion that i try to apply it into different
42:55
different parts of my life this is the most unique answer we have ever received in this question in
43:01
in this live show but my hobby is to go ahead and just program a music not many people would
43:07
say that so that was an amazing live show but people love reading articles thank you so much
43:12
for all that you have been doing for the community you not only uh you look at the other resources
43:16
you always go ahead and write for other people too so we at c-sharp corner really appreciate
43:21
what you have been doing it and i stephen simon on behalf of entire c-sharp corner community would
43:26
like to thank you uh and for all the contributions you have done and especially for coming to this
43:32
lives are taking your time and uh and we would love to have you back and maybe meet you in person
43:38
for the cshap corner annual conferences we could do it this year because of the pandemic
43:42
uh but maybe we may even travel to your place i think if everything goes fine cshap corner is
43:48
coming to europe so probably we'll just sneak into ukraine or russia too you never know
43:52
so thank you so much for that uh it was a really nice session and have a great day ahead and i hope
43:58
to see you soon uh thank you for presenting this great opportunity to deliver my talk here it's
44:04
really a unique experience and thank you for value and my contributions um have a good day too thank
44:12
you very much thank you everyone who was joining us today we'll see you on the next wednesday
44:16
and the next mvp show and tomorrow we're going to see you with bob bob board for the
44:22
sequels our edge to cloud i will have a ribbon season bye
#Programming
#Windows & .NET