Skip to content

Commit

Permalink
typos and misc cleanup on OOP lessons
Browse files Browse the repository at this point in the history
  • Loading branch information
zstumgoren committed Apr 7, 2024
1 parent 718fa48 commit 9cbca85
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions content/classes_and_oop/elections_oop_code_challenge.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "b4557040-ff63-448b-a083-474de0e17748",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -198,7 +198,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "3f6ffb95-747e-49b2-b05a-e3a5dd7c2893",
"metadata": {},
"outputs": [],
Expand Down
6 changes: 3 additions & 3 deletions content/classes_and_oop/hidden_life_of_objects.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"metadata": {},
"outputs": [],
"source": [
"my_bird.change_name()"
"my_bird.change_name(\"Debbie\")"
]
},
{
Expand Down Expand Up @@ -266,7 +266,7 @@
"\n",
"It would make more sense to name each bird when you create its instance.\n",
"\n",
"And sure enough, Python classes provide a mechanism to supply data to a class instance at the time of creation.\n",
"Sure enough, Python classes provide a mechanism to supply data to a class instance at the time of creation.\n",
"\n",
"It requires using a gnarly bit of syntax known as the [`__init__` method](https://docs.python.org/3/tutorial/classes.html#class-and-instance-variables).\n",
"\n",
Expand Down Expand Up @@ -314,7 +314,7 @@
"id": "ff3cee36-b717-4b5a-84e2-9e144a01d75d",
"metadata": {},
"source": [
"The `__init__` method and `self` are among the most confusing aspects of classes and OOP in general. These concepts will become much more clear as you practice building and using your own classes. Check out the *Coding Challenge* below to get some reps.\n",
"The `__init__` method and `self` are among the most confusing aspects of classes and OOP in general. These concepts will become much more clear as you practice building and using your own classes. Check out the [Elections OOP Coding Challenge](elections_oop_code_challenge.ipynb) to get some reps.\n",
"\n",
"## Always be Returning\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion content/classes_and_oop/method_chaining.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
"outputs": [],
"source": [
"new_df = renamed.reset_index()\n",
"type(df) # Now back to a DataFrame"
"type(new_df) # Now back to a DataFrame"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion content/classes_and_oop/module_dot_something.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"\n",
"### Built-in modules\n",
"\n",
"The Python language ships with oodles of [built-in libraries](https://docs.python.org/3/library/index.html) to handle a myriad of useful tasks. These are modules you can immediately import in your code, without having to install libraries sing `pip` or `pipenv`.\n",
"The Python language ships with oodles of [built-in libraries](https://docs.python.org/3/library/index.html) to handle a myriad of useful tasks. These are modules you can immediately import in your code, without having to install libraries using `pip` or `pipenv`.\n",
"\n",
"Pythonistas like to say the language comes with \"batteries included\".\n",
"\n",
Expand Down
20 changes: 14 additions & 6 deletions content/classes_and_oop/why_bother.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,34 @@
"tags": []
},
"source": [
"# Why bother with classes and OO at all?\n",
"# Why bother with classes and OOP at all?\n",
"\n",
"It's a fair question to ask why we need all the complexity that comes with classes and, more broadly, object-oriented programming. Can't we all just stop chaining methods and confusing people?\n",
"It's a fair question to ask why we need all the complexity that comes with classes and, more broadly, Object-Oriented Programming (OOP). Can't we all just stop chaining methods and confusing people?\n",
"\n",
"After all, it's perfectly possible to write valid and useful Python code without ever creating a class, much less chaining methods. But you'll notice that many libraries use classes, and a primary reason for their existence and widespread use is complexity. Specifically, once you gain some comfort with classes and OO, **you can use them to dramatically reduce the complexity of large code bases**.\n",
"After all, it's perfectly possible to write valid and useful Python code without ever creating a class, much less chaining methods. But you'll notice that many libraries use classes, and a primary reason for their existence and widespread use is complexity. Specifically, once you gain some comfort with classes and OOP, **you can use them to dramatically reduce the complexity of large code bases**.\n",
"\n",
"As programs grow in size from a few lines in one script or Notebook to hundreds or thousands of lines scattered across many modules, it can become extremely difficult to maintain and debug code. \n",
"As programs grow in size from a few lines in one script or Notebook to hundreds or thousands of lines scattered across many modules or notebooks, it can become extremely difficult to maintain and debug code. \n",
"\n",
"Classes provide a mechanism to model aspects of our code in sensible ways, so we can group together related bits of data and functionality (aka *methods*) and use them in larger programs.\n",
"\n",
"For example, if you're building a system to gather and publish election night results, you might want to create classes for `Race` and `Candidate`. In such a system, you could store the votes each candidate received from a given precinct on separate instances of the `Candidate` class (one per candidate). Meanwhile, the `Race` class might have a `determine_winner` method that tallies the vote counts of each candidate and figures out the winner -- or if the race was a tie.\n",
"For example, if you're building a system to gather and publish [election night results](elections_oop_code_challenge.ipynb), you might want to create classes for `Race` and `Candidate`. In such a system, you could store the votes each candidate received from a given precinct on separate instances of the `Candidate` class (one per candidate). Meanwhile, the `Race` class might have a `determine_winner` method that tallies the vote counts of each candidate and figures out the winner -- or if the race was a tie.\n",
"\n",
"Classes can be quite useful in such a system since they let you model real world entities and more easily associate useful data and functionality with each entity. Such an approach can dramatically improve your ability to make sense of complex systems. And of course, you can use this approach for more abstract domains such as reading and writing [CSV files](https://docs.python.org/3/library/csv.html), interacting with an [operating system](https://docs.python.org/3/library/os.html), [analyzing data](https://pandas.pydata.org/), and so on. \n",
"\n",
"There are many more features of classes and OO in general -- we've barely scratched the surface here -- that make them useful and flexible tools for writing code, and we encourage you to learn more about them on your Python coding journey.\n",
"There are many more features of classes and OOP in general -- we've barely scratched the surface here -- that make them useful and flexible tools for writing code, and we encourage you to learn more about them on your Python coding journey.\n",
"\n",
"All that said, you may find classes to be overkill in your own daily work. But keep them in mind as a handy tool for managing complexity, especially as the number of lines of code increase.\n",
"\n",
"And if nothing else, a basic understanding of classes and how they work will help you understand *how* to use dot-notation to access data and functionality in classes and modules."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "106713f5-307c-4c9f-9b6e-a294032d373d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit 9cbca85

Please sign in to comment.