Click here to Skip to main content
15,886,513 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Unit tests Pin
PIEBALDconsult15-Jan-23 4:16
mvePIEBALDconsult15-Jan-23 4:16 
GeneralRe: Unit tests Pin
Richard Andrew x6415-Jan-23 11:36
professionalRichard Andrew x6415-Jan-23 11:36 
GeneralRe: Unit tests Pin
PIEBALDconsult15-Jan-23 13:37
mvePIEBALDconsult15-Jan-23 13:37 
GeneralRe: Unit tests Pin
englebart15-Jan-23 5:15
professionalenglebart15-Jan-23 5:15 
GeneralRe: Unit tests Pin
PIEBALDconsult15-Jan-23 5:59
mvePIEBALDconsult15-Jan-23 5:59 
GeneralRe: Unit tests Pin
jschell15-Jan-23 8:33
jschell15-Jan-23 8:33 
GeneralRe: Unit tests Pin
Jeremy Falcon15-Jan-23 8:45
professionalJeremy Falcon15-Jan-23 8:45 
GeneralRe: Unit tests Pin
PIEBALDconsult15-Jan-23 10:00
mvePIEBALDconsult15-Jan-23 10:00 
Hmm, well, as to "purity"... not technically, but in the spirit of it.

I could write the function so that it allocates a new local buffer on each call -- then it would be pure.
The issue I have with that is when a large buffer is required many times. I'd rather use a static buffer so that repeated calls (if any) don't have to keep allocating large buffers; they can re-use a buffer which has already been allocated for the largest value so far encountered.

Although my original post involves a scenario in which this function gets called once (or twice, rarely) with small values (short strings), the function might get called millions of times with strings of thousands of characters in the worst-case scenario.

So I have the buffer static. And I clear it upon entering the function (unless I forget to) rather than at the end.
If I clear it at the end, that might be seen as "more pure", in that it leaves the buffer the way it found it.
But I see no point in clearing it before the end of the function; clearing it at the beginning makes more sense to me.
Clearing the buffer takes hardly any effort, so it's not like there is a performance difference in when it gets cleared.

Having said that, in some other situations, clearing a full buffer may require more effort than clearing an empty buffer, so maybe needlessly clearing an empty buffer on the first call is better than needlessly clearing a full buffer on the last. :shrug:

At any rate, I'm not about to change the function just so that it fully qualifies as a pure function; there are bigger fish to fry.
GeneralRe: Unit tests Pin
Jeremy Falcon17-Jan-23 3:46
professionalJeremy Falcon17-Jan-23 3:46 
Generalworldle358 Pin
jmaida14-Jan-23 10:49
jmaida14-Jan-23 10:49 
GeneralQM + AI = oo Pin
BernardIE531714-Jan-23 3:53
BernardIE531714-Jan-23 3:53 
GeneralRe: QM + AI = oo Pin
Mike Hankey14-Jan-23 5:11
mveMike Hankey14-Jan-23 5:11 
GeneralRe: QM + AI = oo Pin
jmaida14-Jan-23 16:59
jmaida14-Jan-23 16:59 
GeneralRe: QM + AI = oo Pin
BillWoodruff16-Jan-23 20:35
professionalBillWoodruff16-Jan-23 20:35 
GeneralRe: QM + AI = oo Pin
BernardIE531716-Jan-23 20:58
BernardIE531716-Jan-23 20:58 
GeneralIs "New Year; New Me" ... Pin
OriginalGriff14-Jan-23 0:24
mveOriginalGriff14-Jan-23 0:24 
GeneralRe: Is "New Year; New Me" ... Pin
theoldfool14-Jan-23 2:04
professionaltheoldfool14-Jan-23 2:04 
GeneralOi Griff ! Pin
pkfox13-Jan-23 23:38
professionalpkfox13-Jan-23 23:38 
GeneralRe: Oi Griff ! Pin
Richard MacCutchan14-Jan-23 0:14
mveRichard MacCutchan14-Jan-23 0:14 
GeneralRe: Oi Griff ! Pin
pkfox14-Jan-23 0:40
professionalpkfox14-Jan-23 0:40 
GeneralRe: Oi Griff ! Pin
Richard MacCutchan14-Jan-23 0:52
mveRichard MacCutchan14-Jan-23 0:52 
GeneralRe: Oi Griff ! Pin
pkfox14-Jan-23 21:49
professionalpkfox14-Jan-23 21:49 
GeneralRe: Oi Griff ! Pin
Richard MacCutchan14-Jan-23 21:56
mveRichard MacCutchan14-Jan-23 21:56 
GeneralRe: Oi Griff ! Pin
pkfox14-Jan-23 23:59
professionalpkfox14-Jan-23 23:59 
GeneralRe: Oi Griff ! Pin
OriginalGriff14-Jan-23 4:07
mveOriginalGriff14-Jan-23 4:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.