![]() ![]() ![]() It's not a big deal when two lines are the same and exist right next to each other. In the second example, we only need to make the change in one place. In the first example, we would need to update two lines of code. In our example, let's pretend the soldier dictionary changed, and now the key that stores the "damage" value is called dmg. When code is duplicated, it leads to many potential problems. We don't want too much of our code doing the exact same thing. Soldier_two_dps = get_soldier_dps(soldier_two) Soldier_one_dps = get_soldier_dps(soldier_one) We can use a function to refactor the code a bit: def get_soldier_dps(soldier): Soldier_two_dps = soldier_two * soldier_two Let's pretend we have some code that looks like this: soldier_one_dps = soldier_one * soldier_one The best way to stay sane as a software engineerĪ couple of examples of "clean code" practices include writing good comments, using DRY code, and naming variables well, just to name a few.A way to make new feature development faster.A way to make finding and fixing bugs easier.Something that helps humans model and simulate the real world.Designed to make code easier to work with in many situations.Necessary to create certain kinds of programs.A way to make your program use less memory.Good programmers write code that humans can understand. Any fool can write code that a computer can understand. We call code that is easy to work with "clean code". Object oriented programming and other paradigms like functional programming are all about making code easier to work with and understand. The Goal of Object Oriented Programming.But if you would like to go more in-depth with live coding exercises and quizzes, you can find those here on v. I've included all the learning material you'll need here in this article. All the coding examples will be in Python, but the concepts apply generally to all coding languages. Stick with me through this article and you'll have a full understanding of the core tenets of OOP by the end. The main benefit of writing your code in an object-oriented way is to structure your program into simple, reusable pieces of code. Object Oriented programming, or "OOP" for short, is a way of writing code that relies on the concepts of classes and objects. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |