 Yeah, here you go. Okay. Okay. I see myself now great Thank you and welcome everyone to the first talk of PyCon. I'm so excited. I hope This will be a very interesting Talk for you Especially since we are doing this online It's it's new for me as well. So please excuse me if I'm not not being able to give you that feeling of being there But we are pretty close to right. I mean if you have any questions, please put it on the chat I'll be happy to talk about it in the end So on to the talk the talk today I would like to talk about is how I built a ray tracer in pure python. Thanks to the great background from a beyond that But just a little more about the background in case you don't know what I'm talking about This talk is about how I created a ray tracer called pure a pure is just a abbreviation of pure ray tracer and that pure part I would be explaining in a bit But basically what pure refers to here is I'm just using the python standard library I won't be using any external third-party libraries Which includes numpy or any of the graphical Libraries or even an image writing library like libpng or for jpeg writing it's all in python and The outcome of this was not just this particular library. I also presented or published six parts of how to make this ray tracer library on YouTube This was like a tutorial series aimed at intermediate level Python programmers and It took me a pretty long time to do it It took about 12 months for me to complete it But at the end of the day the response was phenomenal like I did not expect it to have more than about a thousand views But it's now clocking more than 17,000 views and a lot of people are sending a lot of positive things about it If you want to see this tutorial Please scan the QR code which you see right now on the screen or just type on your open your browser Just type bit.ly bit.ly.ly slash pure P U R A Y and You will be taken to the YouTube playlist where you can start seeing this video or Start from part one and go all the way to six parts by the end of six parts You should be able to create an image like this This is a fully retraced image in 1080p Some of the things that you can see here are that there are Rendering of spheres. There is a rendering of a checkerboard pattern And if you look very closely, you can see that there are reflections within reflections So there's the reflection of the red ball within the purple ball and inside that reflection You might actually see the purple ball. So this is like multiple depth recursive Structures which we have used here Just to see the kind of positive response over here I have just put together some comments that have got Both from new people who are new to Python programming as well as people who have been using Python for decades And just wanted to do something fun And interesting and they just tried this tutorial and they found this to be a great weekend project If you are a beginner, it might be like a mini project as I call it For for instance, it might take a couple of weeks for you to complete it if you're trying to do it in a very leisurely manner, but you might not only have something that is Informative that's knowledgeable as well as you might have some fun in doing it So that's why I just wanted to show you how people found this In the next couple of minutes the whole talk is structured into this format I'll be talking about what motivated me to do this I'll also talk about some of the challenges. I faced when I was trying to do this and I will share some Tips or some of the tools that I used for making video tutorials in case You are interested in making a video series or something similar to what I did Making a video is a lot more involved than other mediums and I think there's very little information out there to help people guide you in this Process and finally I'll tell you about what my learnings were what the post-mortem of the project is now that it is over and What I would do better in in my next future projects A Quick introduction about me. I beat it a pretty good job there as well I'm the author of the book Django design patterns and best practices Currently now in its second edition. I've been a speaker for multiple conferences including PyCon from the very early days Back when we it used to be conducted in the meat space as we used to call it Than a virtual event I'm an engineer by By education as well as a products person in my day job I'm a senior product manager at a company called unisys where I deal with multiple server technology products I'm also a dad for two beautiful children and I'm based in Bangalore. Now, I would like to tell you how it all started right as Simple as it may be or as It happens in many of the cases it all starts with a tweet I had a weekend free in which I was tinkering with some graphical code and I thought it might be a cool project to do and I tried creating a ray tracer by reading some theory materials and Made my render in about 10 minutes At that time I was using numpy and as you can see The render is just a very simple white sphere on a checkerboard and Just for a bit of ego massaging. I just write written my name also using spheres In on the floor and I thought it'll be cool to share it with others. So I just shared it on Twitter and I just Waited for what kind of responses came out One person who actually asked me this looks really cool. Can you post a tutorial on how you did this? So I jokingly replied to him saying that aren't there enough ray tracing tutorials published every year or every month That why should I add to that and I left it at that? I mean, I didn't think too much into it Then many years later, I should say this was 2015 I think about 2018 2019 my daughter is about 11 years old now She was about nine then she was interested in learning Python. She wanted me to you know teach her Python Because I was so enthusiastic about Python. So The funny thing there is You might think that Python is a great beginner language It is actually but it's still very difficult for a beginner to understand, right? A beginner might find it extremely Challenging with some of the simple concepts which happen or conversions which might happen for example when you divide two numbers you might get sometimes the wrong answer like Instead of nine divided by three returning three there might be like a floating point number like 2.9999 And if you really you can simply explain it by saying that you know Python Is using floating point numbers and inside and floating point numbers have these kind of problems or you can go really into the depth of this You know saying that you know, there are there are these kind of errors which can be corrected and all that So that is all very daunting and I would call a leaky abstraction that even if you are a beginner Or even if you are an experienced person you might face When you are using Python and then there is a big problem a beginner phases that is When you are faced with a problem, how do you really break it down? How do you really start from something like build a web application or big build an application? And that starting problem is enormous. How do you design that problem that is very difficult if you're a beginner and if especially if you're coming from a non programming background as many people who use Python are You might be a scientist or a teacher. You might find it very difficult to use when you're using Python Or any programming language for that matter. The other thing I noticed when I was teaching my daughter was there are two different kinds of Python learning materials. The elementary level, which is basics of Python programming language, which might tell you this is a print statement does an if statement. This is how you Write loops and things like that and the advanced level, right, which goes into really specific topics like how to do asynchronous programming in Python, how to do web development in Python, how to write type annotations in Python three things like that. Now I would say that You know, the, the big gap in between is not really addressed here. So somebody who is using the elementary level Material might see that this is really not very intuitive for somebody who is, you know, learning the programming language. I would say learning programming to be exact. So if you're already familiar with a programming language like see or some other language, you might find it intuitive to understand. Okay, a conditional statement is used using if instead of using curly brackets, you have to use indentation. But what beyond that, like, how do you really do problem solving that I'm sorry, that is the part where I feel a lot of tutorials, a lot of learning materials are lacking. How do you take a very difficult problem and break it down. Now, I would say majority of the people are in this category, because if you're a beginner, you might read the basics of Python in a couple of days and you're cross that beginner stage. Whereas to become an advanced Python programmer, you have to spend so many years or you have to do so much of coding. So most of the people are actually in between and the learning material is actually not catered to that. And even if it is catered to the intermediate level people, there are some problems with that, which is what I'm going to talk about next. So what are the problems which I see with most learning content which involves which are for intermediate level. Now, remember an intermediate level content should be about taking something like a project from end to start, sorry, from start to end. So it should be like building an application or a web application or a game or anything. It should lead you step by step from from very beginning to the very end. And it is kind of like a project based approach, which I would say is ideal here. Now, to understand what is the problem with most of these materials, I would like to take you to a very well known model in human psychology called fog behavior model. I came to know of this because of my product management background and I'm interested in how users think about a product. So it is not just for under the actual model is for understanding how human behavior can be changed. For example, you want to learn a new you want to develop a new habit like I want to work out or do exercise every day and I'm not doing it. So how do I change my behavior. But this is also interesting. If you want to build new products, you want to design something that is human centric the fog behavior model really helps. If you look at this model, you'll see that on the x axis, you have ability that something that is hard to do do something that is easy to do. And on the y axis, you have motivation, something that is low, not very motivating and something that is highly motivating. Let's look at a Python learning content. Most of the time, the ability is not an issue. Python is very readable to one. And if you just read, even if you have no programming language, you understand that, okay, if statement should be some condition, a while statement should be something like that. And there's not many punctuations or special characters. So you might be able to read it. So on the ability side, it might be easy to do so you're on the right side. But on the motivation side, is it really motivating? I mean, is it something that you would like to do and you would like to do for a very long time without any sort of Other external and extrinsic motivator. I feel that this is where most of the content falls below the line. So you can see that there's a curve which is called the action line. And if you're below that, you really fail as can see triggers fail here. And if you are about that, the triggers really succeed. So a successful or a very effective learning content should be about the line. It should be motivating as well as it should have the ability or the person should have the ability to do it. Now, how do I put it in very simple terms. I would put it in just two questions like is it easy or is it cool. Now, is it easy means that does not mean that it should be too simple or too trivial. It should be in the light right level of difficulty that you feel challenging that you want to do it. As well as it's not so difficult that most people leave it midway. So some tutorials, they start very easy, but in midway, it becomes too difficult that you know some people drop out. That is very important to take care of. And the second thing is, is it cool. I mean, once I do complete this tutorial. Can I show it to somebody or can I share it with my friends. Everybody knows that traveling salesman problem is a great problem to do in computer science. But once you completed that successfully. You show that completed solved graph. Your friends are not going to be impressed right and they'll be like what is this. But if you actually have something that is visual like you have built a game in Python or you have built some Cool graphic demo in Python or you have done a rate racer output. People, even if they are not programmers, they'll look at it and say, wow, this looks really nice. How did you do it. And they get interested, right. So that motivator is actually going to motivate you till the end of the project like, okay, I have to do this. This is the outcome that I'm trying to create. And that is actually going to drive you. Now, by no means, this is the only rate racer implemented in Python. So if I do a quick research, I can see that there are a lot of rate racers which have been written in Python and You can see that you have a n number of things on open source GitHub repositories as well. But what I have tried to do here using puree is to do everything in pure Python. Now, the question is why I'm stressing too much on pure Python in in this case it is because I'm looking at that from the audience perspective from somebody who's learning Python perspective like it has to be Something that does not involve that does not task the person to learn and another library like NumPy. Already you have the cognitive load of learning a language, a programming language. Why do you want to add in another cognitive load of learning a third party library like NumPy. Now, this might be non trivial for many people. That's why I very deliberately try to keep away from any other third party library, even if it means you just have to learn the API. Second thing is very easy to find out what the source of information is. If you're only using the Python standard library, the Python documentation is all that you have to reference. You can download an offline copy of it as a PDF or nowadays you get it as an EPUB disconnect yourself from the Internet and start doing it peacefully. Now, I find doing disconnecting myself from the Internet to be very important because it's quite distracting. There is a lot of there are a lot of things social networks and all sorts of distractions online and if I disconnect myself. I can actually do a much I can be much more productive. So if I say that I'm going to use only Python, just open the Python documentation, which is installed by default in many cases, and you just have to go through that. Of course, when you hit a problem, you might have to check you might have that temptation to check on stack overflow for that problem for that solution. But I would say resist that temptation for some time, try to find out what the solution what the problem is actually caused by and try to do some troubleshooting yourself. This is important because if you don't learn that crucial skill of troubleshooting and debugging, you're not really going to become a very effective programmer. So this this approach or strategy strategy of just using Python is very deliberately for you to do that. And another thing is that it becomes more readable. You understand what is more pythonic here. In my personal opinion, NumPy is not very pythonic. NumPy is actually influenced by array based programming languages like APL or J, and a lot of those ideas have come directly imported into NumPy. Same problem with Pygame. Pygame is an SDL is based on SDL, which is based on C, and a lot of C conventions come into play. Whereas if you use pure Python, you can understand what is pythonic and translate those concepts into other areas. And finally, there is this problem of security. A lot of people might be hearing about what is called as typo squatting, where you try to install something and you make a typo and you have installed something that an attacker has put in like a malware. So that's something to think about. Now, when I used Python, what were the challenges I felt? The first challenge was the problem of plenty. A lot of programming languages offer multiple ways to do the same thing. And this often leads to analysis by paralysis, right? This was the problem with the programming language, Perl. It offered multiple language constructs for doing this one thing. It was called there is more than way to do it. And I feel there is a creeping feature, feature creep happening within Python as well. And now I'll give you the example in a raytracer context. I want to create a vector, which is to represent a three dimensional point, which has just three components x, y, and z. I can use a number of data structures here. I could use a dictionary, a class, or if I want to make it even more optimized, I could use slots, which are faster than classes. Now, which one did I end up using? And how did I go about this process? I actually show it in the tutorial, but I actually tried all the different implementations. In fact, puree is currently in its sixth or seventh rewrite. And I've rewritten the entire raytracer multiple times and compared their performances to see which is best. But I always went for readability rather than performance. And that's why I ended up with classes. The second problem was I needed to use object oriented programming. Now, I'm not a big fan of classes. I wanted to do the raytracer in function functional style. And there are a number of problems with Python. If you want to use pure functional style, one of the problems which is solved in other functional languages like Haskell is laziness, right? I mean, if you are copying very large data structures, which happens a lot in image processing that you're dealing with megabytes or sometimes even gigabytes of data within memory, it all gets copied. And there are ways to avoid that in Python, but you have to jump a lot of hoops and instead of fighting against the language, I thought, why not use object oriented programming and embrace it, right? The other problem was automatic integer to floating point conversions and other sort of conversions, right? There is something happening within integer space as well called big num conversions. All these conversions just add to the memory and makes reasoning the problem very difficult and I had to be very careful to cast it to an integer where an integer is expected instead of automatically converting it into float and things like that. So all these challenges are actually because Python is trying to be more friendly, but sometimes it gets in your way. And of course, I have to talk about the elephant in the room, though it's a very tiny elephant in that bullet. It's that the programming language Python is actually slow when it comes to CPU intensive tasks. And this is the biggest criticism that you would face when you're telling somebody that, hey, I'm going to write a racer in Python. People are like, wow, you're going to use a language like Python for this. But as you would see, as I found out, it's not really a problem if you have, if you broaden your mind to other implementations like PyPy and things like that. So it's ultimately a matter of optimization. And now my racer actually runs in less than 10 seconds or five seconds to render a 1080p image, which is pretty acceptable according to me. And I would say that that is good enough if you're trying to create your own racer for the first time. A very little time to talk about art of video presentations. My process is kind of something like this. I do the coding first. I do the scripting after that. And scripting is pretty important because I need to be very clear in writing as to what I need to do before I actually start recording. And that helps me a lot in saving time. Some people just write the outline. That is also fine. But I try to make it more elaborate, especially in the intro and the outro. Whereas in the middle part where I'm doing a screencast, I kind of, you know, leave it to the outline. Then the screen recording part comes, as I said, the face recording is mainly for the beginning and the end part of the video where I'm talking to the camera. And then the editing part, which is usually the most time consuming part. And the post production, which is now becoming more and more time consuming. And the marketing part, which is basically tweeting on social media and things like that. How do you know these skills? Preparing a video requires a knowledge of a number of skills. And it's not very easy. It took me a very long time to pick it up. But I found, you know, Skillshare and YouTube to be very good resources for these things. How do you structure and script it? Now, my principle is keep them engaged almost all the time. And the way I engage them is by having a very interesting structure. I start by talking about the problem and I give them clues and I stop it at that. I allow, I give a pause deliberately in the middle so that you can solve the problem yourself. And this has been very effective. Many people like this approach. And finally I show them how I solve it in my own way. And in the end, I sometimes add a bonus content. Now, what I want to talk about visual storytelling is if you're trying to use video as the medium, make sure that you make good complete advantage of it. For example, some people think that you just have to narrate something on looking at the screen. Or, you know, just have to talk something like a live stream. All these are good approaches for certain things. But if you want to make them engage like I talked about in the fog model, you have to make full use of the medium. You know, make use of the sound, the sound effects, the music, the videos, the animation. If you can animate a concept, try to animate that. If you can try to explain it using, you know, actual props in the video, try to use the props. Make use of the medium. And of course, find novelty. One thing I have to remember, people who read a blog post have... Thanks, Abhi. People who read have much more attention span than people who watch videos. So try to keep it interesting, try to mix things up a bit. Don't keep it too static and boring. Some of the tools and technologies I've used are, as you know, you cannot simply do a screencast as I used to do in my early days. I would say you can start simple. You don't have to use everything that I talk about. But just to give you an idea, these are the hardware and software I use. When you look at the hardware, you'll find that I use an SLR camera, which gives tremendous video output. And if you can afford it, please use it. Otherwise, even a normal mobile camera or a webcam would do. Invest in a good mic. This is one of the most important things. Your audio quality is going to determine how well people would listen to your content. I actually use two mics, a USB Yeti mic and a Boya Lavalia mic. And lighting is equally important. If your lighting is bad, your image quality suffers. Sometimes you spend a lot of money on lighting. I don't think you need to spend a lot with LED and other forms of lighting, but please make sure that it's well lit. Software I use is almost all open source. OBS Studio is excellent for recording. KDN Live is very user friendly for video editing. Inkscape, GIMP, Blender for image editing. IP Cam is an Android app which can help you use your Android phone as a webcam. And this is how I reach the audience using red, posting it on Reddit, Hacker News, Twitter, etc. This is what I feel what went right and what did not go so well in the project. I felt that showing my mistakes instead of editing them out was a very good decision because a lot of people struggle when they face an error message or find something which went wrong. And I also showed that I also made mistakes and that helped a lot of people to find out, okay, this is how you go about the process of debugging, which I feel is a very important part of programming. Find a niche. So ray tracing was a niche when it started, but fortunately for me, NVIDIA came out with their ray tracing graphics cards and it became like a big buzzword, like what is ray tracing and then Minecraft was created using ray tracing and things like that. So instead of trying to go behind the trends like machine learning or some other hot topic right now, try to find a niche that is more interesting for you and go for it. Yeah, I spend a lot of time between each episodes, even though I had a day job, I feel I could have made it much more faster. And a lot of people did not really use the bonus content, so I felt it was not very useful. Now, what is the one takeaway that I would like to tell you is try to make your own content, try to explain something if you're trying to learn a concept. And I feel that that is the best way to learn something as well for you as well as for the other person who's listening. It might be a better way for them to understand a topic because even if there are a lot of tutorials or content out there, your content might be something that they could relate to, they could understand better. So that is one takeaway. If from the entire presentation I could let you go with, like if you can explain something, please make time to explain that, publish a video, publish a blog post or write a book. I mean, however you want to do it. So that was my talk. Any questions? Thank you so much, Arun. I mean, I expected this and they are known for good sessions, so there are no surprises there. We do have some questions. The first question, one of the questions is, any thoughts on using might be threading to make the ray tracer faster and optimized or using the GPU, which if you already mentioned that. I do cover that in my technique. In fact, instead of multi-threading, I use multi-processing and I give a very good reason for that in the last part of the ray tracer. GPU is something that I have not really tried. In case there is a future part to it, I might try doing that. But yeah, multi-threading is something that I definitely cover in the last part. Okay. And there was one question about the internals of Python. Where can we get the sources for that? So one thing is the documentation we have mentioned, but is there something that you would recommend? See, internals of Python is something that is great if you want to understand why certain things work in a certain way. When I was like two or three years old using Python, I just opened the source code of Python and tried to learn from that. And I feel that is still possible, that is still good. It's one of the well-documented projects written in C. And because I was also interested in how languages work, that really helped. So I would recommend doing that. And there are a lot of good books also about internals of Python these days. There is also a very good book called Elegant Python, which I suggest in case you are learning more about how the language itself works. Elegant Python noted. Yeah. So all of these, whatever you've mentioned and whatever we've spoken about in the chat, et cetera, will be made more tough and we'll be putting it upon Zulip as well. Abhijith is playing simple, no nonsense talk. Again, no surprises there, but thank you Abhijith. And to people who have missed it or have joined late, this will be made available later on YouTube. And Arun, am I right in assuming that you'll be available on Zulip for a while to answer any questions on the Chennai stage? Yeah, definitely, I'll be there. Okay, thank you. I think we are on schedule now for the next talk, but a quick word from our sponsors and then we'll be moving on to Sonam. First, we'll do a sound check from Sonam. Arun, I'm going to bring you down from the stage, but thank you once more. And we will be providing everything, all the resources that Arun has shared and the connect with me details on the Zulip chat and on the Hopin chat as well. Vikas, can you please note that down over on the Hopin chat? Yeah, and today Vikas is helping me out with the Python India Chennai stage. So thank you Vikas. Yeah, I think thanks to the audience as well. Next, Arun, I'm going to bring you down. Okay, thank you.