The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,262 other subscribers

Archive for April 8th, 2021

UUID/GUID as primary keys in databases; generating them from a .NET assembly

Posted by jpluimers on 2021/04/08

Some links for my archive:

–jeroen

Posted in .NET, Database Development, Development, PostgreSQL, Software Development, SQL Server | Leave a Comment »

Tidy First?

Posted by jpluimers on 2021/04/08

Reminder to myself to check out of the Tidy First? book by Kent Beck got out yet.

I discovered he was writing it after reading this tweet:

Like Extreme Programming, which I used before I even know about the term, Tidy First is my natural way of approaching code: step by step tidying small spots, so I get a feel on the why and how of the code. For me, tidying consists of very small refactorings. I am anxious to see what it means for Kent.

Related links:

–jeroen

Read the rest of this entry »

Posted in Uncategorized | Leave a Comment »

Delphi TestInsight: when supporting it, test if it is running at all. Same library has a deferer pattern.

Posted by jpluimers on 2021/04/08

Interesting idea by Cesar Romero (who has some interesting repositories at [WayBack] cesarliws (Cesar Romero) · GitHub and [WayBack] cesarliws — Bitbucket) when using TestInsight for Delphi: first test if TestInsight is running at all: [WayBack] foundation-4-delphi/Foundation.Test.Utils.pas at master · cesarliws/foundation-4-delphi · GitHub.

function IsTestInsightRunning: Boolean;
{$IFDEF TESTINSIGHT}
var
  TestInsightClient: ITestInsightClient;
begin
  TestInsightClient := TTestInsightRestClient.Create;
  TestInsightClient.StartedTesting(0);
  Result := not TestInsightClient.HasError;
end;
{$ELSE}
begin
  Result := False;
end;
{$ENDIF}

procedure RunRegisteredTests;
begin
  ReportMemoryLeaksOnShutdown := True;

{$IFDEF TESTINSIGHT}
  if IsTestInsightRunning then
    TestInsight.DUnit.RunRegisteredTests
  else
{$ENDIF}
    DUnitTestRunner.RunRegisteredTests;
end;

Another interesting bit from the same library is the deferer pattern (which is different from the promise pattern!)  in [WayBack] foundation-4-delphi/Foundation.System.pas at master · cesarliws/foundation-4-delphi · GitHub with the below code examples.

I think a better name might be DeferExecutionToEndOfScopeFor.

procedure ProcessFile (const FileName: string);
var
  File: TFile;
begin
  File: = TFile.Open (FileName);
  Defer (File.Close);
  while not File.EOF
  begin
    // ... process file
  end;
end; // Defer will be executed here [File.Close]

procedure ExecSql (const ConnectionString, Sql: string);
var
  Database: TDatabase;
  Exec: IDeferred;
  Query: TQuery;
begin
  Database: = TDatabase.Create (ConnectionString);
  Exec: = Defer (Database.Free);
  Database.Open;
  Exec.Defer (Database.Close);

  Query: = Database.Query (SQL);
  Exec.Defer (Query.Free);
  Exec.Defer (Query.Close);
  if Query.IsEmpty then
   Exit;

  while not Query.EOF
  begin
    // ... process query
  end;

  Exec.Defer (
    procedure
    begin
      Writeln ('Finished ExecSql');
    end
  );
end; // Defer will be executed here [Writeln, Query.Close, Database.Close, Database.Free]

–jeroen

Posted in Delphi, Development, Software Development, Spring4D, TestInsight | Leave a Comment »