As long time readers of Playful Python know, we have written a lot about functional programming in Python. Functional programming is the current "hot" topic in the programming community and Python has great support for it.
In case you didn't get a chance to read these older articles, you can find all 14 articles in the two series below
So when the news came out today that Code Sandbox has added support for Python, we were pretty excited to give it a try.
What is Code Sandbox?
Code Sandbox is a site where you can write code and run it right from the browser. You do not have to have anything installed locally. If you use VSCode, you can install a code sandbox extension which will allow you to edit the code on your desktop or laptop and sync it with code sandbox.
Because code sandbox is online, it is easy to setup any kind of environment with minimum effort. Maybe your work requires you to have an older version of Python on your system, but you want to try out the new features in the latest Python? Simply setup a code sandbox environment and you can experiment there without touching the environment on your local machine.
Exploring Functional Programming
As we mentioned above, we've written a lot on functional programming on this site. Now, we have gone a step further and added the code from the Robot Kata to code sandbox. Not only can you view the code and run it, but you can also fork the code to your own account and change the code to further explore the concepts.
You can find the code at the link below
This example kata demonstates how to use Python for writing functional style code. In particular you will see the following in action:
Furthermore, it uses some of the newer features of python like structural pattern matching which only released in Python 3.10. You will also see type hinting and iterable unpacking being used. If you are unfamiliar with any of these features, you can get a quick introduction in the twitter thread below
So what are you waiting for? Head over to the code and play around with it 😀
Did you like this article?
If you liked this article, consider subscribing to this site. Subscribing is free.
Why subscribe? Here are three reasons:
- You will get every new article as an email in your inbox, so you never miss an article
- You will be able to comment on all the posts, ask questions, etc
- Once in a while, I will be posting conference talk slides, longer form articles (such as this one), and other content as subscriber-only