2013-07-27

Writing code in my sleep

Not sure if I blogged this before but being a s/w engineer most of my life I occasionally find I have been working on code in my sleep.

I have woken to realise I have found a bug which is exactly where I think it will be when I check, having somehow tested changes and debugging in my sleep and reviewed code I had not looked at for a long time whilst in my dreams.

It is scary.

On some occasions I have written code in my sleep, which is the most disappointing thing to realise, as you then have to write it again while awake. Worse is if you do not realise until later that you only dreamed of writing the code and thought that you really had written it right up until you came to use it.

I had a funny today that was almost the other way around.

I had an issue from a customer and I realised that what was needed was a whole section of code that handled cases where SIMs did not authenticate with username or password. I worked out I would have to code the whole system, faking a PAP or CHAP response based on configurable parameters picking what to use as the "faked" username and password and so on.

I had been busy all week and so putting this off until this morning. But finally I put aside some time to code it.

I made a start and was a good 5 minutes in to coding when I realised that there was code already there, slightly later on in the code. It covered it all - a range of options for where to optain a meaningful username and set a default password. It was svn revert time.

Only now do I recall, in a haze that was a week in an air conditioned villa in Greece while the rest of the family sat by the pool in the sun, I had in fact already allowed for this and coded it. Not a dream this time!

All I had to do was point the customer at the config options!

I must be getting old and/or losing it :-)

6 comments:

  1. Maybe you are, but if so I've been getting old since I was about fourteen (as for losing it, I never *had* it to lose).

    The most recent example was dreaming in DWARF and finding a bug in the code I use to transform the DWARF representation of the types in the Linux kernel into a more compact form for DTrace. But I've been doing it for years: financial systems, compilers, even shell scripts, you name it I seem to have done more work in my sleep than awake, they're the only dreams I ever remember. I've also dreamt that I was falling along control flow or data structures, and woken up in a panic when I fell into an assertion or into some bit of data structure that spelt trouble.

    It's quite easy to have the inverse belief, that you dreamt something when you actually didn't. You just need to be ill or on the way towards being ill when you wrote the code, so it felt like you were asleep anyway, and you remembered it afterwards about as long...

    ReplyDelete
  2. It's certainly not just you!

    It's a very powerful technique, and I've used it a lot. You make sure you're acquainted with all the details of what needs doing, then you ignore it and do something else. Your subconscious mind is working on it while your consciousness gets on with whatever is the current task.

    Some time later when you come back to it, you can often find that the tricky bits are now "obvious" and you can breeze through it. It's like free brainpower, but it's not always reliable and sometimes you still have to do it the hard way!

    My most memorable occurance of this was a whole subsystem of a warehouse-managing system that I was writing - I knew what it needed to do but hadn't worked it all through. Then one morning I woke up and "knew" the whole thing, all the ins and outs of the design were clear in my mind, with no apparent work needed to resolve anything - and I *knew* it was correct!

    All I had to do was get the code into the machine straight from my mental model of the design, and it was all correct and worked first time (and for several years afterwards). Simples! :-)

    It doesn't always go that dramatically well, but when it does it's magic.

    Cheers,
    Howard


    ReplyDelete
  3. (RevK: if this is posted twice please delete one - for some reason it sometimes loses my message when I have to log in after typing it)

    It's a very powerful technique, and I've used it a lot. You make sure you're acquainted with all the details of what needs doing, then you ignore it and do something else. Your subconscious mind is working on it while your consciousness gets on with something else.

    When you come back to it, you can often find that the tricky bits are now "obvious" and you can breeze through it. It's like free brainpower, but it's not always reliable and sometimes you still have to do it the hard way!

    My most memorable occurance of this was a whole subsystem of a warehouse-managing system that I was writing - I knew what it needed to do but hadn't worked it all through. Then one morning I woke up and knew the whole thing, all the ins and outs of the design were clear in my mind, with no apparent work needed to resolve anything - and I *knew* it was correct!

    All I had to do was get the code into the machine straight from my mental model of the design, and it was all correct and worked first time (and for several years afterwards). Simples! :-)

    It doesn't always go that dramatically well, but when it does it's magic.

    Cheers,
    Howard

    ReplyDelete
  4. It's certainly not just you!

    It's a very powerful technique, and I've used it a lot. You make sure you're acquainted with all the details of what needs doing, then you ignore it and do something else. Your subconscious mind is working on it while your consciousness gets on with whatever is the current task.

    Some time later when you come back to it, you can often find that the tricky bits are now "obvious" and you can breeze through it. It's like free brainpower, but it's not always reliable and sometimes you still have to do it the hard way!

    My most memorable occurance of this was a whole subsystem of a warehouse-managing system that I was writing - I knew what it needed to do but hadn't worked it all through. Then one morning I woke up and "knew" the whole thing, all the ins and outs of the design were clear in my mind, with no apparent work needed to resolve anything - and I *knew* it was correct!

    All I had to do was get the code into the machine straight from my mental model of the design, and it was all correct and worked first time (and for several years afterwards). Simples! :-)

    It doesn't always go that dramatically well, but when it does it's magic.

    Cheers,
    Howard


    ReplyDelete

Comments are moderated purely to filter out obvious spam, but it means they may not show immediately.

Missing unix/linux/posix file open option

What I would like is a file open option for "create replacement file". The idea is that this makes a new inode in the same mount p...