Wednesday, 1 May 2019

Case sensitivity

Found this piece of code in a message (now deleted) on Stack Overflow, for the language Go:

func addGmp(a, b, c, d, e, f, x, y, X, Y, P *big.Int) (*big.Int, *big.Int) {
    // a,b,c,d,e,f this var (fast in func)
    a.Sub(Y, y)
    b.Sub(X, x)

The problem is not only that all the parameters have single-letter names that don't say anything about them, the much bigger problem is that there are parameters named x and y as well as X and Y. This is, IMO even worse than something like (in C):

int SomeApi(HWND hwnd, HDC hdc);

Let me reiterate that I am so happy that Delphi (and Pascal) are case-insensitive, and that such abominable parameter names are not possible.

Wednesday, 27 February 2019

New in Rio: custom PRNG

I don't know if anyone noticed, but there is something new in the System unit of Delphi 10.3 Rio that is not documented yet.

In Rio, if you want to improve the default pseudo random number generator (PRNG), you can now supply your own 32 bit random function. There is a procedural variable, Random32Proc of type function: UInt32, to which you can assign your own random function. Random will call this function to get a new random value instead of the default function.

The default setting of this variable is System.DefaultRandom32. This is the same as the old Delphi PRNG.

Because your new function may need a different way to set the random seed too, there is something similar for Randomize: RandomizeProc.

Here is the corresponding part of System.pas:

{ random functions }

  TRandom32Proc = function: UInt32;
  TRandomizeProc = procedure(NewSeed: UInt64);

function DefaultRandom32: UInt32;
procedure DefaultRandomize(NewSeed: UInt64);

  Random32Proc: TRandom32Proc = DefaultRandom32;
  RandomizeProc: TRandomizeProc = DefaultRandomize;

procedure Randomize;

function Random(const ARange: Integer): Integer; overload;
function Random: Extended; overload;

I tried this with the XorShift implementation in my DelphiBigNumbers GitHub repository and it worked as expected.

Much fun with this!

Saturday, 2 February 2019

Just a short thanks.

I personally still prefer Usenet-like NNTP newsgroups and a newsreader like XanaNews, Forté Agent, Gravity or even Mozilla Thunderbird over any web-based forums.

But since we don't have those anymore, I would like to thank the fine people at They have done an excellent job replacing the various Google+ as well as the old Embarcadero forums. They have created a well balanced set of groups to discuss things pertaining Delphi and C++Builder.

Sure, there is the new Idera Community, the official replacement for the Embarcadero forums, but I think the forums have a, je ne sais quoi, different "feel" to it.

Note that both platforms require you to sign up. I am pretty sure that helps (a little) keeping away the spam and other unwanted input.

If you haven't, go and visit the place. It is a good one. (Also visit the Idera forums, and see which you prefer. I regularly visit both.)

Also recommended: