Author Topic: newbie question: COND limits?  (Read 9379 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: newbie question: COND limits?
« Reply #45 on: November 14, 2010, 09:50:52 AM »
I would add that it's an art, and many programmers don't get it right, and what's "right" is a matter of opinion / taste. My basic stance is that low level routines should rarely, if ever, trap argument type errors, e.g., if a function expects a string and you pass it a real it should do a face plant and cause the calling function to chuck a wobbly, because that's a programming error. I see many programmers applying overly defensive strategies like this, and I think that's a mistake. However, higher level functions / procedures should trap potential errors, e.g. a function that processes csv data should anticipate that one or more fields are null or a data type not expected, because that's a potential execution error.

I acknowledge it can be a matter of taste, this was mine.

Man it's WAY to early for me to be posting. Runs off to find a coffee ...
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: newbie question: COND limits?
« Reply #46 on: November 14, 2010, 01:23:01 PM »
Most defensive programing for me is dealing with what the user might or might not do.
Back when I was doing some work in FoxBase & i thought I had all the options covered
I would let a friend of mine put the program through it's paces.
He could break anything & often did. :evil:
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: newbie question: COND limits?
« Reply #47 on: November 14, 2010, 01:34:39 PM »
`Defensive Programing'? I read that book when it was called "Forethought". The continuation of this discussion aught to be very interesting to say the lest.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CHulse

  • Swamp Rat
  • Posts: 504
Re: newbie question: COND limits?
« Reply #48 on: November 15, 2010, 05:12:38 AM »
...e.g. a function that processes csv data should anticipate that one or more fields are null or a data type not expected, because that's a potential execution error....

Ok, now you really have my attention. (it's 5 am here and I have coffee  :-D)
Any guidence on how I might address a null field? So far, I have just been very careful formatting the input data...
Cary Hulse
Urban Forestry Manager
Wetland Studies and Solutions

Civil 3D 2020 & 2023

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: newbie question: COND limits?
« Reply #49 on: November 15, 2010, 05:48:11 AM »

If unexpected null data, tell the user nicely, then spit the dummy.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: newbie question: COND limits?
« Reply #50 on: November 15, 2010, 08:51:25 AM »
A more ambitious option would be to get input form the user for that data.
Use it this time and or update the data file. You would need to know if this user had permission to update the file.
One more option would be to check the file while loading for incorrect data & deal with it at that time.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.