[solved] ignoring a function result lazarus / 61-Beginners ---------------------------------------------------------------------- speter · 2021-02-19 02:38 I have a simple function, for example:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function foo : boolean;begin  // calc stuff ...  result := true;end;sometimes I want to ignore the function's return value:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if not foo then  writeln('oops');. . .foo;  // here I don't care what the result is...I seem to remember that Laz/FPC is ok with this, but I couldn't find a reference to it. Is it ok to not 'catch' the result!? cheers S. ---------------------------------------------------------------------- Blaazen · 2021-02-19 02:59 It's OK. ---------------------------------------------------------------------- speter · 2021-02-19 08:35 Thanks ---------------------------------------------------------------------- lucamar · 2021-02-19 10:10 Do note that this is true only if "extended syntax" is on (which it is by default); otherwise you'll have to set it either through directives: {$X+} or {$EXTENDEDSYNTAX ON}, or the compiler switch: -Sa1 But, as said, that is uncommon: the normal (default) state is extended syntax set to on and one uses those directives to deactivate it if needed. ---------------------------------------------------------------------- speter · 2021-02-19 10:45 Quote from: lucamar on February 19, 2021, 11:10:17 amDo note that this is true only if "extended syntax" is on (which it is by default); otherwise you'll have to set it either through directives: {$X+} or {$EXTENDEDSYNTAX ON}, or the compiler switch: -Sa1 But, as said, that is uncommon: the normal (default) state is extended syntax set to on and one uses those directives to deactivate it if needed. If someone had "extended syntax" off; would there be a compiler error if a function result was not 'caught'? I am 99% certain that I haven't changed this setting; but someone else might. cheers S. ---------------------------------------------------------------------- dbannon · 2021-02-19 11:14 speter, I really would not worry about it. If 'someone' did change that setting, they would probably break  a whole lot of other things too. While I have not tested it, I am pretty sure it would trigger a compile time error (that is, not a run time one). So, this 'someone' would very quickly spot what they did was wrong.  I have, in my code, lots and lots of cases where a function result is ignored. Its not a great idea if a particular function is always ignored, your code would be (very slightly) more efficient then by using a procedure.  But if you some times need it and sometimes don't, it will be fine. Davo ---------------------------------------------------------------------- Bart · 2021-02-19 11:17 Quote from: speter on February 19, 2021, 11:45:41 amIf someone had "extended syntax" off; would there be a compiler error if a function result was not 'caught'? Yes, it would be a compilation error. Bart ---------------------------------------------------------------------- MarkMLl · 2021-02-19 12:20 Quote from: dbannon on February 19, 2021, 12:14:15 pmI have, in my code, lots and lots of cases where a function result is ignored. Its not a great idea if a particular function is always ignored, your code would be (very slightly) more efficient then by using a procedure.  But if you some times need it and sometimes don't, it will be fine. I wish there were a syntax that controlled this. I use it as well, but it invariably reminds me of the can of worms that is the ALGOL/C/C++ multiple assignment which gets particularly noisome when any sort of implicit type transfers/casts are permitted. MarkMLl ---------------------------------------------------------------------- Zvoni · 2021-02-19 12:39 IMO it's bad practice to ignore a function-result. It's been written as a function to return a result. Period. Ignore it at your own peril. ---------------------------------------------------------------------- Kays · 2021-02-19 13:28 Quote from: Zvoni on February 19, 2021, 01:39:32 pmIMO it's bad practice to ignore a function-result. It's been written as a function to return a result. Period. Ignore it at your own peril. It is bad practice: There is a reason you’re calling a function as a procedure: You want to trigger side-effects. Functions with side-effects are an indicator for bad design (although sometimes it can’t be avoided).Pascal’s spirit discourages the programmer to think about the generated machine code or hardware details. Extending the syntax to address memory issues is bad style. Since 3.0.0 the FPC supports {$optimization deadStore} which will eliminate assignments of function calls’ results to variables. Thus this issue is dealt with on an entirely different level (the processor’s [compiler’s] level), which is way more elegant.NB: {$extendedSyntax off} has some other implications other than calling functions as procedures. ---------------------------------------------------------------------- Bart · 2021-02-19 14:53 Quote from: Kays on February 19, 2021, 02:28:09 pmIt is bad practice: From the old days: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure ClrKbd;begin  while KeyPressed do ReadKey;end; Without Extende syntax you would have to do: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure ClrKbd;var  Ch: Char;begin  while KeyPressed do Ch := ReadKey;end; Is that really better? And now you get a compiler warning, which you have to suppress. In both cases you can argue that clearing the keyboard buffer (the goal of that procedure) is a side effect of ReadKey. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ...  CloseFile(AFile);  //ignore IO errors here since we're exiting the program now.  IOresult;  writeln('Bye');end. That's just bad practice, since there is a better alternative which does directly what you want to achieve and what IOResult does as a side effect. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ...  CloseFile(AFile);  //ignore IO errors here since we're exiting the program now.  InOutRes := 0;  writeln('Bye');end. Bart ---------------------------------------------------------------------- Kays · 2021-02-19 20:05 Quote from: Bart on February 19, 2021, 03:53:20 pmQuote from: Kays on February 19, 2021, 02:28:09 pmIt is bad practice: From the old days: I wrote “is”, not “was”. Quote from: Bart on February 19, 2021, 03:53:20 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure ClrKbd;begin  while KeyPressed do ReadKey;end;This only proves my point of bad design: Apparently there is a demand for this kind of functionality, the clrKbd procedure, but the CRT unit doesn’t provide it. This is a design flaw, you know. Repeated keyboard buffer reads without actually using the values is just bad. The ncurses library provides flushinp for this, and every OS provides some means to seek the EOF of an input stream without reading anything. That’s just far more efficient and better design. I know that you know that, Bart, but you gotta name a better example why allowing to call functions as if they were procedures is generally useful, globally (per module) [{$extendedSyntax} is a global compiler directive]. Quote from: Bart on February 19, 2021, 03:53:20 pm[…] Without Extende syntax you would have to do: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure ClrKbd;var  Ch: Char;begin  while KeyPressed do Ch := ReadKey;end; Is that really better? And now you get a compiler warning, which you have to suppress.I get a mere note. Notes are nice and do not hurt. I have {$extendedSyntax off} and as consequence do write wrapper procedures for a handpicked set of functions, where I know discarding the result does not have any negative consequences: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$push}{$warn 5027 off}procedure discardKey; inline;var        c: char;begin        c := readKey();end;{$pop}But I do this consciously, that’s the point. Generally allowing functions being called as procedures may produce inadvertent programming mistakes. I’d rather really rely on the compiler optimizations than producing, IMO “dirty” code, trying to outsmart the compiler. ---------------------------------------------------------------------- MarkMLl · 2021-02-19 20:59 Quote from: Kays on February 19, 2021, 09:05:45 pmBut I do this consciously, that’s the point. Generally allowing functions being called as procedures may produce inadvertent programming mistakes. I agree that that's the important thing. FWIW, some scripting stuff that I wrote/use suppresses an expression result if it is parenthesised, i.e. like Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure ClrKbd;begin  while KeyPressed do    (ReadKey)end;  I'm not sure whether there are cases where an lvalue can (or at least needs to) start with a parenthesis, but so far I've gotten away with it. MarkMLl ---------------------------------------------------------------------- Bart · 2021-02-19 22:10 Quote from: Kays on February 19, 2021, 09:05:45 pmI know that you know that, Bart, but you gotta name a better example why allowing to call functions as if they were procedures is generally useful [snip] I don't say it is generally usefull. I'm just stating that the functionality of ClrKbd can be achieved by disregarding the function result of ReadKey, and the example using a variable that you don't use at all is just cluttering the code (and needs an additional compiler directive (or 2)) and IMO does not make for better code. In general functions have a result for a reason, so throwing it away should be the exception to the rule. If you use it cautiously it's ok IMO. Bart ---------------------------------------------------------------------- dbannon · 2021-02-19 23:46 Maybe, for the benefit if the OP, we should keep this in reasonable space. He asked if bad things would happen. The answer is, I believe, no.  We often use a function in slightly different ways, sometimes its return value is important and sometimes its not.  Doing - Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function MyFunction : boolean;begin    ....    result := true;end; procedure MyProcedure;var    Junk : boolean;begin    Junk := MyFunction;end; Is NOT good design, it has introduced a new method and a new variable that might get optimized out to some degree but we have also extra code, two different method names to remember and and a warning about an unused variable. And, honestly, anyone looking at it would have every reason to wonder why ?  (I am sure it can be done more elegantly than this but why complicate things ?) I would certainly change my mind if someone can demonstrate the bad thing that does happen if we ignore a function result. But I reckon the compiler is well aware we don't always use a function result and acts accordingly. One or two wasted ops, thats all. David ---------------------------------------------------------------------- egsuh · 2021-02-20 01:02 The point is not assignment issue. This issue is rediculous. Would you not write            if  function1 (function2 (function3(aparam))) then ... The issue is returned value is "NOT" used in any part of the program. I have a function that inserts several records into a database table, and an auto-incremental id field value is returned. Sometimes I need to check the last id, sometimes do not have to. In this case, the answer is clear enough. I do not have to write two almost-identical subroutines, one function and one procedure. The issue is, would you declare any subroutine as function, whose result is never used? Well, for me declaring as procedure is more comfortable.  But as soon as I need some return value from it, I'll change it to function. Adding an out parameter to the procedure makes it much complicated. ---------------------------------------------------------------------- Bart · 2021-02-20 07:57 Quote from: Kays on February 19, 2021, 09:05:45 pmI know that you know that, Bart, but you gotta name a better example Well, maybe not a better example, but TStrings/TStringList.Add() is a function. I bet you that hardly ever anybody bothers to check the function result as it is generally NOT needed. I guess you would consider this a design flaw in TStrings/TStringList. Bart ---------------------------------------------------------------------- Sieben · 2021-02-20 08:49 Quote from: Bart on February 20, 2021, 08:57:45 amWell, maybe not a better example, but TStrings/TStringList.Add() is a function. I bet you that hardly ever anybody bothers to check the function result as it is generally NOT needed. It relies heavily on being a function internally, however. ---------------------------------------------------------------------- MarkMLl · 2021-02-20 08:55 Quote from: egsuh on February 20, 2021, 02:02:53 amThe issue is, would you declare any subroutine as function, whose result is never used? Well, for me declaring as procedure is more comfortable.  But as soon as I need some return value from it, I'll change it to function. Adding an out parameter to the procedure makes it much complicated. The bigger issue is that you can't polymorphosise (?!!!) a function based on its return type. So even in cases where such a thing might be desirable you can't have both a procedure and a function implementing (say) TStringList.Add()... and that's a fundamental language limitation that isn't going to change. If you /could/ to that, then where a result definitely needed to be checked you'd quite simply not define the procedural form which would oblige the programmer to do something with the result. MarkMLl ---------------------------------------------------------------------- Kays · 2021-02-20 12:37 Quote from: Bart on February 19, 2021, 11:10:31 pmI don't say it is generally usefull. […] In general functions have a result for a reason, so throwing it away should be the exception to the rule. If you use it cautiously it's ok IMO. Uh, OK. That seems fair. Quote from: dbannon on February 20, 2021, 12:46:09 am[…]Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function MyFunction : boolean;begin    ....    result := true;end; procedure MyProcedure;var    Junk : boolean;begin    Junk := MyFunction;end; Is NOT good design, it has introduced a new method and a new variable […]Well, if you are programming both the function and procedure, you could achieve the same with just one extra declaration: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function myFunction: Boolean; public name 'my_function';begin        // ...      result := true;end; // results of these functions can be safely ignored:procedure doMyFunction; external name 'my_function';// ... more procedure declarationsBut, as you see, I document it, I do this intentionally, for a carefully selected subset of functions. ---------------------------------------------------------------------- MarkMLl · 2021-02-20 12:42 Quote from: Kays on February 20, 2021, 01:37:00 pmWell, if you are programming both the function and procedure, you could achieve the same with just one extra declaration: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function myFunction: Boolean; public name 'my_function';begin        // ...      result := true;end; // results of these functions can be safely ignored:procedure doMyFunction; external name 'my_function';// ... more procedure declarationsBut, as you see, I document it, I do this intentionally, for a carefully selected subset of functions. Interesting. Does that /have/ to be in a separate unit? MarkMLl ---------------------------------------------------------------------- winni · 2021-02-20 13:11 Hi! If I need a "swiss knife" function, that I can use as procedure AND function I do it this way: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Function incF (var s : single) : single;begins := s +1;result := s;end;  So I can use it both ways depending on the situation: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var x, s : single;....x := x +incF(s);  or Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i incF(s);x := x + s;  Winni ---------------------------------------------------------------------- dseligo · 2021-02-20 17:34 Quote from: Bart on February 20, 2021, 08:57:45 amQuote from: Kays on February 19, 2021, 09:05:45 pmI know that you know that, Bart, but you gotta name a better example Well, maybe not a better example, but TStrings/TStringList.Add() is a function. I bet you that hardly ever anybody bothers to check the function result as it is generally NOT needed. I guess you would consider this a design flaw in TStrings/TStringList. Well, you have TStrings.Append if don't need index: https://www.freepascal.org/docs-html/rtl/classes/tstrings.append.html ---------------------------------------------------------------------- Sieben · 2021-02-20 18:16 QuoteWell, you have TStrings.Append if don't need index Guess how it's implemented... ---------------------------------------------------------------------- Kays · 2021-02-20 18:39 FYI, the GPC is still my favorite Pascal compiler: It has a discard(…) intrinsic. Alternatively, you can specify attribute (ignorable); after a function declaration. Otherwise, without ‑‑ignore‑function‑results, an error is generated (equivalent to FPC’s {$extendedSyntax off}). Quote from: MarkMLl on February 20, 2021, 01:42:41 pm[…] Does that /have/ to be in a separate unit? […]External does not mean it’s in a separate unit. Both declarations are in the same file. And actually they have to be in the same unit, otherwise it doesn’t work transparently. If they were in separate units, you would need to specify the FQI for either routine, because the order units are listed in the uses clause matters. If you did not mean by the word “unit” UCSD Pascal units, but two separate declarations: Yes, the FPC requires one declaration starting with the word procedure. AFAIK there’s no shortcut. The GPC on the other hand, as mentioned above, would be satisfied by appending …; attribute (ignorable); to the function header. Neat. ---------------------------------------------------------------------- dseligo · 2021-02-20 18:42 Quote from: Sieben on February 20, 2021, 07:16:14 pmQuoteWell, you have TStrings.Append if don't need index Guess how it's implemented...  But then can change ---------------------------------------------------------------------- Bart · 2021-02-20 20:43 Quote from: Sieben on February 20, 2021, 09:49:07 amQuote from: Bart on February 20, 2021, 08:57:45 amWell, maybe not a better example, but TStrings/TStringList.Add() is a function. I bet you that hardly ever anybody bothers to check the function result as it is generally NOT needed. It relies heavily on being a function internally, however. That's not the point in this discussion. It has been stated that something like Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   StringList.Add('Something');is bad programming. You are supposed to do it like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   Index := StringList.Add('Something');and then suppress the note about Index not being used, and use yet another modeswitch so that the compiler eliminates Index alltogether. Bart ---------------------------------------------------------------------- Sieben · 2021-02-20 22:53 You said about TStrings.Add() that the result is 'generally NOT needed'. Apart from that I admit that my statement was a bit ambigious but in the end it was meant to second the notion that sometimes it makes sense to implement a routine as a function - because in certain situations the result IS needed - and on the other hand it's perfectly ok to use it like a procedure when it is NOT needed. I don't see the point in introducing sth like TStrings.Append or a second procedure using a dummy var just to hide it from the eye. In the end it might just blow up code and make it harder to maintain. It is of course allways a good idea to consider carefully if a routine should be implemented as a function or a procedure. But if it's 'and' instead of 'or' a function will suffice. ---------------------------------------------------------------------- lucamar · 2021-02-20 23:04 Of course, doing the "devil's advocate" thing one might contend that TStrings.Add doesn't need to return the index, since it's already known (TStrings.Count), so making it a function is pointless. But then, as a function returning the index if you need it allows you to avoid further accesses to get it through Count. As can be seen, extrapolating from the examples, it's all a question of point of view. Is it convenient to be able to disregard a function's result if one just needs its side-effects? If yes, then doing it can't be bad programming provided one is even remotely aware of what he's doing. And don't say that those "side-effects" are bad; in lots, if not most, cases the "side-effects" are really the main operation (as with TStrings.Add), while returning some value in case it's needed is just "icing on the cake" As with most not-so-obvious features of any language, it's there for a reason and it's the programmer's responsibility to know and acknowledge when and why it's used. IMHO, of course ---------------------------------------------------------------------- dbannon · 2021-02-21 04:04 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function myFunction: Boolean; public name 'my_function';begin        // ...      result := true;end; // results of these functions can be safely ignored:procedure doMyFunction; external name 'my_function';// ... more procedure declarations But, the OP question was, "would bad things happen, at either compile or run time ?"  The above approach still leaves a function's result being ignored. If something bad is going to happen just ignoring a function result, the same something is going to happen with a call to doMyFunction. If we are talking about a purely style or theoretical thing here,  there is another fairly widely used programming language where every method returns something, possibly only 'void'.  And it seem to be doing OK .... :-) Davo ---------------------------------------------------------------------- PascalDragon · 2021-02-21 15:30 Quote from: Kays on February 20, 2021, 07:39:52 pmQuote from: MarkMLl on February 20, 2021, 01:42:41 pm[…] Does that /have/ to be in a separate unit? […]External does not mean it’s in a separate unit. Both declarations are in the same file. And actually they have to be in the same unit, otherwise it doesn’t work transparently. If they were in separate units, you would need to specify the FQI for either routine, because the order units are listed in the uses clause matters. You're wrong. By declaring it as public name 'my_function' you're declaring a non mangled assembly symbol that is useable across units. In fact if you use public name 'my_function' from multiple units you'll in fact get a "duplicate symbol" error. Thus you can import in from any unit as external name 'my_function' and even from e.g. statically linked C code. A general note for this "functionality": don't use this with managed types or records as the former need to be finalized by the compiler to avoid memory leaks and the later will likely be passed as a hidden parameter thus leading to different ABIs for the procedure and the function. To answer the question of the OP: yes, in general it is safe to ignore results, at least if you're dealing with simple or managed types (this also includes records). What you need to pay attention of are allocations inside the functions (e.g. if the function does a TSomeClass.Create or GetMem), cause then you need to free it yourself to avoid memory leaks. ---------------------------------------------------------------------- MarkMLl · 2021-02-21 18:17 Quote from: PascalDragon on February 21, 2021, 04:30:45 pmWhat you need to pay attention of are allocations inside the functions (e.g. if the function does a TSomeClass.Create or GetMem), cause then you need to free it yourself to avoid memory leaks. Presumably you're referring to result := TSomeClass.Create etc. here. Don;t know about anybody else but I always explicitly note in a function's comment if it returns something that needs to be freed by the caller... if a programmer ignores that then it's his problem (and job). MarkMLl ---------------------------------------------------------------------- PascalDragon · 2021-02-22 08:42 Quote from: MarkMLl on February 21, 2021, 07:17:11 pmQuote from: PascalDragon on February 21, 2021, 04:30:45 pmWhat you need to pay attention of are allocations inside the functions (e.g. if the function does a TSomeClass.Create or GetMem), cause then you need to free it yourself to avoid memory leaks. Presumably you're referring to result := TSomeClass.Create etc. here. Don;t know about anybody else but I always explicitly note in a function's comment if it returns something that needs to be freed by the caller... if a programmer ignores that then it's his problem (and job). That is indeed the best one can do in that case. ---------------------------------------------------------------------- Zvoni · 2021-02-22 09:09 Quote from: lucamar on February 21, 2021, 12:04:35 amOf course, doing the "devil's advocate" thing one might contend that TStrings.Add doesn't need to return the index, since it's already known (TStrings.Count), so making it a function is pointless. But then, as a function returning the index if you need it allows you to avoid further accesses to get it through Count. Errr??? IIRC, what's the Index of an added Item, if TStrings/TStringList is sorted? ---------------------------------------------------------------------- Zoran · 2021-02-22 11:10 Quote from: Zvoni on February 22, 2021, 10:09:16 amQuote from: lucamar on February 21, 2021, 12:04:35 amOf course, doing the "devil's advocate" thing one might contend that TStrings.Add doesn't need to return the index, since it's already known (TStrings.Count), so making it a function is pointless. But then, as a function returning the index if you need it allows you to avoid further accesses to get it through Count. Errr??? IIRC, what's the Index of an added Item, if TStrings/TStringList is sorted? What do you find confusing there? In sorted list, the newly added item will get its position in sort, and the function will return the index; in the next line of code, you can access this element by index. The returned index is even more useful in sorted list, as it is not simply Count - 1. ---------------------------------------------------------------------- Sieben · 2021-02-22 11:15 'Thread of Confusion' - I think this is exactly what Zvoni wanted to point at...  BTW - Zoran, did you see this...? ---------------------------------------------------------------------- Zvoni · 2021-02-22 11:52 Quote from: Zoran on February 22, 2021, 12:10:13 pmQuote from: Zvoni on February 22, 2021, 10:09:16 amQuote from: lucamar on February 21, 2021, 12:04:35 amOf course, doing the "devil's advocate" thing one might contend that TStrings.Add doesn't need to return the index, since it's already known (TStrings.Count), so making it a function is pointless. But then, as a function returning the index if you need it allows you to avoid further accesses to get it through Count. Errr??? IIRC, what's the Index of an added Item, if TStrings/TStringList is sorted? What do you find confusing there? In sorted list, the newly added item will get its position in sort, and the function will return the index; in the next line of code, you can access this element by index. The returned index is even more useful in sorted list, as it is not simply Count - 1. Zoran, exactly my point. I was pointing to the statement, that Add doesn't need to return the index, since you have it with Count, which doesn't work with sorted TStrings/TStringList ---------------------------------------------------------------------- lucamar · 2021-02-22 13:06 Quote from: Zvoni on February 22, 2021, 12:52:59 pmI was pointing to the statement, that Add doesn't need to return the index, since you have it with Count, which doesn't work with sorted TStrings/TStringList You're right, of course, and it's probably the reason (one of them) why Add returns the index. ---------------------------------------------------------------------- ASBzone · 2021-02-22 16:02 Quote from: speter on February 19, 2021, 03:38:31 am... sometimes I want to ignore the function's return value: ... Is it ok to not 'catch' the result!? cheers S. The short answer is, "yes, but there are a few caveats". The longer answer is covered adequately in the thread. Indiscriminate use of any such technique could lead to potential problems, but using this methodology sparingly is unlikely to cause significant problems.  NOTE: @PascalDragon did point out a significant issue to consider, however. ---------------------------------------------------------------------- speter · 2021-02-22 23:19 Thanks to everyone to a most interesting discussion. cheers S. ---------------------------------------------------------------------- Zoran · 2021-02-24 09:17 Quote from: Zvoni on February 22, 2021, 12:52:59 pmZoran, exactly my point. I was pointing to the statement, that Add doesn't need to return the index, since you have it with Count, which doesn't work with sorted TStrings/TStringList I see, yes, sorry. ---------------------------------------------------------------------- Zoran · 2021-02-24 09:21 Quote from: Sieben on February 22, 2021, 12:15:16 pmBTW - Zoran, did you see this...? Yes, I added OnShowHint to (DB)DateTimePicker. I'll see about other events. I don't think that this needs backporting to fixes, though.