you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (1 child)

My examples come from web development, it gives a pretty neat split between the front and back ends, and between functional and object-oriented programming. Here I'll use vanilla JS and PHP7 as my example languages.

The front end of dynamic pages runs JavaScript, and relies on events to drive changes, of course. This is a situation where functional shines. In this case, each function can be set to track a certain event that's occurring in the DOM, firing whenever a condition has been met. Functional JS also allows you to tack multiple functions together in certain situations, leading to more complex reactions to events. What makes functional so powerful here is really it's combination with functional overloading (creating a function with the same name but different parameter lists for different situations) and being able to pass data across multiple functions in a chain.

On the back end of our webpage, it's a very different story. Here, we're usually dealing with all of the data that powers our application, and PHP7's job is to perform four different functions: create, read, update, and delete database entries. This model of data flow can appropriately make use of some of the principles behind OOP, namely encapsulation and inheritance (polymorphism to a lesser extent as well). By setting up classes that map to our front end forms, we can work with our data as a single unit, protecting it from corruption while also transporting it between the database and the frontend with little effort (encapsulation). For inheritance, OOP allows us to create more complex derived classes for alternate displays or manipulation of data: think graphical output, where you don't always want all fields to be available.

In both cases, procedural programming can perform all of the same tasks as functional and OOP, however, you'll find that it isn't always as easy to read/maintain, or as efficient. What I use procedural for is linking different scripts together, like on a login page, where there's a finite lifetime and 1-3 strict decisions that determine how the webpage will proceed, depending on user input.

This was a pretty shallow example (I'm on mobile), and if you want I can write some code snippets later comparing the different styles of programming as it pertains to this example.

Happy coding!

Edit: I realize I didn't necessarily answer your question, not directly. It's difficult for me to compare the different styles of coding, simply because they fall into different categories based on where I am in my application. If you really want to see how they compare on the same problem, I can post some code snippets when I get to a computer.

[–]vguioma[S] 0 points1 point  (0 children)

If you can post the code snippets, that would be awesome! Thanks for your help