Reputation: 531
An article I read gave this example for the difference between declarative and imperative programming:
Declarative
small_nums = [x for x in range(20) if x < 5]
Imperative
small_nums = []
for i in range(20):
if i < 5:
small_nums.append(i)
The imperative example declares an array. How is the data stored in the declarative example? Or is the storage structure determined by a separate piece of software?
Upvotes: 1
Views: 205
Reputation: 531
Based on my searches, declarative programming does not create data structures. Instead, declarative programming is an abstraction. That it, it calls on objects that create the needed structures.
With that in mind, the imperative programming is not done away with, it's just pre-written.
Upvotes: 1