Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I noticed something this morning. Good code feels good - for whatever my definition of good is worth. I had been struggling with the beginnings of a large project and how to handle error conditions. Things were complicated and brittle. Lots of code existed to handle potential problems, obscuring the main goals. I couldn't seem to avoid multiple global variables, it was clear that changing things later would require updates in multiple places, Things were just generally yucky.

Then I figured out what to do. As I implemented it everything became simple(er) and robust(er). Lines of code dropped, what was left was easier to understand, long range coupling decreased. All was good in the world. (Why it took hours to settle on essentially die and warn and their associated sig handlers is something I'd rather not discuss <sigh>).

But I could literally feel that it was good. The code flowed and the structure was apparent. I didn't have to fight the language or logic. Stuff just happened, and with fewer keystrokes, fewer variables, fewer loops, etc..

The same thing happened earlier when I realized I needed a multilevel hash with coderefs and qr'ed regexes. Once I implemented that, some subs lost half their lines of code. Of course, after the fact, I realized that I was just implementing 'good coding practices' by moving things to data and utilizing features of the language in standard ways. But that was after I did it. The intuition came first, the analysis followed.

This is doubly interesting to me because it jives with how I view what I do in my real life as a graduate student in physics. There is a common view that the sciences proceed in an analytical way, with each step taken for consciously recognized reasons, like the derivation of a mathematical proof. That a researcher sits down at his desk or in front of her experimental apparatus and slowly and relentlessly and logically 'derives' new facts about the world.

From my experience this is complete hogwash. It doesn't work like that at all. What really happens is that you (well, I guess I can only say 'I', can't I?) flounder around in the dark, with vague notions of where you are and where you're going. You try various things that you're not at all sure will work. You try to fit various theories to the problem at hand.

After a few false starts you begin to see how things work, and you try a few more focused experiments and then you understand. Only after that do you construct a specific theory, set up clear and persuasive experiments, and 'derive' your conclusions from commonly accepted axioms.

Well, so much for my ramblings

Which way do you program? Relentless logical derivation or intuitive-casting-about-with-a-helping-dash-of-pre-and-post-hoc-analysis?

How much time do you spend consciously thinking things like 'I need to decrease coupling', 'This logic is too complicated', etc. and how much time do you just do it and go where your intuition says?

In reply to Code that feels good by scott

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2021-10-22 23:16 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (86 votes). Check out past polls.