Microsoft Community Insights Podcast

Episode 35 - Functional Programming with C# with Simon Painter

Episode 35

Dive into the world of functional programming with Simon Painter, a  .NET developer with 20 years of experience who literally wrote the book on functional C#. Simon breaks down this powerful programming paradigm in refreshingly accessible terms, comparing it to connecting Lego bricks to create increasingly complex systems.

Beyond his professional work, Simon shares his passion through teaching children Python at a code club, speaking at conferences worldwide, and authoring "Functional Programming with C#" (O'Reilly). Whether you're curious about a different programming approach or seeking more reliable, testable code, this episode provides a compelling introduction to thinking functionally.

Ready to explore functional programming? Follow us on social media to catch more expert insights and expand your developer toolkit!

Read more about it here 

https://www.amazon.co.uk/Functional-Programming-Simon-J-Painter-ebook/dp/B0CHXS6BWB

Text Us About the Show

Speaker 1:

Hello, hello, welcome to Microsoft Community Insights Podcast, where we share insights from community experts to see up to date in Microsoft. I'm Nicholas. I'll be host today. In this episode we will dive into functional programming, but before we get started, I want to remind you to follow us on social media so you never miss an episode, and it helps us to reach more amazing people like yourself. Today we have a special guest called Simon Painter. Could you please introduce yourself?

Speaker 2:

My name is Simon Painter. I am from the UK as you can probably tell from my accent roughly from the middle of the country. I'm from the West Midlands and I've been a NET developer for something like 20 years now. I started working in NET 2, and I've worked in pretty much every version of NET that's ever been, and these days, of course, I'm big into functional programming, amongst other things, and that's what I'm here to talk about today.

Speaker 1:

Yeah, so before we dive into the theme of the program, can you just tell us a bit about yourself, like what you do in your day job?

Speaker 2:

Sure, sure, sure. So I work for a company called Talos360. They're a NET software as a service house. They're based vaguely near the Manchester area although I work remotely, which is great for me because I have children, so it means I can be there to drop them at school, and all that in the morning, it suits me very well. And they make software for use by recruiters.

Speaker 2:

So it's stuff like candidate tracking, like upload a CV, track them through the process, make comments, evaluate, do, give evaluation quizzes out to your candidate and then aggregate together a short list of the best candidates all that sort of a thing. Arrange interviews all the sorts of things you do when you're trying to hire new staff. So that's what we do, Thankfully and rather conveniently for me. They're actually a functional programming house. That is the style that they write all of their code to, which is handy for me.

Speaker 2:

So it meant that, rather than have a lengthy period of learning what functional programming is as I come on board, I didn't need to do any of that because I sort of literally wrote a book on the subject once and it meant that I could just get straight on with a little bit. There was some in-house style to learn, but get. Get straight on with a little bit. There was some in-house style to learn, but get more straight on with the coding when I started. So I think that was a relief to them in some ways, although they have had to put up with all of my terrible, terrible jokes in meetings.

Speaker 1:

That's just the way I roll, okay. So I'm curious about what's functional programming, because I've not heard about it in my time. I know about object-ordinated, different type of programming, but I've not heard about functional programming.

Speaker 2:

Right, no problem. Functional programming is a style of programming. It's not like an add-on or something that you install or use that way. It's a way of programming, but it's very different to OOP, that is, object-oriented programming. Of course, basically the name is poorly chosen. For a start I mean functional programming. Then Does that mean all the rest doesn't work? It's a terrible name. It's a bit like organic food or what's all the rest of the food? Is it inorganic rocks and stuff? No, it's called functional programming because everything's made of functions.

Speaker 2:

Everything in functional programming is made of functions and it's functions which are sort of plugged together like Lego bricks. You know, if you imagine a Lego brick as being a small little function, you could place many Lego bricks together to make a larger, more complex function and then to a larger, more complex system. But the whole thing is composed of many little functions glued together. This is actually something that's been in NET in principle since about C-sharp 3. Link is based on functional programming. If you think about link, when you call a select, what you were doing is those arrow expressions, those arrow functions you write. Those are functions. Those are little, tiny functions which are being passed into another function as a parameter and then executed by that function in a certain context, which is it, takes it and then runs it against every element in an enumerable. That's a basic functional programming concept Functions passed around as if they were variables and functions called by other functions. By doing that, by passing a function into a select statement, you are composing two functions together to make a larger, more complicated behavior.

Speaker 1:

So I'm not in a developer industry, but is it good to have a lot of function in the program? I was thinking like too many functions.

Speaker 2:

I never thought about it that way, I suppose. So it's got a few benefits. I mean, one is reuse. Um, you know, if you, if you are being sort of enforced by the, by the programming style, to to write everything as small, little tiny, composable functions and you're tending to make it easier to reuse stuff, I mean that's one thing?

Speaker 2:

yeah, absolutely, that is definitely a. There's no state as such in functional programming. So OOP is predicated on the idea that you have this big blobby state object, for example, and then your program runs and updates state. It updates this object, it pulls data from it, pushes data to it. We don't have a state object in functional. We kind of have this state as a concept, but it's more like state is a transitory continuity of objects. Um, which one sec, excuse me, sorry, which um? Which exists only for a moment. And um, what you do to update state is, instead of literally updating the object, you you take the old state object some parameters, some little bits of data and an instruction and create a new state object based on the old one, which may sound on the face of it a little overly complicated, but it gives you this advantage of incredibly predictable state management systems. You get code that is and that's the really big one You're writing a code base which is really, really predictable.

Speaker 2:

Everything is written with a principle in mind. We can call it pure functions or something like that. The idea is, every function that you write is written in such a way that it will always return the same data given the same parameter values. That is, the same parameter values. So if you're adding an add function, you give it a 10 and a 20, always giving it back a 30 every single time, and nothing else.

Speaker 2:

It involves eliminating the concept of side effects. Side effects are things like throwing unhandled exceptions or, um, skipping to other bits of the code base any other way, uh, or updating something that isn't contained within the function itself. Once you get rid of all those side effects, all of your code becomes really very predictable, which makes it easy to do things like writing unit tests or to immediately. You don't have to worry about things like side effects happening when you're running, say, a whole load of processes in parallel. You tend not to get things like resource contention happening in cases like where you're doing multiprocessing on data with lots of different tasks running all in parallel. It tends to handle those sorts of scenarios really really well. So Azure Functions, stuff like that that tends to be supported by functional programming.

Speaker 1:

I'm just curious, since it's functional programming, c sharp, can you do that with different programming languages like Python as well?

Speaker 2:

Yeah, you can do it with just about any programming language around. As far as I'm aware I haven't tried it with every single one Functional programming is actually really, really old. It predates NET actually by decades. The very first work that was done in what became functional programming eventually was done in the late 1800s. To some extent it predates the modern concept of the computer. The first functional programming language was made in the late 50s. It was called Lisp, written by a guy called John McCarthy. So functional programming has been around absolutely ages and for almost any given programming language I guarantee you that you write programming language in functional programming.

Speaker 2:

You'll probably find there's already a book on this subject or several Python for example. I'm almost certain that book exists. I think I've seen it around C++, javascript certainly JavaScript supports functional programming very, very well, better than most programming languages do. Just by the sort of fluid nature of JavaScript it can be everything and everything to everyone, except when it isn't because it's JavaScript and occasionally it's an empty array or something. But JavaScript does functional very, very, very well indeed. And Java, of course. Java and C Sharp are remarkably similar to each other.

Speaker 1:

Yeah, I take it, c Sharp is one of your favorite languages, right, because you want it to be another language Like, for example, it could be I won't mention Batch, because Batch is not a programming language. It could be like JavaScript and Python and stuff.

Speaker 2:

JavaScript has a special place in my heart, just in part because it is just so wild and woolly and weird, and I quite like JavaScript. It's the wild west of programming. Everything is possible except when it isn't. But yeah, I mean C Sharp is the language that I have spent the entirety of my professional career working in. When I got my very first job in the early 2000s, I was actually trained as a Java developer. That was when I did my degree at university. Actually, the languages I learned at university were Java and C++ and C of all things. C is still very useful and very important, but most of us don't work in it, and those were languages I studied at university. But as soon as I got my first professional job, they wanted me to work in C Sharp, but I'd never seen it before. But I had done Java and of course they're very transferable.

Speaker 1:

Yeah, I think the fundamental would be the similar Like declaration classes functions.

Speaker 2:

Yeah, there's a little bit of syntax different, a bit of terminology different, but it's a totally transferable skill. So from that point on, in about 2005, 2006, something like that since that day, pretty much, I've just been a NET developer and that's what I've worked in ever since, as well as a bit of JavaScript on the front end. I do know Python as well. As it happens, I run a code club in my kids' school and I teach them Python Python because we use the code club material that's codecluborg and that's largely Python-driven and Python's both open source and a scripting language, so it's handy for teaching the kids.

Speaker 1:

Let's talk about that cook club. Uh, so did you say you teach kids? I've done at your local school. Where about is that? Is that where you're based, or is it open to any other like attendee that want to join?

Speaker 2:

oh, yeah, that is yeah, that is literally my kids' primary school, primary education, for reference. That's the school you attend in the UK between the ages of roughly 5 and 11-ish, depending on when your birthday is. So it's for smaller children and, yeah, it's not one of those schools that's just open to anyone. There's rules here about who's allowed to attend which school, usually based on where you live. So it's actually the school that my children attend and both of my kids are members of the club as well.

Speaker 2:

Um, so it's, it's run well. It's on break at the moment because there's some exams and they are being worked on and we're coming to the end of the school year, but it generally runs on a monday and, uh, it's runs for an hour or so after school. I teach them a bit of Python. I try and give them a bit of context about how does the wider world of computing work. I try and teach them what it is like in the computing industry and what's the truth about the sort of rubbish that films teach you about how computers work, when that's not quite how the real world is, especially hacker films I have a love-hate relationship with hacker films and how accurately and not they portray.

Speaker 2:

I did ask my brother, who is a school teacher, what would be a lovely way to motivate the kids. Like you know, I thought being a school teacher himself, he would know all of this sort of stuff. And it turned out to be stickers, just give them stickers yeah.

Speaker 1:

It could be like making a game. It could be like making a Pac-Man game in Python, something like that to motivate them, Like winning against each other for stickers or something challenging.

Speaker 2:

It is that sort of a thing. There's actually a load of content already made on the Code Club website, so yeah, they do make little games.

Speaker 2:

They do make little animations. There was one of the early ones where you have to make a rocket to make it fly up into space and you have some readouts that tell you how much fuel it's burned and whether your rocket made it to space. That's cool little stuff and, to be honest, one of the most rewarding moments for me is often when one of the kids just starts and they write their first hello world. And would you believe, like I mean, I've been working in some form, either as a student or as a professional, in programming since 1996. And I have long forgotten the joy of the Hello World. It's so rewarding just to see kids excited because they made their computer write something.

Speaker 1:

That's lovely yeah, because that's normally my first program. A Hello World thing to do, even for any industry like microsoft, ai in programming like creating an app I mean, those are completely different spheres.

Speaker 2:

You can write ai in functional or not, but that is no bearing whatsoever. It's not in and of itself ai or not it's. It's just a style of writing code. We're, we're, we're, we're, uh, ai is about application of what your code does. We're lower level than that.

Speaker 1:

Functional is how do you?

Speaker 2:

write that code in the first place.

Speaker 1:

You know that's we're down.

Speaker 2:

We're down in the weeds, in the, in the, in the maximum level of detail, when we, when we write this stuff.

Speaker 1:

Yeah, so if someone wants to get started in functional programming, how can they learn more about it?

Speaker 2:

sure. Well, I could be very churlish and mention I did, in fact, myself write a book on the subject. Um, it's called, uh, functional programming with c-sharp. It's by myself, as simon simon painter. But I should also point out that there is a most excellent book also on the subject by Enrico Buonanno, which is called Functional Programming in C Sharp. Now my book is published by O'Reilly, enrico Buonanno's is published by Manning, and I think we're both pretty good books, but either of those would be a very good place to start. I have numerous talks that I've given on the subject which are available on youtube, if that's of any interest to anyone. I also do workshops, if anyone's company wants to, to bring some of these benefits in. I'm sure that, uh, I'm sure they can reach out to me and we can have a discussion. Yeah, there's plenty of material out there, plenty no worries, uh, so I'll.

Speaker 1:

I'll let the show notes yeah, so thanks for joining this podcast, simon. So we learned about some functional programming, so I hope everyone knows some bit of functional programming. It's quite useful and it's how everything can be built and from in functional and yeah so thanks for joining. So let's, just before we end the podcast, we just want to just want to know a bit more about yourself. So I said what I see you're like an mvp, so are you doing any community activities, like doing any talk or events, like you mentioned?

Speaker 2:

Sure, that's, that's one of the.

Speaker 2:

That's the thing I've started doing recently. But, yes, I do an awful lot of talks. I, I, I, I travel around a lot doing talks for, for user groups, that is for like little localnet meetup. In fact, I'm doing one next week in manchester. Um, I've been doing that for about 10 years I think now, and I also attend international conferences and I give talks.

Speaker 2:

I was at ndc oslo recently and I was at um tecarama in belgium, in antwerp, and I give talks at them as well and as of now, I do workshops as well. So, yeah, I do a lot of public speaking. Um, I started at community conferences in the UK events like DDD East Anglia was my very first one and stuff like that. I've kind of worked my way up to uh, to attending some slightly bigger conferences, but I still attend, uh, all of the community conferences and community events around the UK. At least any of them have me and they're within travel distance of me, because I love speaking at these things. I really enjoy getting out and traveling and meeting people and talking about all of this yeah, there's a difference between like speaking than actual just blogging.

Speaker 1:

Because I like speaking because it improves like soft skills as well and your interaction with people, so it's a plus one for anyone that want to get into public speaking. And before we close the podcast, are you going to any other events? And you said you got user groups talk next week where?

Speaker 2:

is it? Um? So next week I shall be appearing at uh dotnet north in manchester. Um, I tend to be something of a regular at dotnet knots uh, pete gallagher's meetup, so hopefully I'll be there before long. I don't know if you know pete yeah, he's an awesome guy. Um, I, in september I am going to be going to ndc copenhagen where I'll be once again talking on all manner of things. I I don't have much else planned after that, but I have applied for.

Speaker 1:

What's your session in Manchester on NDC? Is it programming or is it just different? It certainly is.

Speaker 2:

Yep, yep, yep. And when I go to Manchester, I shall be talking about how I once made a computer game based on an old 1970s computer game in entirely in functional style, c sharp it's called oregon trail.

Speaker 2:

Uh, I literally found some source code from 1975 on the internet somewhere and converted it myself into modern functional style c sharp, oh, um. I will also be appearing at b sides in um in leeds. Uh, that's actually I'm going to be talking security there. That's one of my other. That's one of my other topics I talk about. That's a security talk.

Speaker 1:

I thought B-Side is a data event.

Speaker 2:

Which one sorry.

Speaker 1:

B-Side. Don't you mention it, because I saw it somewhere online that it's like a date or something. I'm not sure if you did that, though.

Speaker 2:

Well, at least the talk I'm giving is on security.

Speaker 1:

My talk is about what you can learn about security from really terrible.

Speaker 2:

Hollywood films. It's just a bit of fun I have applied for other events and I'm hoping I'll be popping up at stuff early next year. But I've kind of burned through a lot of my leave and my availability for this year?

Speaker 1:

Yeah, not apply it once? Spread it out, yeah, yeah.

Speaker 2:

My fingers are crossed at the moment for NDC London, but we'll see. That's not up to me to to whether I get that or not.

Speaker 1:

Okay, no worries. Yeah, finger crossed, no worries. Thanks for joining this episode, simon. So hope everyone learned more about French and programming and learned about what Simon does in developer. So if you want to speak, see Simon, you can go to the NET North thing in Manchester. Use the group. Please do Next Thursday, or something. It's next Monday, I think Next Monday yeah, so the details will be on like a meetup is net north, so just google it on the meetupcom and you just need to register it. Okay, thank you bye.

People on this episode

Podcasts we love

Check out these other fine podcasts recommended by us, not an algorithm.

The Azure Podcast Artwork

The Azure Podcast

Cynthia Kreng, Kendall Roden, Cale Teeter, Evan Basalik, Russell Young and Sujit D'Mello
The Azure Security Podcast Artwork

The Azure Security Podcast

Michael Howard, Sarah Young, Gladys Rodriguez and Mark Simos