I was just relieved to get my code to work when I first started coding. I regarded it as a victory and went on if the program performed as intended. However, I came to understand that getting something to work isn't the same as getting it to work well over time, particularly as I began working on larger projects and handling more data. I started to realize how important it is to optimize code for efficiency at that point.
I recall creating a basic script to look for a match in a user list. It initially functioned well with a few hundred entries. However, it became excruciatingly slow when I attempted to run it on a larger list, which had tens of thousands of entries. I didn't know why it was taking so long, so it was annoying. I began studying time complexity and the scalability of various algorithms at that point.
Rather than looping through the entire list, I went back and rewrote my code using a dictionary. Just that modification made my program run nearly instantly. For me, it was a momentous occasion. I came to see that writing neat, effective code improves user experience and performance and isn't just about being fancy.
I now ask myself a few questions before writing any code: Is this the quickest way to obtain the outcome? Is it possible to minimize the quantity of loops or function calls? Are the data structures I'm using correct? Sometimes the changes are minor, such as using a set for lookups rather than a list, but they can make a big difference.
Naturally, I don't become overly fixated on optimization too soon. I've discovered that it's preferable to get things going first, then profile and make improvements where they matter. However, I've become a much better programmer as a result of writing code with efficiency in mind.
If optimization seems difficult to you at first, don't worry. Learn the fundamentals first, such as how data structures, conditionals, and loops impact performance. As you develop, you'll inevitably begin to identify areas that need work. The same as I did.
I recall creating a basic script to look for a match in a user list. It initially functioned well with a few hundred entries. However, it became excruciatingly slow when I attempted to run it on a larger list, which had tens of thousands of entries. I didn't know why it was taking so long, so it was annoying. I began studying time complexity and the scalability of various algorithms at that point.
Rather than looping through the entire list, I went back and rewrote my code using a dictionary. Just that modification made my program run nearly instantly. For me, it was a momentous occasion. I came to see that writing neat, effective code improves user experience and performance and isn't just about being fancy.
I now ask myself a few questions before writing any code: Is this the quickest way to obtain the outcome? Is it possible to minimize the quantity of loops or function calls? Are the data structures I'm using correct? Sometimes the changes are minor, such as using a set for lookups rather than a list, but they can make a big difference.
Naturally, I don't become overly fixated on optimization too soon. I've discovered that it's preferable to get things going first, then profile and make improvements where they matter. However, I've become a much better programmer as a result of writing code with efficiency in mind.
If optimization seems difficult to you at first, don't worry. Learn the fundamentals first, such as how data structures, conditionals, and loops impact performance. As you develop, you'll inevitably begin to identify areas that need work. The same as I did.