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,232 other followers

Archive for the ‘.NET’ Category

GitHub – drewnoakes/string-theory: Identify and reduce memory used by duplicate .NET strings

Posted by jpluimers on 2021/01/19

[WayBack] GitHub – drewnoakes/string-theory: Identify and reduce memory used by duplicate .NET strings:

Identifies opportunities to improve heap memory consumption by strings.

Finds duplicate strings and provides ways to see what object graphs are keeping them alive.

Once you identify a suspicious referrer, you can query to see what other strings it is holding across the whole heap, and the total number of wasted bytes.

Cool tool to help trim down .NET string memory usage.

Via: [WayBack] drewnoakes on Twitter: “This week I published #StringTheory, a tool for analysing and reducing the memory used by strings on the managed .NET heap. We are using it to improve @VisualStudio performance, with encouraging results so far. Try it on your apps!”

–jeroen

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

How To Write Unmaintainable Code: Ensure a job for life ;-) by Roedy Green Canadian Mind Products

Posted by jpluimers on 2020/12/09

A great reference on how not to code still is

How To Write Unmaintainable Code

Ensure a job for life ;-)

Roedy Green Canadian Mind Products

I am still amazed when browsing through code, how many people use one or more of the anti-patterns in it.

One example I came across was this piece of Delphi RTL code:

class function TMarshalUnmarshalBase.ComposeKey(clazz: TClass; Field: string): string;
begin
  if clazz <> nil then
    Result := clazz.UnitName + SEP_DOT + clazz.ClassName + SEP_DOT + Field
  else
    Result := '';
end;

So I did a quick search at in the Delphi RTL for clazz, then found these occurences, indicating not only the authors of them have been under a rock, but also the code reviewers:

  • 98 in data\dbx\Data.DBXJSONReflect.pas
  • 7 in data\dbx\Data.DBXTransport.pas
  • 97 in data\rest\REST.JsonReflect.pas
  • 3 in DUnit\src\TestFramework.pas
  • 22 in indy\abstraction\IPPeerAPI.pas

I have seen similar things in many environments, even run-time libraries of others, though this is one of the worst examples and falls under the anti-pattern:

Thesaurus Surrogatisation

To break the boredom, use a thesaurus to look up as much alternate vocabulary as possible to refer to the same action, e.g. displayshowpresent. Vaguely hint there is some subtle difference, where none exists. However, if there are two similar functions that have a crucial difference, always use the same word in describing both functions (e.g. print to mean “write to a file”, “put ink on paper” and “display on the screen”). Under no circumstances, succumb to demands to write a glossary with the special purpose project vocabulary unambiguously defined. Doing so would be an unprofessional breach of the structured design principle of information hiding.

There is a great other anti-pattern in the document too:

Delphi/Pascal Only

: Don’t use functions and procedures. Use the label/goto statements then jump around a lot inside your code using this. It’ll drive ’em mad trying to trace through this. Another idea, is just to use this for the hang of it and scramble your code up jumping to and fro in some haphazard fashion.

Enjoy reading the anti-pattern descriptions, which are now maintained at [WayBack] GitHub – Droogans/unmaintainable-code: A more maintainable, easier to share version of the infamous http://mindprod.com/jgloss/unmain.html, as it was originally a multi-page hard to maintain set of small articles:

A lot of comments were posted because of it: [WayBack] Responses to Roedy’s Unmaintainable Code Essay

Via:

–jeroen

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

.NET: interfaces that inherit from multiple base interfaces

Posted by jpluimers on 2020/12/03

For my link archive:

Read the rest of this entry »

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

Delphi spring collections

Posted by jpluimers on 2020/12/02

[WayBack] Spring Collections I have a list of elements, there are, for example, 100 of them. List : IList; I want to get 5 values greater than 10 and … – Jacek Laskowski – Google+

Q

I have a list of elements, there are, for example, 100 of them.

List : IList<Integer>;

I want to get 5 values greater than 10 and I do it like this:

result: = List.Where(ValueIsGreatThan10).Take(5);

Will the “work loop” be executed a minimum number of times and if, for example, the first 5 values in the list will be greater than 5, then only the five will be checked? Or maybe the Where() loop will scan 100 elements, and Take() will return the first 5 results?

A (by Stefan Glienke)

Where and Take are streaming operators and only execute as much as required.

Also the operations have deferred execution. So your statement does not materialize any collection yet. Only if you iterate it will.

They are designed after the operators in .NET so the table from [WayBack] Classification of Standard Query Operators by Manner of Execution (C#) | Microsoft Docs applies. If you find any difference please report it.

Example:

var
  nums: IEnumerable<Integer>;
  i: Integer;
begin
  nums := TEnumerable.Range(1, 100).Where(
    function(const i: Integer): Boolean
    begin
      Writeln('checking: ', i);
      Result := i > 10;
    end
  ).Take(5);
  Writeln('query created');
  for i in nums do
    Writeln('got number: ', i);
end.

This code will print:

query created
checking: 1
checking: 2
checking: 3
checking: 4
checking: 5
checking: 6
checking: 7
checking: 8
checking: 9
checking: 10
checking: 11
got number: 11
checking: 12
got number: 12
checking: 13
got number: 13
checking: 14
got number: 14
checking: 15
got number: 15

–jeroen

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

FeaturesShim: using ShimGen for creating a shim to a program either console or GUI so you need only one bin directory

Posted by jpluimers on 2020/11/17

[WayBack] FeaturesShim is a cool Chocolatey feature that uses ShimGen.

This allows Chocolatey to take only one directory in your search PATH, with a lot of small files, that link to the much larger actual executable files.

ShimGen (like many other parts of Windows and some other parts of Chocolatey) is not open source, but the mechanism is documented.

More information:

–jeroen

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

 
%d bloggers like this: