Modularity usually does not cooperate very well with attempting to break encapsulation. That is usually a Good Thing. (And most of the time when people want to break encapsulation, that is a Bad Thing.)

For instance take your example above. You have a nicely encapsulated function to produce Fibonacci numbers. Perhaps it looks like this:

sub fib { my $n = shift; if ($n == 0 or $n == 1) { return 1; } else { return fib($n-1) + fib($n-2); } }
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...

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.