Ditch your Favorite Programming Paradigm

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
programming paradigms are essential to computer science as they outline the way code is styled and written when I was younger I thought the object-oriented programming was the only right way to code and Java was the best language so obviously I wasn't the brightest back then I realized conspiracy myself to one Paradigm wasn't a smart decision and expanding my options could greatly increase my coding quality I'm going to mainly focus on the object-oriented and functional paradigms as oop is arguably the most used Paradigm and functional programming is also growing rapidly in popularity while coding there's multiple ways to solve a problem making the debate of which Paradigm is the best useless the idea behind object-oriented programming is to rely on the concepts of classes and objects where a class can be considered a blueprint to instantiate objects classes usually represent a broad category such as cars animals or any other encompassing field for example if we have a class flu with attributes Supply and type we can now create as many objects of food as we like to add some more functionality the class food can have methods most classes are even more powerful than they look like as they can be extended from to make more subclasses here KitKat can extend from food with KitKat everything's the same except the consume function is overwritten while this specific example is extremely simple an object-oriented design allows for flexible code reuse object-oriented programming can be made more robust with features like abstract classes interfaces virtual functions multiple inheritance and more but that's beyond the scope of this video something you'll probably hear a lot related to object-oriented programming are its four pillars these are inheritance polymorphism encapsulation and abstraction inheritance is what I mentioned earlier about KitKat extending food kitkats are still a type of food so they should be able to take all the properties of food encapsulation allows classes to manage how they hide data allowing access through either the class itself or a function for example if we have a class for a person we wouldn't want their address or SN to be public otherwise any other class would be able to access and potentially change those properties on the flip side something like your name could be public as that data isn't as sensitive the best practice is to declare any variables as private so nothing outside the class can affect it unless it needs to be public abstraction is similar to encapsulation however it's less about data safety but rather for ease of use if we have a string and we want to make it lowercase we can just call the two lowercase function as we don't need to know exactly how the string will be made into lowercase polymorphism is also similar to inheritance except it's about modifying Behavior rather than taking properties in my earlier example polymorphism is used when we override the consume function object-oriented programming is not perfect and it has its issues first of all the code made with object-oriented patterns will generally be longer than other styles there's just more boilerplate code to write and if the project doesn't need all the boilerplate there will be a lot of extra unnecessary code as for functional programming can come in I apologize in advance if I get something wrong with functional programming as I don't have a great deal of experience in it that being said reading and writing well-written functional programs feel great as they can be extremely elegant the main idea with functional programming is that we use functions as our primary building block as opposed to classes and objects the functions are usually pure functions avoiding shared State mutable data and side effects for example if we have a function that adds two variables and changes a global variable to the sum this would not be a functional programming concept as we introduced a side effect the side effect was caused by altering a piece of data beyond our scope which is the function side effects are something developers avoid as they can cause bugs that are completely unexpected we can make the function pure by not altering the global variable another concept of functional programming is that data is immutable because mutable data can also cause side effects instead of having shared State and mutable data we can alter data by using other functions such as map all map does is run a function on every element of an iterable in this case we just append a fire Emoji to the end of each string map is also an example of a higher order function as it's a function that takes another function as a parameter functional programming has many benefits the object oriented programming doesn't have you can get these beautiful or ugly one-liners depending on how you like your code to look it's also far easier to track down bugs as a bug should only be contained within one function and won't have you jumping through 10 different files and nested objects although functional programming seems like a developer's dream with smaller projects it can be considerably harder to scale up in certain cases this is because modeling a problem if functional programming is not as easy as it is in object-oriented programming for example take a car that needs maintenance on a certain date in this case we can just have a car object with an attribute for when it needs maintenance in a functional approach as there is no State we would have to use a function to find out if the car needs maintenance I'm not sure if that's the best way to do it but if there's other method feel free to comment them down below as I would love to know about them as you can see both these paradigms just like every other Paradigm have their benefits but also a wide variety of issues I read something on stack Overflow along the lines of object orientation can improve with functional programming and I agree not everything has to be the same however the functions can improve methods can take the principles behind functional programming functions they don't need to have zero side effects however minimizing them would be extremely helpful for debugging the longer object-oriented code can also be split up into sub methods to do smaller tasks and since object orientation allows abstraction and encapsulation the end user doesn't need to see those changes wherever applicable the one-liners and more concise code patterns from functional programming can be used to create elegant code mixing paradigms and code patterns can increase code quality in so many situations multi-paradigm languages are on the rise and are here to say it's better to embrace the multi-paradigm approach rather than to bottleneck your code by sticking to only one as with any choice there's going to be a prose but there's also going to be cons you might as well take the best from all paradigms and work off of that thanks for watching I'll see you guys next time
Info
Channel: Code Persist
Views: 172,188
Rating: undefined out of 5
Keywords: coding, c++, programming, weird, language, python, auto, STL, standard template library, computer science, software engineering, functional programming, object oriented programming, java
Id: UOkOA6W-vwc
Channel Id: undefined
Length: 6min 7sec (367 seconds)
Published: Tue Mar 28 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.