Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: Simplicity vs. Doing It Right

by dws (Chancellor)
on Oct 13, 2002 at 17:22 UTC ( [id://204918]=note: print w/replies, xml ) Need Help??


in reply to Re: Simplicity vs. Doing It Right
in thread Simplicity vs. Doing It Right

Using a module is not only about reusing code. It's also reusing knowledge about the problem domain.

I agree entirely, but let's approach this from the perspective of someone who needs to understand a thin slice of a problem domain in order to solve a problem, and is handed a handful of standard modules that cover a superset of their problem. If they take the code snippets as offered, they risk being on the slippery slope towards Cargo Cultism. If they take the time to grok the modules, they come out better in one way (knowledge and skill), but worse in another (the opportunity cost of the time taken to understand the modules).

The example that started this off is an interesting one to think through. Someone needed to run unit tests through a browser. They decided to write a small web server. (Perhaps they'd seen another example where this approach had been successful. Perhaps they were in an environment that precluded their installing Apache or IIS. We don't know.)

The slice of the problem that they needed to solve was

  • Use sockets to respond to HTTP requests
  • Ignore requests that didn't originate from localhost
  • Parse just enough of an HTTP request to figure out what to do
  • Return static HTML or images, or run a Java program that emits HTML, and return the results
  • Return a minimally correct content header with the response

This they were able to cobble together in 61 lines. Not pretty, but workable.

If they'd come to me for help, I would have suggested starting with HTTP::Daemon. To use HTTP::Daemon righteously, you need to understand HTTP::Request, HTTP::Response, and HTTP::Status. Status is trivial, but to understand the first two, you need to add HTTP::Message to the mix. It's a common superclass, which adds additional complexity weight. HTTP::Message uses HTTP::Headers, which pulls in URI::URL, HTTP::Date and MIME::Base64. URI::URL subclasses URI::WithBase, with overrides stuff in UNIVERSAL (heads are spinning at this point.)

And I'm leaving stuff out. By suggesting HTTP::Daemon, I've sent someone away with a pretty hefty transitive closure of stuff to read through and understand, if only to know whether or not it applies to their problem.

Are they better off? Maybe yes, maybe no.

Replies are listed 'Best First'.
Re: Re: Re: Simplicity vs. Doing It Right
by chromatic (Archbishop) on Oct 13, 2002 at 21:19 UTC

    I think your initial list is an oversimplification. Either the coder in question takes the time and energy to read and to understand the relevant HTTP RFC, or he copies code from somewhere else. Which is more Cargo Cultish? Maybe it would be simpler (for some value of simple) to post this message by telnetting to port 80, but I'm using a web browser.

    Update: Fixed a punctuation bug.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-25 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found