Previous | Next --- Slide 6 of 64
Back to Lecture Thumbnails
flyne

Is there a way of deciding which performs better, declarative or imperative without actually testing it?

Elias

That question doesn't really make sense. Imperative means that you (the programmer) have actually specified how something should be done. Declarative makes no claim about the implementation - a declarative framework may be implemented many different ways, and they may have dramatically different performance characteristics.

You'd have to evaluate an imperative approach against a particular implementation of a declarative approach - and even then, you'd have to actually test it.

yuel1

I guess this goes back to the lecture on abstraction we had earlier in the semester. An Imperative implementation is only as good as you can make it, a declarative one can be very bad (in that the implementation is very basic) or it can be very good. The way I see it, unless performance is absolutely critical, 9 times out of 10 it's better to go with a declarative solution (not to mention it's faster to write and less likely to be erroneous)

BryceToTheCore

@yuel1 I think I see things differently. It depends on what you mean by "better". I know that I learn a lot more when I actually know how the machine works and sometimes it is fun to spend a longer time writing code and debugging can also be a fun process and lead to some revelations that cannot be found if the implementation details are swept under the rug.

That said I am very biased towards imperative programming and very biased against declarative programming.

yuel1

@BryceToTheCore I guess what I meant by better is added productivity. Unless I was implementing something that was on the critical path of something very valuable or important (time wise, think high frequency trading, or something big data related that gets run a lot). I would most likely save time by using declarative programming...

BryceToTheCore

@yuel1 The main thing I wish to convey is that different people will have different preferences about this. I wish to give some voice to the imperative programmers out there.

For me, I understand imperative programming and enjoy it so much, that it takes less time for me to write a program imperatively with algorithms that I fully understand than to read, understand, and gain competency in a declarative programming framework. I also like that I can avoid being "black boxed" out. If something is going wrong with the framework implementing the declarations or has a performance problem, then it is harder for me to fix it.

the abstraction of a declarative model is a strong point, provided one can fully understand the interface and expected behavior and performance guarantees that it provides.