Shop OBEX P1 Docs P2 Docs Learn Events
The problem is NEVER with MY code, because I a coding genius — Parallax Forums

The problem is NEVER with MY code, because I a coding genius

Tony B.Tony B. Posts: 356
edited 2011-11-17 22:32 in General Discussion
I have just spent the last 2 1/2 hours trying to get a new little project working and like so many times before I was sure it was my Demo board or bad wiring NOT MY code. I then spent about twenty minutes writing and inserting code into a forum post. Hit preview and was reading though it and I noticed I forgot this line of code, "dira[18] := 1". Man I hate when I do that. Anyone else find themselves thinking they set among the coding gods only to be reminded you are just human and you are not the perfect coder you thought you were? I wish I had back all the time I've lost over the years because I was so sure of myself, code and too proud to look through it with a critical eye. I'm sure I would be at least 100 projects further down the line.

By the way it works fine now.

Tony

PS I know there is a spelling error in the title. Did you notice it?
«1

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-11-15 19:51
    I'm not quite a coding genus.

    I'm just a coding species.

    I've found many errors as I've tried to tiddy up code to post to the forum. I try to remove all the code exept the code I think is causing the problem. I've found once I have the problem code stripped to it fundamentals the error is much easier to find.
  • potatoheadpotatohead Posts: 10,261
    edited 2011-11-15 20:52
    Yes, and I find it helps to just set it aside, either work on another project, or just do something else. A fresh eye on code often reveals something that would have taken hours otherwise. "It can't be that." is deadly, IMHO. (because it just can be)

    Just went through a very similar experience linking a graphics draw COG to a TV signal COG. Image was not complete, draw sequence was not quite right. Of course, I thought, "It can't be the VBLANK flags", because those are easy. Just drop them in at the right place, and go from there.

    The following day, I saw I reversed the order of those flags. Change one PASM instruction and it displays perfectly, despite all the code I wrote to "refine" the drawing loop. Most of that code was a good thing, but not necessary. Gotta hate it when that happens. It took perhaps 3 minutes to see this, once I got everything setup, program file loaded, F10 sending it to the Prop. The wrong order instructions were on the screen from the night before, right there in front of me. Saw the poor draw order and thought, "Wonder if it's the VBLANK?", and it was!



    Couple of hours just cooked over ONE instruction.

    The "#" sign missing off of something is another trouble spot. I don't always see the things (Octothorpes), glossing over them, "Because it's just a JMP."
  • mindrobotsmindrobots Posts: 6,506
    edited 2011-11-15 20:57
    It's not MY fault the keypad pins on the QuickStart are 0-7 and the LEDs are 16-23!! No matter how many 1 bits I stuffed onto pins 8-15, I couldn't get those LEDs lit!!
  • 4x5n4x5n Posts: 745
    edited 2011-11-15 21:08
    Tony B. wrote: »
    I have just spent the last 2 1/2 hours trying to get a new little project working and like so many times before I was sure it was my Demo board or bad wiring NOT MY code. I then spent about twenty minutes writing and inserting code into a forum post. Hit preview and was reading though it and I noticed I forgot this line of code, "dira[18] := 1". Man I hate when I do that. Anyone else find themselves thinking they set among the coding gods only to be reminded you are just human and you are not the perfect coder you thought you were? I wish I had back all the time I've lost over the years because I was so sure of myself, code and too proud to look through it with a critical eye. I'm sure I would be at least 100 projects further down the line.

    By the way it works fine now.

    Tony

    PS I know there is a spelling error in the title. Did you notice it?

    I like making that mistake as well. It normally happens to me when I write an object and decide I need to launch a method into it's own cog for a while. Of course the start method for the object does the initialization which includes setting the direction of the ports and then does the "cognew"! You would think that after all the hours I've spent on it that I would have learned my lesson.
  • RonPRonP Posts: 384
    edited 2011-11-15 22:27
    Not long ago I got out my PEK Labs bread board it's still all set up for the labs. I wanted to use it for some PropGcc stuff I couldn't get it to blink an LED so I started BST and with a simple Public Method I had a blinking LED. Scratching my head now, I got out my GG PP and it worked with same C code I tried with the PEK. Strange, got out the Meter started checking voltage continuity all the way around the bread board found nothing unusual. I shelved the board. The next day I had another look at it you gussed it I had taken out the crystal for another project. I couldn't belive I didn't notice it the day before. :innocent:
  • HollyMinkowskiHollyMinkowski Posts: 1,398
    edited 2011-11-15 22:30
    My code has very few errors.
    Not because I'm some kind of super genius....I'm not bragging.
    I have mild OCD and errors of any sort drive me up the wall.
    So I painstakingly pore over everything a zillion times and test
    my code exhaustively. My code is good.. but I am very tired..LoL :-)
  • Heater.Heater. Posts: 21,230
    edited 2011-11-15 22:34
    "OCD" ?
    Obsessive Coding Disorder?
  • HollyMinkowskiHollyMinkowski Posts: 1,398
    edited 2011-11-15 22:44
    Heater. wrote: »
    Obsessive Coding Disorder?

    LoL! That's good.... and in my case correct :-)

    Not that I have been getting much chance lately to do any coding.
    This is the first day in many weeks that I have had time to even think
    of browsing the web, let alone write some code.

    And I only have till about noon today free... so I must stop reading the forum
    and start answering my backlog of emails. It's fun to come in and see what everyone
    here has been posting about the last two months or so.... I want to comment on
    so many threads but I will not have the time to do so :-(
  • davejamesdavejames Posts: 4,047
    edited 2011-11-15 22:51
    And I only have till about noon today free... so I must stop reading the forum
    and start answering my backlog of emails. It's fun to come in and see what everyone
    here has been posting about the last two months or so.... I want to comment on
    so many threads but I will not have the time to do so :-(

    Thanks for popping in - be safe.
  • HollyMinkowskiHollyMinkowski Posts: 1,398
    edited 2011-11-15 22:57
    Good grief!
    I just got called to be at a conference at 1045
    Now I don't even have till noon :-(
    I need a vacation.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-11-16 00:08
    One of the hardest debugging habits to break is the internal conversation that continuously repeats, "This looks right; it ought to work," when, in fact, it doesn't work. I constantly have to remind myself to replace, "What's right with this code?" with, "This code is broken. Where did I screw up?" Once you can get over that hurdle, debugging becomes a lot more efficient.

    -Phil
  • Heater.Heater. Posts: 21,230
    edited 2011-11-16 00:19
    But Phil, it does not help. I've checked that function a dozen times it MUST be right:)
    For this reason, as others have said, it often pays to take a break or work on something else or get drunk. Long enough that you forget how correct it must be. When you get back the error hits you in the face.
    Peer review is a good idea. As used extensively on critical projects in medical, avionic, military etc software. And the reason "extreme programming" has become popular. And places like this forum of course.
  • Tony B.Tony B. Posts: 356
    edited 2011-11-16 05:40
    When I first started working with micros it was all on a bread board using PICs. What a nightmare for an absolute beginner. I was forever bumping something and disconnecting it, wiring wrong, which I knew I could never do wrong :) and/or frequent coding errors were very common. How I ever learned or why I stayed with it I'll never know. I guess I wasn’t going to let the micros beat me! I did learn though to triple check wiring and bread board setup and every line of code. With the blessing of Demo and Proto boards I've gotten spoiled. It’s time for some humility and going back to the basics.

    Tony

    P.S. Holly I sure hope you get that vacation soon!
  • mindrobotsmindrobots Posts: 6,506
    edited 2011-11-16 07:20
    Heater, for the peer review, should peers share in the drunkenness or comment on your drunkenness....I'd hate to not follow approved code review procedures! :lol:
  • RiJoRiRiJoRi Posts: 157
    edited 2011-11-16 08:26
    "If you want to avoid human errors, don't use humans!"
    Or, "Programming is imperfect people trying to instruct machines in a perfect way."
    Or, "The only people who do not make mistakes are in the graveyard!"

    My coding problem is tunnel vision. Given Bug #102, I will correct Bug #102 as described, but never check variations. E.g., a bug is reported and the alpha keypad was used. I fix it. Do I see if it shows up on the GUI keypad? NO-O-O! Of course not!

    (I guess it means I am still alive! :D )
    --Rich
  • bill190bill190 Posts: 769
    edited 2011-11-16 08:32
    Even worse is when you know there is something wrong with your code, but it is all correct!*

    *Except one missing comma in 2000 lines of code! :swear:
  • JimInCAJimInCA Posts: 80
    edited 2011-11-16 09:07
    I prefer errors in my code as apposed to errors in the hardware. They're a lot easier to fix...
    Jim...
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2011-11-16 11:43
    > For this reason, as others have said, it often pays to take a break or work on something else or get drunk.

    https://www.xkcd.com/323/
  • Spiral_72Spiral_72 Posts: 791
    edited 2011-11-16 13:10
    One time, several years ago, I typed in an entire program.... and it run flawlessly on the first try. <sniff> I miss that day.
  • ajwardajward Posts: 1,130
    edited 2011-11-16 13:24
    Heh... when writing code, my most used outburst is "What do you mean 'NO'???????"
  • ajwardajward Posts: 1,130
    edited 2011-11-16 13:25
    Spiral_72 wrote: »
    One time, several years ago, I typed in an entire program.... and it run flawlessly on the first try. <sniff> I miss that day.

    Of course you bought a lottery ticket that day? ;-)
  • RiJoRiRiJoRi Posts: 157
    edited 2011-11-16 13:38
    Spiral_72 wrote: »
    One time, several years ago, I typed in an entire program.... and it run flawlessly on the first try. <sniff> I miss that day.

    Not only do I remember that day, I remember the code!
    10 FOR N=1 TO 10
    20 PRINT "HI,RICH!"
    30 NEXT N
    40 END
    

    That was on either my TS-1000 or CoCo2. Both were pre-lowercase!

    --Rich
  • mindrobotsmindrobots Posts: 6,506
    edited 2011-11-16 13:46
    : Hello ." Hello world! " ;

    :thumb:
  • photomankcphotomankc Posts: 943
    edited 2011-11-16 17:14
    I'm so far from a coding genius it's funny. I fully expect to wear the flash memory out on one of my development boards before I ever get it working the way I want it. My favorites are the ones where you you take out/add in some seemingly unrelated line of code and suddenly it works and you don't have a clue as to why. I had a semicolon at the end of an if(...) statement. The result was that a command kept executing but the expected data was all zeros. Data got over the wire, data got into the array, but still zeros. Add in a printf() to view the loop while it read the array, now it works! WTH???? Take out the print, no worky. I beat my head for hours, it's got to be something but what and by god that code is right!!!! That semicolon was causing it to execute the command before all the data arrived because it was not waiting for the index to hit the right position. The printf() was adding just enough delay that it was filling in the data from the I2C wire as the loop was running. I was ready to stomp puppies after a few hours chasing that around. I do lots of those kinda deals.

    That and never being able to remember how I adbrivated that variable name to the point I give up and just accept it will never, ever, compile the first time.
  • Spiral_72Spiral_72 Posts: 791
    edited 2011-11-16 17:34
    photomankc wrote: »
    .......I was ready to stomp puppies after a few hours chasing that around.............

    HA! Wow, that's wrong man. I'll have to remember to use that line.


    I remember the program I wrote... was a kind of screen saver written in Quick Basic to bounce 100 balls, circle(x,y),10,1 around on the screen in random directions at random locations. It was written from scratch. I dunno if it's a good thing that I remember that, but I do.

    It was in CGA on a 4.77Mhz XT or a 16?Mhz 286 if that tells you anything :D


    I started programming in assembly a few months after learning QB. I thought I was really something..... squeeze every last bit of speed out of that old processor. The first disk access program I made wrote a test file to my old 10Mb MFM hard disk. I went something like this:

    MASM disktest.asm
    - Compiled with no errors
    disktest.exe
    <beep>
    DIR C:\
    -system not found, please insert command.com in drive A:

    OH #*&^$!! NOOO!
  • lanternfishlanternfish Posts: 366
    edited 2011-11-16 18:23
    And when you promise yourself that you will dutifully and accurately comment your code. And then when your code breaks you sit looking blankly at your monitor wondering what that certain line of code without comments is meant to do ....
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-11-16 18:34
    The first thing I always look for in PASM?
            jmp     :label
    

    Ugh! That almost never works!

    In fact, after typing in a lengthy block of PASM, the first thing I do is a "Find" for JMP, DJNZ, TJZ, and TJNZ to check them all for the "#" symbol.

    -Phil
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-11-16 23:45
    Phil: Try bst - it can report all missing "#"s.
  • Tony B.Tony B. Posts: 356
    edited 2011-11-17 05:19
    If I were a coding genius, I would have never had to start this thread out of frustration!
  • RiJoRiRiJoRi Posts: 157
    edited 2011-11-17 13:18
    photomankc wrote: »
    ... I had a semicolon at the end of an if(...) statement. ...

    That and never being able to remember how I abbreviated that variable name to the point I give up and just accept it will never, ever, compile the first time.

    I wound up writing an AWK program to catch killers like that if(); I also use a macro
    #define donothing ;
    to alert everyone that I really and truly want to do nothing.

    As to variable names, I'm trying to maintain code that has doozies like ENEXCT and ENEXCNT. Then there's always the question of whether or not an underscore is used. And curses upon he who thought putting pages of ASM statements into a C function was cute! Of course, the asmr allows both @^Varble and _Varble to refer to the same variable! Arrrgh!!!!

    (Running off, whimpering)
    --Rich
Sign In or Register to comment.