i'm now so entrenched in someone else's toolset ( see runtime "use" statements via string eval ) that i can't get out of it and still make my deliverable. i was supposed to be the 'beta tester' to see if this OO toolset was applicable to more than just one project ( and ideally, it should be ). but i've ended up needed functionality added that wasn't planned for, and patching that support in is making what was a rather straight-forward object heirarchy and turning it into a maze of function calls.
and since this is pretty much one of my first OO projects, i don't have tons of experience to go on. . . .
is this the kind of coding procedure to look forward to when doing large OO projects. . .?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: OO Perl is making my brain hurt
by tadman (Prior) on Apr 05, 2001 at 09:55 UTC | |
What I mean, more diplomatically, is that while OO programming is intended to help the programmer to program better, but like discovering a new drawer full of knives and power tools, it increases your ability to hurt yourself if you're not careful. Recently, I was working on a library that compacted and uncompacted IP packets, something like NetPacket but for a different application. The original 'procedurally-based' program ran over 1100 lines with all the various routines required to handle ICMP, UDP, and the like. It was one of those things that just kept growing and growing. At this point, while I was pretty sure where I was going at any given time, nobody else could make heads or tails of it. 1100 lines of code was just too much for someone else to soak up at once, especially when the program was doing some things that made no sense unless you had read the requisite RFCs and understood what they meant. So, I pulled out some relatively static code that was functionally similar and made it into a module. Did that help? Not really. It just meant a lot less scrolling to find what you were working on, but things weren't any clearer. Now you had to cross reference two files to figure out what the program did. So, I whacked away at it again, this time taking an OO approach, and knowing the scope of the program in advance having already programmed it once. I made a few objects that inherited nicely from each-other, and packed this all up into a convenient object that did all the work for you. The end result is a 'main' program that is 51 lines ling, including comments, parameters, and generous white space. The actual 'program' is extremely brief: If you don't know what the heck a Framisdat::Engine is, just perldoc Framisdat::Engine, and read the POD descriptions of the object, and its methods. If when examining the code, you discover something curious, such as a Framisdat::WonderPacket, the same procedure applies. The real benefit of OO is that when examining the code, you only have to dig as deep as you need. Everything else is some sort of little 'black box' which you know how to operate (because of the docs) but don't care about the details. Compare using the 'old' way of using UNIX networking with the new 'OO' way using IO::Socket. Before you had to jump through a whole pile of hoops to do something as simple as create a network socket and connect it to something. Now you can do this in one line and it has better error checking to boot. I'm sure most people are completely stunned after reading something like perltoot. I was. It didn't make any sense at all for the longest time. While authoring objects is perhaps a little bit harder than writing regular code, as you have to think a little harder, using well written objects can be so much easier. | [reply] [d/l] [select] |
|
Re: OO Perl is making my brain hurt
by knight (Friar) on Apr 05, 2001 at 06:37 UTC | |
When I was first exposed to OO principles, I found that many of the touted OO advantages had analogs in things I considered plain old good software engineering practice from my straight-C days: using libraries to avoid re-inventing the wheel (code re-use), "private" structure definitions (data encapsulation), well-defined accessor APIs (method calls). OO does go beyond that, though, making it easy to do nifty things like inheritance that are, at best, laborious without an OO language. Learning OO has actually made me a more effective non-OO programmer, too, so don't let a first sour taste turn you off. There's plenty of value in learning the principles, if only to give your mental toolbox an alternate way of approaching programming problems. | [reply] |
|
More than scratching the surface.
by frankus (Priest) on Apr 05, 2001 at 17:36 UTC | |
This sounds like a plethora of issues; I'd like to summarise your comments 1: Getting OO experience is tricky, ideally you'd have a mentor to guide you. merlyn has written a pretty good tutorial, as ever I'll mention Mr Conway's book, it rocks. Of course there is also perlmonk's own tutorials OO is overwrought for small applications. This is Perl, there are ways around it (oh yes ;). With looming dead-lines (and bad code) good practice isn't high on the agenda, nor should it be. Hack my friend, hack like the wind. Learn OO in fullness later and fix poorly designed code during a lull. For work issues, we need a well-measured response from someone with many years experience in development. My only real advice is pass the stress to your manager. (I bet you've done that already ;), but it is important to define the remit of your responsibility, to do your job well. (1.) Because some folk seem to be wearing OO only blinkers, and I feel there are more answers to give than what OO is, and how it should be used. I can't answer all these points, so please add relevant stuff. --Brother Frankus. | [reply] |
|
Re: OO Perl is making my brain hurt
by Masem (Monsignor) on Apr 05, 2001 at 05:59 UTC | |
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain | [reply] |
|
Re: OO Perl is making my brain hurt
by lachoy (Parson) on Apr 05, 2001 at 06:18 UTC | |
I really do feel your pain, but sometimes these things are actually done for a reason. This reason might not be immediately obvious to you, but it's still there. These are exactly the sort of things that should be in documentation so that you know the author did something consciously and for a reason rather than capriciously. Unfortunately, docs are frequently written so far after the fact of programming that the reasons for doing certain things get lost. Of course, sometimes it's just a poorly designed system and there's no excuse to be made :-) (Calling use within a string eval is kind of odd...) Another thing is this: Perl's OO implementation is quite low maintenance, so creating a subclass with refactored code (for instance, combining the three methods of Class A from your example) is extremely simple. If something's broke, you can fix it! Chris | [reply] [d/l] |
|
Re: OO Perl is making my brain hurt
by mothra (Hermit) on Apr 06, 2001 at 17:08 UTC | |
Every language has its own way of treating OO, and Perl is certainly no exception to having "its own way". As you may or may not know, my day job pays me to write Powerbuilder code. Powerbuilder's "way" is the PFC, which is a service-based architecture. Because of that, the project I'm involved in has resulted in us creating a lot of objects whose only purpose is to do things for other objects (ie. a "sort service"'s purpose is to provide sorting capabilities for datawindows. A "time filter service" was created to provide information to any object that wants to know about time search criteria. etc, etc) However, the project I'm working on is quite large (somewhere between 15,000-20,000 lines, 200+ stored procs, 20-25 table database, about 15-20 different windows, well over 100 classes we've written, etc). OO scales nicely though, and despite the fact that there is definitely a steep learning curve (steep in learning the PFC too), OO has taught what to me is a very natural way of thinking about The Way Things Work. What am I getting at? The point I'm trying to make is that you will probably find that with some patience and practice/experience, OO will scale well. Familiarize yourself with the way Perl does OO and try to think like it does (much like we're doing with PB and the PFC, which have lead us to think in terms of creating a service-based architecture). To this point, I haven't written my own OO code in Perl (I've used other's modules in "an OO way" though), but I still find that much of the way I think about OO in Powerbuilder is very applicable to Perl, certainly in terms of the way I can design classes and methods in a way that minimizes coupling and maximizes cohesion. Give it a chance and you could very well find that this new way (for you) of thinking about things could open up a whole new way of solving problems. You might even like it. :) | [reply] |
|
Re: OO Perl is making my brain hurt
by fmogavero (Monk) on Apr 06, 2001 at 21:12 UTC | |
For example: When you use DBI to access a database, you are actually using an object. Logging on to the server you use . That is using an anonymous object created by the DBI package to create a connection to the database. You are required to pass it parameters. The documentation tells you what parameters to use. You might be able to write scripts and use the objects in the toolset for specific tests. I think that with time you will be able to understand what the creator of the toolset wanted. In the meantime, you can override methods or create your own inherited objects to test the toolset. | [reply] [d/l] |