DEV Community

Cover image for Getting started in Software development: A Path to a rewarding career (Part 3E, Functional Programming and OOP)
Abdurraheem Abdul-majeed
Abdurraheem Abdul-majeed

Posted on • Updated on

Getting started in Software development: A Path to a rewarding career (Part 3E, Functional Programming and OOP)

Hello and welcome

Thanks for stopping by.

Table of Content

Full table of content for the entire series is here

Today, we will continue the following

  • Getting started (cont'd)
    • Learn Programming concepts (cont'd)

Programming Concepts

Today we will round up the section on programming concepts with brief descriptions of Functional Programming and Object-Oriented Programming (OOP).

Fair warning, these concepts are a bit involved so just go through them for the sake of getting introduced to them. Do not be under pressure to understand them completely for now. We are only addressing them here because it is good to have this basic exposure now before we go in deeper in future sessions

Lets goooo!!!

Yeeeeeaaaah

Functional Programming

Functional programming (or FP) is a software development paradigm where functions (Pure functions to be specific) are the building blocks of the computations to be done in the application.

Another aspect to it is that it seeks to avoid concepts of shared state and mutable data. Now lets zoom in to some of the key aspects of FP. Yes, the ones in bold.

Pure functions

They are the basis of functional programming. They are functions like the ones we have addressed in the previous session (used for bundling behaviour to be reused) but with some specific behaviours:

  • They take input parameters and return an output without modifying any external state or data. So, if your function affects anything outside its scope, it produces a side effect and that makes it impure.

Being an impure function is not a crime but it no longer fits the FP paradigm and you have to watch for the pitfalls that make pure functions desirable. It will only be wrong to have those if FP is what you are aiming for.

  • Same inputs to pure functions return same outputs all the time. Like a function to add 2 numbers; no matter how many times you try the function with the same parameters, you can be sure the output will be the same.
function add(a,b) {
   return a+b
}
Enter fullscreen mode Exit fullscreen mode

This add function is pure. It does not impact/modify anything else and it will always return the same output given the same inputs.

This behaviour of pure functions makes them easy to work with because they are predictable and easily testable.

Shared state and Data Immutability

In functional programming, once data is created, it is not changed. Instead, new versions or copies are created when required. This reduces the issues that can arise from mutating (changing) data that can lead to side effect which can be hard to track, test and manage in programming.

FP is not as common as it used to be because it was replaced/overtaken by OOP but there are still a few cases where it holds a lot of value and knowing and applying it as much as is convenient in your programming career might come in handy.

Object Oriented Programming

This is a paradigm that organizes your application code into structures called objects.

The way it works is that everything in your code is an object. Whether you are building a social media app, a ride hailing app or a to-do list app, everything is an object. The database connection is an object, the user is an object, authentication is an object etc. Literally everything in the world can be modeled in your application as an object.

Objects are built from Classes and a Class is simply a template or blueprint that defines the properties (attributes/features) and behaviors (methods/abilities) that objects of that class will have.

oop human

In the image above, you create a class called Human and from that Human class you can build any number of β€˜Human’ objects in your application as needed using that blueprint or template.

Inside the Human class like every other class, you will specify 2 sets of things

  1. Attributes like gender, name, email address, account number and any other attributes that are relevant to your application use case for the Human’s objects.

  2. Methods or function or actions that represent what the Humans in your application can do

Do not make the mistake I made earlier while learning by specifying everything you can think of for a human, only the attributes relevant to the app. If the application does not use the date of birth of the human then it is not relevant. Seems like a given but is worth mentioning.

There are the 4 main concepts in OOP namely Inheritance, Polymorphism, Abstraction and Encapsulation. Do not worry too much what they mean for now, we will go in deeper when we get to the OOP section in our journey

In my opinion, OOP is a super power once you grasp it but it takes some time and effort to truly get it right.

This is it for today and for this section on basic programming concepts.

In the next one, we will get into the real meat of the matter and start writing code.

Until then stay frosty and remember, we are here to help

Iron legion

Previous post is here

Next post is here

Top comments (0)