Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Re: Perl editor idea

by snowhare (Friar)
on Jan 14, 2004 at 14:46 UTC ( [id://321340]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: Perl editor idea
in thread Perl editor idea

For example, I have three arrays that each have to be spliced whenever one of them is, but that's not obvious when working on a routine that deals with only one of them

Use objects. Really. Your problem is that you are doing something complex and scurrying around doing all the things a good object system should be making simple manually all over the place. And as you have discovered, as a system grows large, it becomes impossible to keep all the details in your head at one time.

Step back from your code and analyze what it does. Massive use of global variables is usually a symptom of lack of analysis - you didn't know what you were going to do before you did it. In the hundreds of packages totaling megabytes of Perl code I've written in the last few years, there are only a few _dozen_ global variables - nearly all of which are in fact constants.

If you have three things that have to be maintained in complete synchronization - embed them in a 'container' object that understands how to update and read them. Talk to the container object - never directly to the hashes. Then updates only take one simple call and you worry about what not how the container does what it does in the rest of your code.

Replies are listed 'Best First'.
Re: Re: Re: Perl editor idea
by Wassercrats (Initiate) on Jan 14, 2004 at 17:01 UTC
    Thanks for making your first writeup a reply to my post! Objects were a whole other level of Perl that I was nowhere near ready for when I began my script. I've read a little more about OO programming recently, and I still don't want to take the time to learn it right now, but it's true that I had no idea what my script was going to become when I started it. I don't doubt that it would be better written using objects though.

    Some day, I'll improve my skills enough so I could do things more conventionally, and so I would have more tools at my disposal. I think I could contribute more to the Perl community that way too. One of the reasons I'd be reluctant to release a subroutine of my script as a Perl module is that it would probably be pounced upon and improved beyond recognition and beyond my ability to work with it any longer, and I wouldn't want to lose my first baby.

    I just downloaded Eclipse and was going to try the EPIC editor plug-in, then I was told about Emacs in this thread and was going to try that, and now I see there are even more editors I could try (I'm on Windows XP). I'm not sure what I'm going to do.

      Its not real clear to me that OO will help you here. I think for starters you should simply throw away your code and rewrite it from scratch. Without using any globals. This is a form of refactoring that as a programmer you should be comfortable with. While its a little bit agressive, and some may suggest a less drammatic form of refactoring, a total rewrite can be very beneficial and many programmers and programmer shops assume that the first version of eveything will be thrown away. The result is usually cleaner and better code.

      Think of it this way: You already know what needs to be done (always an important issue) you already know at least one way to do it, and you most likely have learned important lessons in how it can be done better. In fact you certainly have, as you have already noticed that using a lot of Globals is just trouble.

      So rewrite the puppy. Try not to look at the old code when you do, and certainly avoid cut and pasting from it as much as possible.

      The result will be better code and many useful lessons learned.


      ---
      demerphq

        First they ignore you, then they laugh at you, then they fight you, then you win.
        -- Gandhi


        So rewrite the puppy. Try not to look at the old code when you do, and certainly avoid cut and pasting from it as much as possible.

        YIKES!!! It's a bit more than a puppy! Have you seen the (disabled) interface? The script does this in about 2500 lines (I hate that comments get included in these counts). It works beautifully and I can handle the maintenance. It's just that I had some ideas that would make things a bit easier. Out of curiosity, I would like to see the expression on a maintenance programmer's face after he saw the code, but I'm the maintainer now, and it seems ok to me.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://321340]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.