Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re (tilly) 3: Efficiency in maintenance coding...

by jynx (Priest)
on Nov 15, 2001 at 04:26 UTC ( [id://125472]=note: print w/replies, xml ) Need Help??


in reply to Re (tilly) 2: Efficiency in maintenance coding...
in thread Efficiency in maintenance coding...


One last hurdle,

What if you want to print out the list not alphabetically, but by how many occurances of the word occur? The easiest way to do this would be an ST1. Is an ST easy to maintain?

Correct me if i'm wrong but i believe that Java has a method of doing this immediately (which is probably why they used the Tree to print it) whereas Perl can do it readily, but it's harder to understand for the common Java programmer, not to mention a few Perl programmers. Who wins maintainability this time?

jynx

1Schwartzian Transform
update - d'oh, i shouldn't post before my first cup of coffee. please disregard...

Replies are listed 'Best First'.
Re (tilly) 5: Efficiency in maintenance coding...
by tilly (Archbishop) on Nov 15, 2001 at 04:55 UTC
    Perl.

    Right now our Java solution hasn't yet figured out how to handle contractions yet. Perl is still ahead. Secondly why break out the sledgehammer when you don't have to?

    foreach my $word ( sort { $freq_count{$b} <=> $freq_count{$a} or $a cmp $b } keys %freq_count ) { print "$word:\t$freq{$word}\n"; }
    Most Perl programmers should understand this. Doing the same in Java, well probably somewhere in their maze of classes is one that naturally sorts in exactly the order you want. Good luck finding it, and good luck for the average Java programmer realizing why you chose this way of doing things.

    And as for the maintainability of a Schwartzian Transform, it is a trick. If you think in a list-oriented way, or if you have ever really understood the tranform, then maintaining it when you see one is pretty easy. I understand it, and I try to ensure that people I train are able to handle list-oriented thinking. So it isn't a problem for me. But YMMV on its maintainability.

(tye)Re2: Efficiency in maintenance coding...
by tye (Sage) on Nov 15, 2001 at 04:45 UTC

    No Schwartzian Transform is required. Does Java let you easily sort ignoring case? How about by length?...

    sort { $freq{$a} <=> $freq{$b} } keys %freq sort { lc($a) cmp lc($b) || $a cmp $b } keys %freq sort { length($a) <=> length($b) || lc($a) cmp lc($b) || $a cmp $b } keys %freq
    You might find that a ST executes faster for that second case (and you could almost certainly speed it up with one of several techniques that are faster in Perl than an ST), but I doubt the speed gain would be worthwhile since lc() shouldn't be that slow.

    Speeding up the third case with a ST would be more difficult than using some other sort-speeding techniques (many of which have names that I don't recall). Though you'd have to have a whole lot of different words for the trade off of sort speed for code complexity to be a "win" here, especially since we are trying to write very maintainable code.

            - tye (but my friends call me "Tye")

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://125472]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-03-29 06:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found