From the course: Programming Foundations: Beyond the Fundamentals
Comparing types of external code - Python Tutorial
From the course: Programming Foundations: Beyond the Fundamentals
Comparing types of external code
- When you're first learning to program, solving basic problems can be really useful in honing your skills. But as developers move on to more complex programs, it can become tedious to have to rewrite code to solve the same problem over and over. Fortunately, it's pretty easy to avoid these repetitive tasks. Across programming languages, developers often create code to accomplish basic tasks and then share it with the developer community for free. Instead of reinventing the wheel, you can simply find existing shared code that does what you need and then incorporate it into your program. This lets you focus on building up the custom parts of your programs. There are several different types of shared code and the terms for these can vary from language to language. We'll take a look at types of shared code in Python as a starting point. The most basic type of shared code in Python is called a module. A Python module is a Python file that contains code, like variables or functions. I can make a module available in my own program through a process called importing, which involves referencing the file name in my own code. Then I can use the functions and other parts of the module anywhere I need them. Using the library is similar to buying a cake mix. The basic ingredients are measured and combined for you, saving you some time, but you still get to pick the shape of the pan, the type of frosting and any filling or decoration you want to use. Sometimes it makes sense to use multiple modules together so they're distributed and used in a group. In Python, this is called a package or a library. It's like buying a cake mix that also comes with a tube of frosting and some candles. Everything you need to get a birthday cake ready. Code can also be distributed in even larger groupings. When a set of code is not just used together, but used in a specific way, it's distributed as a framework. When you use a framework, you let the external code set the basic structure and flow of your program, and you customize it for your use case. It's like buying a birthday cake from a bakery. You may be able to select among a few flavors and you can specify the basic decoration style, but the bakery will probably have a standard size and shape for all cakes and then you can do any final customization you might like. Now, I enjoy baking, so I like to make a cake from scratch from time to time, and likewise, it can feel really good to write an entire app from the ground up instead of using external code. But when you're not excited about writing basic code, or you have a tight deadline and need to save some time, modules, packages, libraries and frameworks can help you move on to the custom code you're excited about writing.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.