I am programming in Java in a very object-oriented (OO) style. OOP comes very intuitively to me, but I have very little knowledge about other kinds of programming.What exactly is procedural programming? How exactly is it different from OOP? Is it the same thing as functional programming?I used to think that all programming that isn't OO is procedural. But I'm starting to think this isn't true.
What exactly is procedural programming? How exactly is it different from OOP? Is it the same as functional programming?
object oriented;procedural
Wikipedia has good explanations for these terms. Regardless, here's the summary:Imperative programming models computation as a sequence of statements that alter mutable state.Procedural programming is imperative programming that breaks down the code into subroutines.Structured programming is a more disciplined approach to procedural programming that forbids arbitrary jumps (e.g. goto) and global state changes.Declarative programming is the opposite of imperative programming - it specifies what to calculate rather than how (e.g. SQL, regexes).Functional programming models computation as expressions that (may) yield values. Functions are values and can be passed to or returned from other functions. Mutation is discouraged; all variables are immutable by default. As a result, it's more declarative than imperative, since it emphasizes what is being computed rather than the sequence of state changes needed to achieve it.Purely functional programming disallows mutation altogether (though contrary to popular belief still has mechanisms for achieving side effects).Total functional programming additionally forbids exceptions and infinite looping. (A total function in mathematics is a function that returns a value for all of its inputs.)Object-oriented programming emphasizes the use of objects/interfaces to achieve abstraction and modularity.Their relationships are a bit complicated because OOP is a pretty loaded term. You can use objects in both functional languages and procedural languages, but the languages that advertise themselves as OO are procedural. To further confound the issue:Most people don't know the difference between an object and an abstract data typeMainstream OOP languages make no mention of ADTs, provide very poor support for them, and tout objects as The One True Way.No one says Abstract Data Type-Oriented Programming (because it'd be a silly thing to do; you need both ADTs and objects.)This causes people to think OOP is the only way to achieve abstraction, and that functional programming and OOP are somehow opposites or mutually exclusive. A lot of people also think all functional languages are pure and disallow mutation.Additionally, people generally toss around imperative/procedural interchangeably, sometimes contrasting it with OOP (implying abstraction-less code, generally C) and sometimes contrasting it to functional programming. The term structured programming has mostly fallen out of use as far as I can tell (likely because at this point most people take for granted that goto and globals are considered harmful.)