 This is what the funk, that's my joke. I'm Tim Hess, I've been solving technology problems for about 13 years, primarily using Microsoft Tech. I've been doing a lot of C-Sharp and Visual Basic development, primarily web development. I'm absolutely not an F-Sharp expert, so I apologize for that. But I guess an upside to that is I've only put a few weeks into it and I can see the value in it. So hopefully as a result of this, if nothing else, the rest of you will go out and try it as well. So F-Sharp has kind of a strange reputation. You either are afraid of it or have no idea what it is in general. So I want to spend a minute and talk about what this talk isn't. We're not going to get into the depths of the language. We've got a half an hour. It'd be completely unrealistic to get into that. It's not a new variation of features. Same concept, not a lot of time. And the scary part of most functional programming is advanced math. A lot of functional programming tutorials involve complicated theory and we're not getting into that. This is just going to be some practical application for F-Sharp and we'll show some real code of it in action. And we're not touching monads. If you're familiar with that term, good for you. If you're afraid of that term, I don't blame you. We're not going to talk about it because we don't need to. So before we dig into it, why bother? Well, in the case of F-Sharp, you're probably not going to use it in the real world, which is unfortunate because it's really cool. It's more about just learning a different way to do things. And this guy has a good quote on that. F-Sharp and learning it will provide you a different way of thinking about how to solve a problem. So the more tools in your tool belt, the easier it is to solve problems. F-Sharp is another good tool to have in your tool belt. A quick note about links. The slides are available online, so feel free to download them. Don't worry about trying to record them at this point. F-Sharp specifically has some cool things that C-Sharp doesn't have as .NET languages go. There is some stuff that has crossover from F-Sharp to C-Sharp, like generics and async programming in general. This guy has a really nice post about some features that are still in F-Sharp that don't exist in C-Sharp today. The short version is there are some things that will jump over. There are other things that probably never will just because of the way that F-Sharp is built. And apparently this guy is one of the community members for F-Sharp, and he's a really smart guy who knows a lot about it, but he goes into his post and he says, you know, the explanation for one of these is too deep for me to even understand. So some really advanced stuff that was baked into F-Sharp since the beginning. So what is it? It's part of the .NET family. It's been around since 2005, so it's definitely gotten a lot of attention from a small group of people, and the people that use it really love it. It's been cross-platform since 2010, so they have some opinions on how to do cross-platform, and you can basically run it anywhere at this point in time, whether it's .NET Core, .NET Framework, or if you are really in love with it, you can use WebSharper and Fable to get JavaScript code and do some really crazy things. It is open source. It has been open source since the beginning, so if there's anything you don't like about it, you can feel free to talk to them about it, and they might shoot you down, or they might love whatever you have to say. It works in Visual Studio, Visual Studio Code. Specifically, there's a plugin called Ionite for Visual Studio. Visual Studio Code, that makes it a lot easier to work with. I won't pretend that it is as easy to work with in Visual Studio as C-Sharp. It's been somewhat of a second-class citizen for a long time, and historically it's been more of a work with your text editor to deal with it, but they have been making huge strides towards bringing F-Sharp into a first-class citizen status, and the examples later actually use ASP.NET Core MVC, which previously took a lot of extra work to make happen, and now it's in the templates, so it's gotten a lot easier. And of course, the F-Sharp community is active, and they love F-Sharp, so you can find them online and talk to them quite easily. They are extremely happy to answer questions, which is always a good thing when you're dealing with fringe technologies. So how does it compare to C-Sharp? I'm not going to go extensively into this list right now, but they're both .NET languages, so they work with each other, but the syntax is obviously different. They have different defaults, which we'll get into more, but functional versus object-oriented, they have different history. The philosophy behind them, they exist for different reasons. They solve different problems. And F-Sharp is functional first, which means that it's not purely functional. You can still do just about everything you can do in C-Sharp, even though you might not want to. And there are some ways that F-Sharp makes some things that C-Sharp does naturally more difficult than that, because in F-Sharp there's a different way, which F-Sharp of course thinks is better. There's a system of type inference. A lot of people love the var keyword in C-Sharp. Some people hate it. F-Sharp takes it 11 steps further and implies types for you all over the place, which saves a ton of typing. There's a lot of other features today. I'm not going to get into them. If you want just one really cool reason why you should look at F-Sharp that was too advanced to fit into this half-hour topic, type providers are an amazing topic. All right. This is a basic shopping cart class in C-Sharp. It all fits on the screen. It doesn't do anything fancy, but it looks pretty typical of a small class in C-Sharp. You can see it's got 42 lines, 900 characters. There's nothing real exciting here. It's just basic C-Sharp. Next up is this code in F-Sharp, which we can walk through together in a moment. You can see immediately that it's a lot more compact. We can trim a lot of white space, which doesn't serve any real purpose for most things. If you're familiar with Python, it's similar. The white space is important, and that's how we get in and out of functions. It doesn't seem like a whole lot, but you think about how much more code you can fit on the screen, and that just kind of becomes an immediate benefit of using language like F-Sharp. The character count difference is largely due to type inference, and I should be clicking through these. No semicolons. You can use them in some places. They have a purpose, so if you love your semicolons, they aren't gone completely. Same with the curly braces. Type decorate declarations, which is extremely convenient. Now, access modifiers. One of the different defaults that we'll get into is immutability by default, so as a side effect of that, we don't typically declare access modifiers in F-Sharp nearly as often because it's generally immutable, so you don't have to worry about somebody trying to modify a class or a property they're not supposed to because they can't. And just a simple syntax difference, you'll notice type and let all over the place. Those are the equivalents of class and bar. You also do not need return statements. These true statements are the implicit returns just to match it up with the C-Sharp class library, a class that I had on the screen previously. And just for a nice little side-by-side, the F-Sharp class and the C-Sharp class. They do exactly the same thing. And like with most C-Sharp to F-Sharp conversions, there is a significant reduction in size, which I don't think hurts readability, particularly in this case. There's a lot of tricks you can do with C-Sharp. You can put things on one line that maybe you shouldn't. In F-Sharp, you get the same kind of benefits that you would have to do some crazy things in C-Sharp that may not be best practices, but it just kind of works in F-Sharp. So the defaults. What do I mean by default? Well, in C-Sharp, everything can be null. You have null references and exceptions all over the place. In F-Sharp, you have to do a little extra work for things to be null, and it's generally a code smell. If you have things that are being declared as null in F-Sharp, so they prefer that you don't do that. And that's what that attribute looks like. Another default option that's different is immutability. I already touched on that. In order to create something as mutable, you have to use the mutable keyword in F-Sharp. And not only that, the operator to assign a new value is different. I'm sure that has a name, but I don't know what it is. The little less than dash sign is how you assign a new value to a mutable thing. Mutability. Things don't change when you don't expect them to. Okay, so structural equality is... It's extremely common in C-Sharp to want to compare the value of the properties of an object. By default, you get that with F-Sharp out of the box, whereas in C-Sharp, you're having to override the equals operator, get hash code. There's extra work to do, and F-Sharp just gives you that for free. And it looks like that. This is a record type, which I linked on the other slide. It's just basically an anonymous inline type you can do interfaces inline. Again, additional, really cool functionality that you get to if you play around with it more. So, C-Sharp and F-Sharp exist for different reasons. What does that mean? C-Sharp comes from C, no surprise there. F-Sharp comes from ML. It is effectively the .NET version of OCaml. And one of the main goals of F-Sharp is to help you write predictable code, and you get that by the compiler doing more for you. So, you get that inline functionality, and all ability, so on and so forth. I'm going to talk next real quickly about a couple of really neat features. Pipelining. If you've used bash or PowerShell, you just pass the output of one function to another. It is extremely easy in F-Sharp. You can pass forward, you can pass backwards. It's really common, and it's one of the most popular operators for good reason. And the implicit returns that was mentioned on the previous slide is part of what enables this to be extremely easy. So, an example. We've got a case where we were asked to output the value of all even numbers in a list. So, we've got some basic functions that we've got to find to get us started here. So, the one way of doing that looks about like this. It's fairly simple to just say, here's a line to get the even numbers out of that list and then another line to square them. It's not the worst thing in the world, but we can do better. Next version. We write it all in line. The parentheses here used to guide the compiler for the right order of operations. In F-Sharp, you use a space between parameters, and that's how you typically do it. So, we group the interfunction call with parameters so that the compiler knows what to do with it and so that the type inference works all the way back out. It's still pretty easy to read, and it works. But if we throw in the pipe operator, it gets a little nicer. You can have different formatting options for it. This is the multi-line variance of the pipe operator, which helps if you've got more complex examples or you're doing a whole bunch of things with it. You can throw it all in one line if you want it to get nice and small. All right, so type inference, another cool feature. I'm not going to read that. So what is it? Types are inferred. It kind of speaks for itself with the name of it. I love Microsoft and their obvious naming conventions. So, why less typing? Why retype the type when the compiler can do it for you? We're programmers. We're lazy. Let's let the tooling do the work for us. Another reason it's important is that we can focus more on what matters. There's a better signal-to-noise ratio when we reduce the amount of characters and code that we just plain don't care about. So what does this look like in action? Well, this is the distinct operator from the link source code. This is how C-sharp has this method signature defined. You can figure it out if you work your way through it, but it's a little bit less than ideal. If we were to take this exact same function and write in an F-sharp, it looks like that. So you can kind of see how much that can really affect your day-to-day life when you start thinking about advanced enterprise programming with C-sharp and whatnot. Let's look at some real code. I have a fun store application that... We'll have the source for this at the end on the slides. This is a fairly standard style of .NET application. There are four microservices. That didn't work. That's a little better. Can you read that? Kind of. All right, we'll make it bigger. I'll just talk you through it. We've got four applications. There's a cart service, an order service, a front-end store, and an admin application for managing inventory processing orders. And we've also got two-shared libraries, one that's written in C-sharp, where the intent was to put models just to kind of show how you can interop with your legacy C-sharp code or new C-sharp code if you've got maybe multiple teams where one team likes C-sharp and one team likes F-sharp, or you've got some cases where C-sharp is the right tool for the job, F-sharp is the right tool for the job. The point of putting all of this together was just that it all works. So how do we set up SteelTow? That's an important thing to do in Cloud Foundry. The program main in F-sharp looks like this, whereas in C-sharp it looks like this. It's not too exciting for me because I work with this all the time, but it's important to see how it works. If you don't work with it all the time, it's one of the first questions. It's like, how do I really apply this? And you can see that we don't specify types in as many places. It looks really similar because it's all .NET. So I have this running in Cloud Foundry. Of course. It's a fun store. I made inventory based on font awesome icons. I thought it was fun. It was easy. I didn't want to have just plain text. I live in Wisconsin. We just had a snowstorm in April. It was a pretty big deal. If we add that to the cart, we break it because my session expired or something along those lines. I'll try it again. Okay. This demo app is just a basically really simple e-commerce type scenario. But the F-sharp MVC web application just works. It's got F-sharp on the MVC side. It's still using razor-style C-sharp syntax for the views. So if you're familiar with C-sharp, it works the same in F-sharp. I did find that it got unhappy with me a lot. The C-sharp razor stuff doesn't work as well in an F-sharp project. Largely because it uses a different compiler. So your C-sharp stuff will have the Roslin compiler running in the background. And your F-sharp stuff depends on the F-sharp compiler. They don't always work the best together. And I'm assuming that's going to get better. I worked with F-sharp a little bit in the past to try it out. A royal pane is set up. And now you get templates out of the box. But the tooling is still a work in progress. Cart contents, place and order. Like I said, it's a really basic app. So the admin side of it just has a mechanism for viewing orders, processing the orders, standard e-commerce type stuff, sting inventory. Someday it will have managing inventory and security and all the standard interesting things about that. Back to the code. Wearing it up is really exciting. Okay, more comparisons here. Again, basic.net. In F-sharp, everything has a return. So if you don't want to do something with that return, you will get compiler warnings if you don't tell it to ignore the return. It's kind of annoying that you have to type more, but it's important because the compiler tells you, hey, there's a thing here that's coming back. Are you sure you don't want to do something with it? Maybe you do, maybe you don't. Obviously, in this case, we don't want to do anything with anything that comes back here. But it's just another case where F-sharp really helps you to do things right. Another nice little comparison here with the values controller. This is the standard default out of the box values controller from F-sharp versus with C-sharp. And again, the main difference is the curly braces, but the implicit returns, you know, you have to, say, return new string array here, whereas it's just all in line. Here's a string array. Figure out the type for me compiler and you're done. Another one of the ways that I got a lot more familiar with F-sharp was something called F-sharp Cohen's, which is a really great place to start. Again, this is a GitHub repository. The link is in the slides. And the way that it works is a bunch of F-sharp code is out here. It's all structured for you. Most of it is written. All you have to do is fill in the blank. So in this particular case, it's explaining how let works. And, you know, we just declare a mutable value of X. It's at 100. We assign 200. And then you just ask you to fill in the blank and say, well, what is this thing worth? And if you just run it, it blows up because I'm in the wrong folder. So it's a really straightforward example of how to learn the language and I highly recommend it. On your journey to become an F-sharp guru, what's left? Scott Willaschen is much better at talking about F-sharp than I am. He also has a fantastic blog, which has every sped is not right. Powerpoint does not like it when you do that. Sorry about that. So Scott Willaschen has F-sharp for funandprofit.com. That blog is an excellent place to go and read all of the things about F-sharp and why it is a great thing. It is extremely easy to follow. He has a great job of explaining it for C-sharp developers. The F-sharp cones that I mentioned, lots more examples of how to get started with F-sharp. If you want to try and run F-sharp in your browser and you don't mind running Silverlight, try F-sharp.org is for you. If you think that Silverlight is a silly thing to use, maybe try .NET Fiddle. I have no idea why try F-sharp.org is still using Silverlight. It's a little disappointing. F-sharp.org, again, that's the primary source for their community. These resources are many more available for you. The source code, you can walk through it yourself, which will probably take you in directions that are more interesting to you as an individual developer rather than this general overview. If you want to get a hold of me and tell me that this was awful or great, whatever you want to do, Twitter, GitHub, and we're on Steel Toe Slack. That's where you can find me. I want to encourage you all to go to the Spring One platform in September. September. Any questions? Yeah. Start up? Sure. It's in the templates. I didn't dig into it a whole lot. Yeah, you can do that. Yeah, so that's effectively this right here. So you can. But not all of it returns exactly the same thing. So it's one of those cases where the compiler will really help you out. In some cases, in this case, a lot of it was copy, paste, and then modify. So it wasn't build it all in one line. Sometimes it works great to chain it. And sometimes you do want it broken out like this, especially when you're passing in the configuration to different methods, things like that. You may not want to necessarily repeat it all in line. Yeah. Well, like I said, Fsharp's been a curiosity of mine. So this was kind of my excuse to try and run it. And it works in Cloud Foundry. It's a .NET language. So you can do it, absolutely. And some of the hardest things were just learning the syntax difference and just plugging it all together. And if nothing else, here's one that you can just CF deploy or CF push. And it should just work. There's a lot of features that I didn't get into, which I apologize, again, I'm not an expert. But the point of it was that it's easy to start, right? So the places that it's most commonly used are probably in finance and advanced mathematics, largely because that's been the history of it. But it does work for anything. You can write a lot less code and do more. And the more advanced features are where it really starts to shine. The type providers that I mentioned are effectively ways to interact with data stores or whatever external data sources without using an ORM. So for example, there was a demo that I saw not long ago that involved using a Star Wars API. And they just reached out and queried it using type providers. But it's kind of, it's difficult to do this talk. It's starting from scratch because the type providers kind of build on a lot of other things. So a lot of these concepts are extremely cool and you can only get a taste of them once you kind of understand the basics. Yeah, well, the math is going to be the primary one. Jet.com is using it, as I understand for all of their stuff. They used to be a lot more vocal about what they were doing. Once they were acquired, I think they stopped talking about it. They shut down their tech blog. I'm hoping to use them for some source material and some inspiration for what to talk about and how to focus on it. But they took all that content away. So anything else? Yeah, I published locally before pushing it. So that's been a lot more successful. This was all actually using .NET Core 2.1 Preview 2. So we got two minutes if anybody has anything else. Otherwise, we can call it good. Thanks for sticking around.