Re: CString

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



My customers don't give a hoot in hell who forgot to initialize a variable --- if the software comes from me, it's my problem. From a puritan standpoint with a bottomless pit of time and reliable testers to back you up, it might make sense to "pass the buck" as you describe here. But in the ruthlessly time-constrained world of commercial software of the type I write, I opt to program defensively. I have been doing it successfully for many years.

Ajay Kalra wrote:
I actually fail to see the logic in this. If this was an issue, you
should expect a well tested library to take care of it. You are dealing
with something which has been used by millions of users.

What you are doing is called "Defensive Programming". You dont actually
want to do this in normal unreleased version of the product. If this
was an issue, you want the product to crash so that it can be fixed in
the library. Its not really a performance issue but more of a style
thing. And Defensive Programming is not good for majority of
development cycles.

---
Ajay


r norman wrote:
I have learned that is also best never to make any assumptions about
the state of an object even one exposed through a library that I
created!

There is virtually no place where ensuring the safety of your code by
ensuring that all objects are properly initialized degrades the
execution of your code unless the execution time is already terribly
degraded by improper design.


On Fri, 16 Jun 2006 12:29:10 -0700, "Sgt. York" <york@xxxxxxxxxxxxxx>
wrote:

As a general rule of thumb, I never make any assumptions about the state
of an object when it's created, especially one exposed through a
3rd-party library I have no control over. Maybe this comes from working
in the cross-platform realm all these years. In any case, I would call
Empty(), or set the string explicitly, always, before assuming anything.
An extra function call's worth of performance degradation is worth the
certain knowledge of an object's state.

-York

Tom Serface wrote:
Hi Ajay,

I'm not arguing that point. In this case, Empty() just does nothing if the
string is already empty so if you want to the string to be empty and you
don't know whether or not it is, it's safe to call the function. I agree,
in general, that it makes sense to only call functions that are needed for
performance sake.

Tom

"Ajay Kalra" <ajaykalra@xxxxxxxxx> wrote in message
news:1150462950.449106.158370@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Frankly, I don't think it hurts anything, but it doesn't help either.
It also does not hurt to call some other function which does nothing.
It may not hurt today but it may start hurting some other time because
code underneath you got changed or performance of calling Empty
deteriorates. IMO, if you dont need a function call, dont call it.

---
Ajay



.



Relevant Pages

  • Re: CString
    ... Empty(), or set the string explicitly, always, before assuming anything. ... It also does not hurt to call some other function which does nothing. ... IMO, if you dont need a function call, dont call it. ...
    (microsoft.public.vc.mfc)
  • Re: Read line from TXT file
    ... empty line is read, so it is the wrong approach. ... variable empty because the variable should not participate in the loop test. ... initialize it at all ... because all CStrings are constructed with an empty string. ...
    (microsoft.public.vc.mfc)
  • Re: Beginners question: assigning same value to many variables
    ... Subject: Beginner's question: assigning same value to ... I presume you want each variable initialized to a _different_ empty ... string. ... it's not too hard to initialize a group of instance variables to ...
    (comp.lang.ruby)
  • Re: CString
    ... Empty(), or set the string explicitly, always, before assuming anything. ... It also does not hurt to call some other function which does nothing. ... IMO, if you dont need a function call, dont call it. ...
    (microsoft.public.vc.mfc)
  • Re: CString
    ... As a general rule of thumb, I never make any assumptions about the state of an object when it's created, especially one exposed through a 3rd-party library I have no control over. ... In this case, Empty() just does nothing if the string is already empty so if you want to the string to be empty and you don't know whether or not it is, it's safe to call the function. ... IMO, if you dont need a function call, dont call it. ...
    (microsoft.public.vc.mfc)