For instance take your example above. You have a nicely encapsulated function to produce Fibonacci numbers. Perhaps it looks like this:
So you want to break the encapsulation to show how the computation works. Well what happens if someone wants to later on Memoize the function so that it will calculate answers at a reasonable rate? There is no good way to show the logic and also short-circuit uselessly repeated logic. So you are now stuck with an exponentially bad algorithm to calculate this function because someone might want to display it...sub fib { my $n = shift; if ($n == 0 or $n == 1) { return 1; } else { return fib($n-1) + fib($n-2); } }
OK, this is a toy example, and with excess work you can work around it. But the principle still holds. When you break the encapsulation, you cause extra work and limit your ability to optimize under the hood. And this is a bad thing. By contrast if you separate display and implementation, then you don't needlessly complicate your life later. Sure it makes some things harder now, but if you can hold that line it will make a lot of them easier later.
In reply to Re (tilly) 1: How realistic is separation of computation from it's display?
by tilly
in thread How realistic is separation of computation from it's display?
by princepawn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |