Athanasius:

Thanks for taking the time to take a look at it.

Regarding encapsulation violations: One of them was accidental. After I got the code largely to where I wanted it, I didn't like the delete $g->{nodes}{out_neg} statements, so I created _keep_only_names() to handle that. I put it into the first example, but forgot to put it into the second example. After thinking about it, I think that a better approach would be to tell the simplify() function which names it needs to care about, so I can use the same graph for multiple runs. If I ever get serious about putting more electronics components in there and other network types, I'll probably do something like that.

For the second one, as you mention, I should put the factory functions build_impedance() and build_pad() into the Gr package.

I don't generally write OO code in perl (aside from using packages from CPAN), as generally I use perl for my "let's learn about some problem domain before getting serious" language. I find good OO code really requires you to have a sufficient understanding of the problem domain before you start figuring out what the classes are or should be. I don't often get to use perl at the $job, so I generally use perl to explore the problem, then switch to an "approved" language, with classes and objects and whatnots ;^).

Your solution to removing the duplicate node() calls is amusing looking. I may have to play with it a little and see how I like it.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re^2: Resistor network simplifier by roboticus
in thread Resistor network simplifier by roboticus

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.