Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Data Structures

by leocharre (Priest)
on May 02, 2008 at 15:05 UTC ( [id://684186]=note: print w/replies, xml ) Need Help??


in reply to Data Structures

I am going to approach question from a different angle.
I am going to assume by "would then be accessed as" and by "Is there an easier, more efficient way to do this?" you may be talking about interface more then performance.

"accessed as" wreaks of api, as does 'easier'. I'm going to imagine that efficient means you want to be able to remain efficient in your job as in you don't want to go insane in 6 months- and create something important that only you know how to use...

I smell poop here.
Perl Object Oriented Programming.

I am trying to suggest that.. let your code be all nuts and creepy.. but.. provide an object oriented interface. Then later on you can worry about the innards and not change the interface.

Wouldn't it be nicer to interact with ...

use Seismic; my $s = new Seismic; my $lines = $s->lines; my $line0 = $s->line(0); my $line1 = $lines->[1]; my $stations = $line0->stations; my $station0 = $stations->[0]; my $station1 = $s->line(0)->station(1); my $x = $station0->easting; my $y = $station0->northing; my $z = $station0->elevation; my ($x,$y,$z) = $station1->xyz;

You can then rearrange your code, change your hash hierarchy, and it won't change your scripts using it, etc!

I've done some crazy hash stuff like this before- and looking back, this is stuff that's a nightmare to maintain interaction with. The interface really should be separated from the innards.

This is what OO is for, this is what computers are for, not people, imho.

Putting the extra week or two to learn some OO and implement it here- will save you countless hours later.

Replies are listed 'Best First'.
Re^2: Data Structures
by YYCseismic (Beadle) on May 02, 2008 at 16:10 UTC

    Yes, I suppose I am talking more about interface here, rather than performance. I do want the program to be fast and efficient at what it does, but I also want it to be an easy-to-use and efficient tool for loading surveys. The previous version of the program looks to me more like a kludge rather than something that was well thought out with some semblance of design taken in to account.

    The possibility of using OO code had crossed my mind, but I was not sure I'd know how to do it properly. (I certainly do like the sample you have shown!) Fortunately, this project is not a priority, so I'm basically working on it during "down-time", which allows me to learn a lot in the process. Can you (or anyone) recommend any specific books for helping to learn poop?

      Very good attitude.

      Once you go over the learning curve, this is all going to make so much sense to you that you'll be jumping up and down throwing confetti at random strangers and nobody will understand... but that's ok.. we understand.

      It will not take long to get it, and seriously- it will be a blast. You can still have very intricate ways of associating and storing data but you can have an incredibly simple way to get to it.

      With OO, you think of the modules (classes) as blue prints, as instructions on how to build something. And objects are the thing made, the houses built from the blue print, alive- and this only happens when you 'instance' (new) from a module(class).

      You have your architect's plan, and you build from it 5 houses, they all have different addresses and people inside them, but you only needed one plan.

      Anywho, forget everything I said and try it out. You can get an example working and understood in a few hours. After that you will think you 'got it'- and then a few days later you'll start to more honestly get it. This is what I went through.

      Do you have the OReilly Porgramming Perl book? You should have a copy, you can get it off amazon for 10 bucks. You'll need it- it's very handy.

      This is (un?)fortunately going to be an adventure, learning OO. There is no one place to 'learn' it. You will have to scavenge various sources, from each place you will attain a new facet of understanding. And you will have to experiment endlessly- which you will probably do out of sheer curiosity if not out of need.

      Search the turorials section, there's really some very good stuff in there.

      Most important, do not get discouraged if it's weird. Don't give up on the concepts until you can tell yourself you really understand what the idea of oo is.

      I love good ol bash and straight empirical(is it?) functional programming - but for complicated stuff with thousands of lines of code...screw that! I need pOOp. (sorry... it's Friday...)

      (Please excuse the very loose non technical language in this post).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-19 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found