in reply to Light Bulb Joke

How many Object-Oriented Programmers does it take to change a lightbulb?

You shouldn't be changing the light bulb by hand. If you'd used Electric::Light instead of reinventing the wheel, the Electric::Light::Socket would have noticed the need for a new Electric::Light::Bulb object and instantiated it automatically. By rolling your own implementation, you're likely to get all kinds of edge cases wrong. Can your hand-rolled lightbulb-changing code correctly handle 240V 50Hz current and install the correct sized bulb for the room in question? What about 120V and 60Hz? What if the building's electrical system uses unicode? What if this is an embedded lightbulb running on a small flashlight system? Electric::Light handles all of these details correctly for you. By trying to do this stuff yourself, you're going to repeat every bug that's been ironed out of that module over the years. Will your hand-rolled implementation be tested by millions of people worldwide on dozens of platforms, from LED-based indicator lights all the way up to redundant arrays of airport beacons? No. Use Electric::Light or die.


;$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$;[-1]->();print

Replies are listed 'Best First'.
Re: use Electric::Light or die
by mugwumpjism (Hermit) on Feb 16, 2004 at 23:19 UTC

    And then you go to change a lightbulb of a high intensity discharge light, and find that Electric::Light does not support edison screw bulbs - only bayonet. So, you get involved and add support for Edison screw bulbs, including mini-sized, and complete the support, adding mini bayonet fittings. This was easy enough, and you contribute the code back. The patch is not accepted because the original author did not like your suggestion that the code wouldn't work on all light bulb fittings, and when he finally went to the effort of buying an "obscure" light fitting from a "specialist" store, the first case he tried it on - mini bayonet - didn't work due to a typo. You decide to use your modified version and forget the original author.

    However, as you use the derived module more and more for a wide variety of purposes, you find that you need higher powered lights, so investigate supporting High Intensity Discharge lamps. But Electric::Light is missing the abstraction layer of a ballast, so cannot automatically determine what type of light to install. The assumption that you're using a simple mains light bulb is "hard-wired" (sorry) into the program. So, you try to modify the code to add the functionality, but the implementation is a poorly considered procedural mess and you start from scratch on the OO Electric::Lamp.

    Your new implementation handles all sorts of high intensity discharges correctly - and the high-end lighting community is overwhelmed with satisfaction - but support for changing standard mains bulbs is never considered, because the new code supports HPS, LPS, Metal-Halide, Fluourescant and Neon lights correctly. This is achieved through a strict OO approach, each bulb exporting its required characteristics and performance values in a sensible fashion. What was previously a mine field of matching component specs to get the right transformer, ignitor, inductor, ballast and lamp combinations is now as easy as:

    my $light = new Electric::Lamp (type => "HID", bulb => "HPS", power => "250W"); $light->install($fitting);

    Traditional, incandescant bulbs look so pale in comparison, that someone writes a Electric::Light::Bulb::Lamp that contains a fluourescant tube in the same original API, and while it costs you an extra 400% in startup time and takes marginally longer to light up, you saved 85% of the power bill, made the part last 10 times longer and hence increased the efficiency of the system.

    Critics of Electric::Lamp say "that module sucks! It can't even change a simple lightbulb without installing the Electric::Lamp::Discharge, Electric::Lamp::Ignitor, Electric::Light::Ballast, and Electric::Lamp::Fluourescant modules! I even had to install the Electric::Transformer and Electric::Inductor modules, what on earth for? Not only that, but it takes 3 seconds to start up! What a waste of space!". Of course, as he does not run the module for the 5 years to see the real benefits, he keeps happily letting Electric::Light change every bulb every 6 months.

    People with experience with professional lighting come along and ask him how to light up their stadium, and they are told; "Go to Electric::Light. It's all you ever need to light your house and beyond; it supports light bulbs up to 1 million Watts, in theory!". The module doesn't do anything like the scale that they need, so they end up getting a .NET contractor in instead, and pay them 10 times what they needed to, for a solution that's barely more efficient than your average fluourescant tube.

    Ah, cynicism.

    The lesson is, horses for courses.

    $h=$ENV{HOME};my@q=split/\n\n/,`cat $h/.quotes`;$s="$h/." ."signature";$t=`cat $s`;print$t,"\n",$q[rand($#q)],"\n";