> Programming Languages > Perl
Various Topics Home | Disclaimer | Report Adult Posts

Various Topics on Perl



Perl - "Complex datastructure do***entation?" in Programming Languages


Old 11-18-2004   #11
.. ..n.. ....
 
Default Re: Complex datastructure do***entation?

Doug O'Leary <dkoleary@olearycomputers.com> wrote in
news:slrncpq50f.cp6.dkoleary@x1-6-00-b0-d0-c1-44-09.comcast.net:

> On 2004-11-18, A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
>>
>> I am not sure if you intended this to be a sarcastic remark but it
>> does come accross that way.
>>
>> There is no way you came up with the data structure you came up with
>> through "good" design. Take John's recommendation to heart, figure
>> out the relevant abstractions.

>
> To be blatantly clear - Yes, it was meant to be sarcastic. It was
> meant that way and meant to be taken that way. He has no logical
> basis for critiquing code he hasn't seen.


You don't have to see the fish to smell that it is rotten.

> Nor, will I listen to pedantic pinheads who critique code or
> procedures they haven't seen.


Yup, that's me.

Sinan.
 
Old 11-18-2004   #12
..i ..ttm..
 
Default Re: Complex datastructure do***entation?

>>>>> "DO" == Doug O'Leary <dkoleary@olearycomputers.com> writes:

DO> On 2004-11-18, Uri Guttman <uri@stemsystems.com> wrote:
>>
>> but no one else uses that style. think about it. code for yourself or
>> for others - which is more professional?


DO> Actually, I usually code for other UNIX administrators. This
DO> script, for instance, talks to oracle databases, obtains a list of
DO> logical volumes its using, then verifies/updates Omniback
DO> datalists to ensure the databases are getting backed up correctly.

so do they do code review for you? i do it professionally and teach perl
and refactor it. no one uses that style of data structure code in any
depth.

DO> Another script, more complex code, but less complex data
DO> structure, hits up to 1800 routers/switches via snmp every 5
DO> minutes and runs a user specified command if a user specified
DO> formula evaulates to true.

so what if it works? it is not maintainable by anyone but you. sure some
could hack it but it is harder to work with than it needs to be.

DO> Command = `$opcmsg node=$Node app=SNMP obj=SNMP msg_grp=SNMP severity=warning msg_text="Output queue drops > 3% bandwidth."`
DO> ###

DO> That client is still using that script - at least they were
DO> two months ago when I talked to them last...

so what? lots of bad code it used all the time. it is still bad code.


>> anyone who does perl data structure stuff without using data::dumper as
>> a debugging tool is not doing it right. (YAML can be used too but it
>> isn't standard in the perl core).


DO> I'm not sure I buy that 100%. After figuring out what was needed,
DO> I was able to generate this data structure w/o errors first time
DO> running. It read the config fiie, created the structure, then
DO> read it back out again using simple loops and print statements..

fine. i can do that too. big deal. it is still not the best way to do
it.
DO> # printf ("\t%-8s %-7s %-4s %d\n",
DO> # ${${${$hash}{'Datalist'}}{$dl}}{'Host'},
$hash->{'Datalist'}{$dl}{'Host'}

if you don't think the latter is clearer and easier to read, you must
have braces tattooed on your eyelids. it is shorter too.

DO> data::dumper may do all that work for me; dunno. I'll look into
DO> it though. So far, though, I haven't *needed* it - and all my
DO> scripts work the way they're supposed to..

dunno?? what about dumper wouldn't do? it dumps perl data structures. it
does it accurately. it is flexible. it is easy to use. its output can be
postprocessed easily. it can be eval'ed back into perl later.

DO> Thanks again for the input, though. I like learning new ways
DO> to do things.

that is good. your structure skills do need you to learn more.

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Old 11-19-2004   #13
.... ..bs..
 
Default Re: Complex datastructure do***entation?

On Thu, 18 Nov 2004 18:52:08 +0000, Doug O'Leary wrote:

> ################################################## ###################
> # Redesigned data structure.
> ################################################## ###################
> # %$hash:
> # ${$hash}{Datalist} = \%datalist:
> # ${${$hash}{Datalist}}{$dl} = \%
> # ${${${$hash}{Datalist}}{$dl}}{host} = $host
> # ${${${$hash}{Datalist}}{$dl}}{sid} = $sid
> # ${${${$hash}{Datalist}}{$dl}}{suffix} = $suffix
> # ${${${$hash}{Datalist}}{$dl}}{stream} = $stream
> #--------------------------------------------------------------------
> # ${$hash}{Host} = \%host_list;
> # ${${$hash}{Host}}{$host} = [ \@dls, \%sids ]
> # ${${${$hash}{Host}}{$host}}[0] = \@dls
> # ${${${$hash}{Host}}{$host}}[1] = \%sids
> # ${${${${$hash}{Host}}{$host}}[1]}{$sid} = [ @dls, %lvs ]
> ################################################## ###################
>
> Does anyone have any tips on how I could do***ent that
> clearly - for people that aren't used to complex data
> structures in perl?
>
> Any formatting/other hints/tips greatly appreciated.


Err.... write it in English ?

The do***entation is uninformative and duplicates itself :-

{stream} = $stream could read

{stream} the input stream, type is scalar, etc. i.e. explain what it is

Use the -> notation and remove the superfluous duplication :-

$hash->{DataList}->{<DataList Key>}->
{host} the host reference comment
{sid} the sid etc.
{suffix} the suffix
{stream} the stream


 
Old 11-19-2004   #14
.... ..k..
 
Default Re: Complex datastructure do***entation?

Doug O'Leary wrote:

> On 2004-11-18, John Bokma <postmaster@castleamber.com> wrote:
>>
>> Rewrite it, to use OO programming.
>>
>> Also, do***entation should be your first step in design, not last.
>>
>> I think with 3 or 4 cl***es you can make it way more readable and
>> less error prone.

>
> Wow; I can only aspire to being good enough to critique code without
> seeing it... That's truly impressive. I will be certain to give your
> thoughts all the consideration they're due.


Things like:

${${${${$hash}{Host}}{$host}}[1]}{$sid} = [ @dls, %lvs ]

Even if you write them using the -> notation are a pain in the lower
part to maintain and to read.

You can just ignore my remarks however, I don't care.

But if interested, clarify what

${${${${$hash}{Host}}{$host}}[1]}{$sid} = [ @dls, %lvs ]

means, and I try to come up with an OO design. Maybe others can chip in
a bit too.

And my other remark, regarding do***entation is certainly valid. I just
finished a small OO thingy, which took more time on paper than to
actually implement :-)

--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html

 

Thread Tools
Display Modes





Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0