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 2,099 other followers

Archive for September, 2020

From Delphi 1: Type Compatibility and Identity

Posted by jpluimers on 2020/09/30

A feature overlooked by many Delphi programmer was already introduced in Delphi 1 which is more or less the same as in the Delphi 2007 documentation at [WayBack] Type Compatibility and Identity.

There is a distinction between these explained in the above link:

type
  TMyInteger1 = Integer;
  TMyInteger2 = type Integer;

Where TMyInteger1 is an alias for Integer, TMyInteger2 introduces a new type which is distinct from Integer and TMyInteger. That way the compiler can set them apart, and even generates separate RTTI (Run-Time TypeInformation) for them.

Probably the most used distinct types are these:

TDateTime = type Double;
...
TDate = type TDateTime;
TTime = type TDateTime;
TFontName = type string

These are unlike TColor which is defined as “just” a subrange of Integer, but because it is a subtype, also gets a distinct type:

TColor = -$7FFFFFFF-1..$7FFFFFFF;

Type identity is important because Delphi 1 introduced these mechanisms:

  • the streaming instances and their properties
  • editing instances and properties in the object inspector
  • two way binding of designer (form/datamodule/frame/…) and the underlying Pascal source

Without them, very basic Delphi features would not work.

In addition, a lot of other RTTI based code now enables features like object relational mapping, binding to JSON/XML and many others.

What I did not know is that the Pascal and Delphi type systems have been heavily influenced by ADA. Luckily Lutz Donnerhacke pointed me to ADA [WayBack] Types and Subtypes.

Example

I made an example Distinct type types in Delphi · GitHub showing the differences on RTTI level in these properties:

property IntegerProperty: Integer read FIntegerField write FIntegerField;
property ColorProperty: TColor read FColorField write FColorField;
property DoubleProperty: Double read FDoubleField write FDoubleField;
property DateTimeProperty: TDateTime read FDateTimeField write FDateTimeField;
property DateProperty: TDate read FDateField write FDateField;
property TimeProperty: TTime read FTimeField write FTimeField;
property StringProperty: string read FStringField write FStringField;
property FontNameProperty: TFontName read FFontNameField write FFontNameField;

The generated table (see also the source below using [Archive.is] TRttiContext added in Delphi 2010) indeed shows distinct types on the RTTI level:

Name Type.Name Type.QualifiedName Type.TypeKind
IntegerProperty Integer System.Integer tkInteger
ColorProperty TColor System.UITypes.TColor tkInteger
DoubleProperty Double System.Double tkFloat
DateTimeProperty TDateTime System.TDateTime tkFloat
DateProperty TDate System.TDate tkFloat
TimeProperty TTime System.TTime tkFloat
StringProperty string System.string tkUString
FontNameProperty TFontName System.UITypes.TFontName tkUString

This post was inspired by an interesting discussion on [WayBack] What’s the technical term for the following construct: type intx = type integer; type inty = integer; What term would you use to describe the differen… – Johan Bontes – Google+

Documentation:

RTTI dump inspired by [WayBack] delphi – How can I distinguish TDateTime properties from Double properties with RTTI? – Stack Overflow.

–jeroen

Read the rest of this entry »

Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | 2 Comments »

A series of Medium posts introducing functional programming in manageable bits and pieces

Posted by jpluimers on 2020/09/30

I have summarised the main topics of each part in this table of contents, and indicated at the time of writing which parts I did not get yet:

  1. [WayBack] So You Want to be a Functional Programmer (Part 1) – Charles Scalfani – Medium
    • pure functions (only operate on input parameters: without side effects)
    • immutability (no variables! loops through recursion)
  2. [WayBack] So You Want to be a Functional Programmer (Part 2) – Charles Scalfani – Medium
    • refactoring leads to the need of higher-order functions
    • higher-order functions: passing a function as a parameter, or returning functions as a result
    • closure: when a returned function has access to the captured parameter(s) of the function creating the returned function
  3. [WayBack] So You Want to be a Functional Programmer (Part 3) – Charles Scalfani – Medium
    • functional decomposition (I still need to wrap my head around this)
    • point-free notation (same)
    • both lead to currying (which I also need to wrap my head around)
  4. [WayBack] So You Want to be a Functional Programmer (Part 4) – Charles Scalfani – Medium
    • currying: when you want to combine functions having different parameter counts
    • refactoring based on currying (I still need to wrap my head around this)
    • map/filter/reduce functional building blocks (I still need to wrap my head around this)
  5. [WayBack] So You Want to be a Functional Programmer (Part 5) – Charles Scalfani – Medium
    • referential transparency (I still need to wrap my head around this)
    • execution order: in a pure functional language the compiler can determine the order when functions are completely independent
    • type annotation: I do not yet get why you would do without this
  6. [WayBack] So You Want to be a Functional Programmer (Part 6) – Charles Scalfani – Medium
    • Functional JavaScript and ELM: two functional languages, of which Ramba can help make better JavaScript code

Via: [WayBack] So You Want to be a Functional Programmer (Part 1) Link to part 2 in the article. https://medium.com/@cscalfani/so-you-want-to-be-a-functional-programm… – Lars Fosdal – Google+

–jeroen

Posted in Development, Functional Programming, Software Development | Leave a Comment »

When your ORM does not support string concatenation by || or + operator…

Posted by jpluimers on 2020/09/30

If your ORM does not support string concatenation by operator (standard double pipe || or non-standard plus +), you can usually revert to the CONCAT function.

Very often, the CONCAT function supports more than 2 parameters.

References:

–jeroen

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

When did we stop caring about memory management? – Scott Hanselman

Posted by jpluimers on 2020/09/29

Still relevant [WayBack] When did we stop caring about memory management? – Scott Hanselman

Via: [WayBack] Jeroen Wiert Pluimers – Google+

–jeroen

Read the rest of this entry »

Posted in Development, Software Development | Leave a Comment »

variables – What is “_,” in a Golang declaration? – Stack Overflow

Posted by jpluimers on 2020/09/29

As a (then) go lang n00b, the less upvoted answers helped me e lot: [WayBack] variables – What is “_,” in a Golang declaration? – Stack Overflow:

  • The Go compiler won’t allow you to create variables that you never use.

    for i, value := range x {
       total += value
    }

    The above code will return an error message “i declared and not used”.

    Since we don’t use i inside of our loop we need to change it to this:

    for _, value := range x {
       total += value
    }
  • _ is the blank identifier. Meaning the value it should be assigned is discarded.

    Here it is the value of example key that is discarded. The second line of code would discard the presence boolean and store the value in prs.
    So to only check the presence in the map, you can discard the value. This can be used to use a map as a set.

–jeroen

Posted in Development, Go (golang), Software Development | Leave a Comment »

 
%d bloggers like this: