Jump to content

David Heffernan

Members
  • Content Count

    3499
  • Joined

  • Last visited

  • Days Won

    174

Posts posted by David Heffernan


  1. I know I go on about this but it's really important, in my view, to stress that the testing framework doesn't discover the bugs. It's the developer that writes good tests that discover the bugs. 

     

    You need a testing framework to help manage the test code. But the strength of the test is always the quality of the test code rather than the framework. There are plenty of libraries that ostensibly have test suites but are full of bugs because the test suites are incomplete.

    • Like 3

  2. 3 hours ago, Rudy Velthuis said:

    Off-topic, but actually, that is multi-posting.

     

    Cross-posting is posting to several newgroups on the same server, with one single post (i.e. the single post has multiple targets and a reply in one group will usually appear in the other groups too, unless the reply was specifically set up not to do that).

    There are no newsgroups here. 


  3. 1 hour ago, Rudy Velthuis said:

    Not much, as this is only one function. And it is more elegant than passing a pointer and type info.

     

    I would then make this function call a private function with the pointer obtained from the parameter and the typeinfo obtained from T.

     

    That way, there will hardly be any bloat. And if this function is not critical, you will never notice a difference.

    That's exactly what I suggested if you read on to the second paragraph. 


  4. 4 hours ago, johnnydp said:

    Sorry I mean that code:

    https://stackoverflow.com/questions/22002120/how-to-get-path-of-current-active-application-window

     

    Thanks. Yes mentioned URLs to stackoverflow contain the same problem asking, but there are many answers and comments I don't know which one is realiable.

    Has anyone had something similar in Delphi which works ?

    That SO topic is the same issue as yours. You might have to do a bit of research starting there. 

     

    What you need to do is find the child process that actually implements the app. Lots of code examples to do that. 


  5. 54 minutes ago, Mahdi Safsafi said:

    I believe that you didn't understand me clearly. My answer wasn't about whether is pointless or not ! my answer was about the coding style (and I gave an example about the Win32 api). 

    Suppose I made a library that have a record like this :

    
    
    type
      TDummy = record
        // ...
      public
        function Create(): TDummy;
        procedure Free();
      end;
    
      { TDummy }
    
    function TDummy.Create: TDummy;
    begin
      // FOR NOW ... do nothing here   !
    end;
    
    procedure TDummy.Free;
    begin
      // on this platform do nothing for now !
      // feature platform do something.
    end;

    Currently Create and Free do nothing on Win32(x86). Yep there is no need to use them. But I use them just for future compatibility.

    Now after 1 year, I decided to port my library to let say WinRT or MIPS. Now my Free must do something here (really)!

    Now, from your approach, you must track all variables and free them if you want your code to run successfully on WinRT, MIPS.

    For me, because I used them on all configurations, I wan't going to track them !

     

    Also, is there any guaranties that "FContextToken" won't change to something else on future ? 

    No point planning for a future you can't see. The real problem was the stupid design in adding Create and Free methods that serve no purpose and confusing so many people. 

     

    Best strategy is to use a singleton for the context. 


  6. 2 hours ago, Uwe Raabe said:

    Make the function a static class function of a record:

    
    type
      TMyPassHandler = record
      public
        class function Pass<T:record>(const Value: T): Boolean; static;
      end;
    
    class function TMyPassHandler.Pass<T>(const Value: T): Boolean;
    begin
      Result := False;
      { do whatever is needed }
    end;
    

    Most of the time the compiler should be able to infer the proper type, so a call would look like:

    
    TMyPassHandler.Pass(myRec);

     

    If the goal is to use RTTI then it seems questionable to use compile time generics. Will result in generic bloat. May as well pass the address of the record and the type info.

     

    Or if you want to ensure type safety have the generic method call a further helper method that is non-generic and receives the address of the record and the type info.  That avoids the bloat and gives benefit of type safety.


  7. 1 hour ago, David Schwartz said:

    Rudy said: I think this order is guaranteed, but I would not really count on it.

    There's a compiler switch that overrides this, so it's not really "guaranteed".

     

    The point about the order was to be sure that the condition was evaluated. Consider the two settings for the switch:

     

    1. Left to right, condition is first sub expression, therefore it is evaluated.

    2. Complete eval, all sub expressions are evaluated, therefore it is evaluated.

     

    QED


  8. 7 hours ago, Rudy Velthuis said:

    Does Python run on a stack machine? Anyway, if they can manage to have proper if conditions too (and they do) then I don't see why they have this alternative syntax.

     

    I looked and saw that CPython emulates a virtual stack machine.

     Nothing to do with implementation details. The Python syntax is simply the Python equivalent of the C conditional operator. You know, the operator that is missing from Delphi. 


  9. 4 hours ago, Lars Fosdal said:

    There is one, but you "wasn't about to download some project from a file sharing site" (i.e. a zip file with source code from Google Drive)

    It's an extra step for every one of your readers. In fact it's multiple steps. Down file. Unzip file. One goal of the writer is to make it easier for the reader to see and understand. 

     

    For instance, if I was on a mobile device how would I read files in a zip file? 

    • Like 3

  10. 12 hours ago, Mike Torrettinni said:

    Yes, no matter what i tried, it didn't compile. Was hoping there is simple solution, missing from help. No luck.

    Seems kind of a waste of time this entire discussion. The language is well documented and is quite concise. The are only a handful of conditional statements. The syntax for if is clear. You have to write the code in the language that is provided to you. Use an if statement. End of story. 

    • Like 1

  11. 1 hour ago, Mike Torrettinni said:

    Is it possible to switch the condition to the end:

     

    from this:

    
    If (condition) Then Result := True;

     

    into something like this:

     

    
    Result := True if (condition);

    Or similar variation, where result is shown first.

    I know that Case works like that, but I need it to work on string values.

     

    When visually looking at the statement, sometimes the Result value has a 'priority' over condition - my personal preference.
     

     

     

    What does the documentation say? 

×