What are Programming Paradigms?
Programming paradigms encompass the various styles used to program, and the characteristics that come with those styles. Programming paradigms are abstractions of language features and practices, but not languages in and of themselves.
Paradigms often piggyback off of prior paradigms, with significant overlap in characteristics, and most take root in two major paradigms: imperative, and declarative.
Understanding programming paradigms is important because they give us a common vocabulary to help categorize and understand features as they present themselves across various languages. It's important to know, though, that many languages tend to pick paradigm features a-la-carte; it's very rare that a language (especially modern languages) will implement only one paradigm purely. Languages that offer more than one style of programming are often referred to as multi-paradigm languages.
Some paradigms are actually pieced together from features seen in mathematics as well as languages that showcase new features; when LISP was invented in 1960, it featured recursion, among many other pioneering features. When the definition for functional programming was formalized, the idea of recursion was inspired by LISP when added into the paradigm.
Popular programming paradigms include the following:
- Imperative
- Declarative
- Structured
- Procedural
- Object-Oriented
- Functional
- Logical
- Event-Driven
Multi-Paradigm Languages
Nearly all languages offer features that can be classified under multiple paradigm definitions. For example, Python allows for both the creation of objects as well as the use of lambdas, and also features module-level scoping in the form of a python file. These three features each common to Object-oriented, functional, and procedural programming respectively.
Because of the presence of features found in separate paradigms, many languages are referred to as multi-paradigm, but sometimes we might classify a language, for example, as "an object-oriented language with procedural and functional features", or similar depending on what is most prevalent in the given language. Because languages can sometimes be difficult to individually classify, some computer scientists disagree with the practice of trying to classify languages into paradigms.
Different Paradigms for Different Purposes
Occasionally you might run into paradigm "purists", who are convinced that only X paradigm is needed, and all the others are just a waste of brain space. You might even see OOP purists battling it out with functional purists, who might claim the other's paradigm is impractical, or an all around mistake. These arguments aren't too different in spirit from those seen in the "console wars" between Xbox, Playstation, and PC (let's be honest, Nintendo is in a league of their own); at the end of the day, they all get the job done.
When I see arguments or read articles claiming a single paradigm is "superior", I often remind myself of the saying "when all you have is a hammer, everything looks like a nail." Different paradigms can solve certain problems better than others, but if all you know is functional programming or OOP, then every solution -in your perspective- is a perfect fit for {insert paradigm here}.
The goal of learning different programing paradigms is to help you realize that you have the whole toolbox, not just the hammer; if you've spent your whole programming career up to this point in imperative languages, understanding and utilizing the concepts of functional programming can help you write code that's more concise, and actually use all the language features in that multi-paradigm language you love so much!