Choosing a career in programming is one of the most lucrative deals one can pursue in this age of technology. This is pretty evident by the number of students there are enrolling on various programming courses, degrees or choosing other ways of learning programming online. There is a huge community, demand and every bit of luxury this career can provide you with is only to be experienced through either subjective experience or watching others.
Confusing terms and approaches of programming
It is easy to get into programming but takes a great deal of effort, dedication and commitment to keep yourself to the top of your game. Getting the fundamentals is the best move you can make if you are just beginning. For those, who have already got their fundamentals right and somewhat floating in between with the floating points, this article will be of a great use especially if you are looking for the exact explanation of imperative and declarative programming.
You might have come across these two terms often used by the mentors or seniors interchangeably. This may leave you in confusion, but here is this reading might save you some great deal on the way.
So, what is declarative and imperative programming? Let’s dive in. These two are basically the way you would a write your code blocks based on the language and your projects need. Declarative programming is something, where you have to pedantically write every details to instruct the computer for your desired purpose. Mind boggled? Okay, let me break it down a further.
Declarative programming is the approach making your code look like step-by-step instructions. Let’s say, we want have a string variable called ‘text’ where we store some sort of string input, maybe from a user. Now, we are to make a copy of the string and store it in another variable, called ‘copy’ and assign the ‘text’ variable to it.
Now, to see the surprise, if we make the first letter of the ‘copy’ to uppercase and print out both ‘text’ and ‘copy’, we will see that one of them has changed while the other remained unchanged. In this case, the first letter of the ‘copy’ has been changed but the ‘text’ has not been changed. This is so, because, such languages as C in nature, require a declarative approach. I am not going to dive into the solution here by code, but I am going to tell you the solution is to use a function in the way in which one has to point both ‘copy’ and ‘text’ to the memory location.
As you can imagine, this is not the same for imperative programming.
So there it is, this is the simplest way to understand this concept. Happy coding!