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 1,854 other subscribers

Archive for the ‘Software Development’ Category

Detecting what language or script a run of text is written in, redux – The Old New Thing

Posted by jpluimers on 2021/01/29

Interesting: [WayBack] Detecting what language or script a run of text is written in, redux – The Old New Thing.

Do not confuse language with the scripts in which one or more languages can be written, and much more is covered in it.

Related:

–jeroen

Posted in Development, Software Development, The Old New Thing, Windows Development | Leave a Comment »

Nick Craver on Twitter: “1. “Are you ready to work on the auth code?” 2. New dev: “Hell yeah, bring it on!” 3.… “

Posted by jpluimers on 2021/01/28

[WayBack] Nick Craver on Twitter: “1. “Are you ready to work on the auth code?” 2. New dev: “Hell yeah, bring it on!” 3.… “.

Relevant because security often is a nightmare:

 

Both threads are a good read.

–jeroen

Read the rest of this entry »

Posted in .NET, Android, Development, Fun, Mobile Development, Software Development, Xamarin Studio | Leave a Comment »

Deciphering the Messages of Apple’s T2 Coprocessor | Duo Security

Posted by jpluimers on 2021/01/28

Interesting read: [WayBack] Deciphering the Messages of Apple’s T2 Coprocessor | Duo Security.

Via:

–jeroen

Posted in Development, Security, Software Development | Leave a Comment »

Delphi: getting the name of the current unit

Posted by jpluimers on 2021/01/28

If you have a class (like TMyClass) in the current unit, you can get the unit name as follows:

  • inside a method of the class (either instance or class method): call UnitName or UnitScope to get the unit name
  • outside a method of the class: call TMyClass.UnitName or TMyClass.UnitScope

Delphi added UnitName [WayBack] and  Delphi XE2 added UnitScope [Archive.is]. Their implementations are different, but I have not seen classes where the outcome is different.

The code below shows that when the underlying RTTI UnitName field inside a PTypeData referred by a PTypeInfo contains an @ sign, then UnitName takes the part before the @, and UnitScope the part after the @, but I have not yet seen units where the underlying field contains an @ sign.

If you have seen that, please let me know.

I needed this in order to research some unit initialisation order issues.

A post helpful with that was [WayBack] windows – Can I determine the order in which my units have been initialized? – Stack Overflow for which this comment by Ritsaert Hornstra is the most important bit:

Related: If you use a unit in the interface section you know that that unit will be initialized BEFORE the unit that uses that unit. When using units in the implementation section this is not the case. So usually when you are using a unit with a singleton in it, created in it’s initialization section, you should use that unit in the interface section to make sure that it is initialized before use.

There is also an answer [WayBack] by Remko Weijnen that shows how to hack the current initialisation order if you know the address of InitContext inside the System.InitUnits method.

Back to UnitName versus UnitScope, the code:

class function TObject.UnitName: string;
var
  LClassInfo: Pointer;
  S: _PShortStr;
begin
  LClassInfo := ClassInfo;
  if LClassInfo <> nil then
  begin
    S := @PClassData(PByte(LClassInfo) + 2 + PByte(PByte(LClassInfo) + 1)^).UnitName;
    if S^[1] <> '@' then
      Result := UTF8ToString(S^)
    else
      Result := UTF8ToString(Copy(S^, Pos(_ShortStr(':'), S^) + 1, MaxInt));
  end else
    Result := '';
end;

class function TObject.UnitScope: string;
var
  LClassInfo: Pointer;
  S: _PShortStr;
begin
  LClassInfo := ClassInfo;
  if LClassInfo <> nil then
  begin
    S := @PClassData(PByte(LClassInfo) + 2 + PByte(PByte(LClassInfo) + 1)^).UnitName;
    if S^[1] <> '@' then
      Result := UTF8ToString(S^)
    else
      Result := UTF8ToString(Copy(S^, 2, Pos(_ShortStr(':'), S^) - 2));
  end else
    Result := '';
end;

Related:

–jeroen

Posted in Delphi, Development, Software Development | 1 Comment »

NDC 2019 Keynote: Welcome to the Machine – Hadi Hariri – YouTube

Posted by jpluimers on 2021/01/27

I am really glad this keynote got recorded. Still very relevant, it is as much about software development as it is about society.

Go watch it, as it gives you reason to think about your role in the software development process, and in the information fire hose at large.

Back in the days, David Intersimone was right when he created the regular blog post “Sip from the Firehose” (for early materials, see [WayBack] GetPublished – Author Information: Firehose).

The talk main thread is about current and ever growing overload of information which basically makes it disinformation, combined with the abundance of “AI” recording devices around you that basically make you the product.

Basically we reached all the tick marks of these books:

The session is not just about “how bad is the situation” (it is very), but also provides directions on how to get out of it for both people in the development process, as well as consumers, producers and sharers of information.

via:

–jeroen

Read the rest of this entry »

Posted in .NET, Development, Opinions, Power User, Security, Software Development | Leave a Comment »

Few remember the ancestry of programming languages

Posted by jpluimers on 2021/01/27

A while ago, I saw this tweet:

It mentions LISP (nowadays mostly called Lisp), likely because their derivatives like Scheme and Clojure still actively mention their ancestry.

ALGOL is not in the list, but has had so much influence on modern programming. So here the thread that followed:

–jeroen

Read the rest of this entry »

Posted in ALGOL, Delphi, Development, LISP, Software Development | Leave a Comment »

On my research list: Delphi “Package Cache” subtree

Posted by jpluimers on 2021/01/27

On one of the sites, when having some Delphi package registration issues, the standard measure was to delete the complete Package Cache subtree (like HKEY_CURRENT_USER\Software\Embarcadero\BDS\17.0\Package Cache).

Since there is so little information about it, it is on my list of things to eventually research.

Some links I already found, but had no time for to fully read:

Unrelated: You should not delete the folder C:\ProgramData\Package Cache\? – Super User, but matched my initial delphi registry “Package Cache” – Google Search.

Yup, I did it: I added an “Undocumented Delphi” category.

–jeroen

Posted in Delphi, Development, Software Development, Undocumented Delphi | Leave a Comment »

Run your unit tests in parallel with NUnit

Posted by jpluimers on 2021/01/26

TL;DR

The examples in this post are specific for NUnit but, you can apply this pattern for safely running unit tests in parallel to any unit test framework that supports parallel execution.

To safely run tests in parallel, do the following:

  1. Mark your test fixtures with the Parallelizable attribute and set the parallel scope to ParallelScope.All.
  2. Create a private class called TestScope and implement IDisposable.
  3. Put all startup and clean-up logic inside the TestScope constructor and .Dispose() method respectively.
  4. Wrap your test code in a using (var scope = new TestScope) { ... } block

From [WayBack] Run your unit tests in parallel with NUnit, which also covers:

  • Background (on why you might want this)
  • How to safely run tests in parallel
  • Maximizing parallel execution with Visual Studio
  • Maximizing parallel execution with Azure DevOps

Via: [WayBack] Sander Aernouts on Twitter: “Run unit tests in parallel with NUnit without having one test interfere with another test. https://t.co/FC0fNocGov”

–jeroen

Posted in .NET, Development, Software Development | Leave a Comment »

datetime – Determine Whether Two Date Ranges Overlap – Stack Overflow

Posted by jpluimers on 2021/01/26

[WayBack] datetime – Determine Whether Two Date Ranges Overlap – Stack Overflow answer by Charles Bretana with input from Baodad and tomosius.

TL;DR (proof is in the post)

(StartA <= EndB) and (EndA >= StartB)

Alternative (also from the post):

DateRangesOverlap = max(StartA,StartB) < min(EndA,EndB)

It gets complicated when the date boundaries for A and B can be out of order.

The post also covers that.

Related:

–jeroen

Posted in Development, Software Development | Leave a Comment »

Delphi debugging tip: keep an eye on a object field of an object that will go out of scope eventually

Posted by jpluimers on 2021/01/26

Every once in a while you want to have a Delphi Watch of a field inside an object (say an object of type TContext), except that the field has no value yet, but eventually will point to another object (say an object of type TUser).

However, the original object will go out of scope, so you need to employ a few tricks.

First of all, you get the address of that field:

@(Context().FCurrentUser) = $7EF6F624

Then you watch the content of that field:

TUser(PPointer($7EF6F624)^),r = nil

To get to this trick, you have to remember:

  1. The contents of address $7EF6F624 is pointer (at first nil) to a TUser.
  2. You get to the contents of the address $7EF6F624 by using PPointer($7EF6F624)^.
  3. Then you cast it to the object you want with the TUser(...) cast.

–jeroen

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