Recent

Author Topic: Draft article for Wiki: TDictionary  (Read 7801 times)

nhollm

  • Newbie
  • Posts: 3
Draft article for Wiki: TDictionary
« on: January 02, 2025, 09:05:38 pm »
Hello there  :)

I have put together a draft article for TDictionaries

You can see it here:
https://wiki.freepascal.org/User:Nhollm
(Its on my about page)


Plesse bear with me, there will be some errors for shure :)

Best regards
Nils
« Last Edit: January 05, 2025, 12:13:14 am by nhollm »

wp

  • Hero Member
  • *****
  • Posts: 12589
Re: Draft article for Wiki: TDictionary
« Reply #1 on: January 02, 2025, 11:06:43 pm »
Please don't write it on your user page. Just create a regular article (in the wiki "search" box search for "TDictionary", and on the result page you will have the option to create a new empty page into which you can copy your text)

nhollm

  • Newbie
  • Posts: 3
Re: Draft article for Wiki: TDictionary
« Reply #2 on: January 05, 2025, 01:19:17 am »
Its done now:

https://wiki.freepascal.org/TDictionary

Some of you experienced folks here please check it for errors. I'm sure there will be some (because Im noobish).
(Is the technical section about hastables correct for example?)

Also, it would be especially nice to get hnb/Maciej Izak's input (the libs author as I suppose).

Working hard to hit the 5 post mark to be able to send PMs  :)

Best regards
Nils

dbannon

  • Hero Member
  • *****
  • Posts: 3212
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Draft article for Wiki: TDictionary
« Reply #3 on: January 05, 2025, 02:34:24 am »
Nicely done !  I don't use TDictionary so cannot comment on its accuracy. (I might use it now its so well documents!). Some very minor suggestions -

Exceptions ?  Does (eg) Add() raise an exception if it fails ? In your Exceptions block, you catch just E: Exception which is a bit of a blunt weapon, be nice to know just what exceptions might be generated without digging into the code or deliberately triggering them.

And a really pedantic thing, under  "Event Notifications", "...which are triggered if an Key or Value got added/removed". Would you mind using "was" instead of "got" ? Just a nod to cleaner English.

Overall, an excellent contribution, as I said, maybe I use TDictionary now ! Thank you.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

zeljko

  • Hero Member
  • *****
  • Posts: 1692
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Draft article for Wiki: TDictionary
« Reply #4 on: January 05, 2025, 02:40:25 am »
Very nice wiki about TDictionary.

Thaddy

  • Hero Member
  • *****
  • Posts: 16520
  • Kallstadt seems a good place to evict Trump to.
Re: Draft article for Wiki: TDictionary
« Reply #5 on: January 05, 2025, 10:51:52 am »
What I miss is reference to alteratives like TFPGMap from the fgl. A map is the the same as a dictionary. I have spotted some more room for improvement. Will report back.

First example:
The example for TObjectDictionary is a bit nonsense. The code works, but the way the objects are free'd in a loop is bad code. The ObjectDictionary can own the objects and will free the objects automatically. Maybe you were a bit confused that TObjectDictionary  has no OwnsObjects property?
You must set ownership in one of the constructors like so:
Code: Pascal  [Select][+][-]
  1. var
  2.   d: specialize TObjectDictionary<string,TObject>;
  3. begin
  4.   // sets ownership through the constructor
  5.   d:= specialize TObjectDictionary<string, TObject>.create([{doOwnsKeys,}doOwnsValues]);
  6.   // do something with d
  7.   d.free;
  8. end. // no leaks
I have seen more things that can be improved. Will add them step by step.
« Last Edit: January 05, 2025, 11:25:43 am by Thaddy »
But I am sure they don't want the Trumps back...

Hartmut

  • Hero Member
  • *****
  • Posts: 891
Re: Draft article for Wiki: TDictionary
« Reply #6 on: January 05, 2025, 11:35:51 am »
Thank you very much nhollm for this article and for improving our documentation.

Until now I did not use 'TDictionary' so I can't check for errors, but I am really enthusiastic about your introduction chapter in https://wiki.freepascal.org/TDictionary#TDictionary which is very good to understand, what this thing is about, before you go into all the details. Very good work!

Thaddy

  • Hero Member
  • *****
  • Posts: 16520
  • Kallstadt seems a good place to evict Trump to.
Re: Draft article for Wiki: TDictionary
« Reply #7 on: January 05, 2025, 11:37:43 am »
@nhollm
You did not have to remove the example, just change the constructor liike I showed and remove the free loop. The example is usable.
But I am sure they don't want the Trumps back...

dbannon

  • Hero Member
  • *****
  • Posts: 3212
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Draft article for Wiki: TDictionary
« Reply #8 on: January 05, 2025, 11:59:50 pm »
@nhollm
You did not have to remove the example, just change the constructor liike I showed and remove the free loop. The example is usable.

nholim does not appear to have removed an example, someone else has come in, made no less that 20 changes to the page without even leaving a note to nhollm or here, in this thread. The changes seem mostly superficial grammar and presentation things that could have, at least waited until the page was stable.

This is not how we attract or encourage new contributors to our documentation.

nholim, please listen to Thaddy's suggestions, and, if possible add the things he suggests. Don't be offended by the rudeness of that other person, he has done this before but does, surprisingly, mean well.

Davo

Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10792
  • Debugger - SynEdit - and more
    • wiki
Re: Draft article for Wiki: TDictionary
« Reply #9 on: January 06, 2025, 12:19:27 am »
Ironic though. Lots of changes that aim at language/style improvements....

And then, changing (several)
Quote
Get an array of all keys -> turn the KeysCollection into an array:
to
Quote
Get an array of all keys, ie turn the Keys collection into an array:

"ie" => that really should be "i.e.".

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12028
  • FPC developer.
Re: Draft article for Wiki: TDictionary
« Reply #10 on: January 06, 2025, 11:27:16 am »
I quickly checked, and could only come up with one extra thing:

Maybe some warning that the for in loop variable is read only and can't be assigned to, if it is a simple type or a record? But if it is a pointer/class type you can dereference and alter it.

AlexTP

  • Hero Member
  • *****
  • Posts: 2526
    • UVviewsoft
Re: Draft article for Wiki: TDictionary
« Reply #11 on: January 06, 2025, 12:54:03 pm »
I edited that 20 edits of the wiki. Sorry to the author, if it was disturbing! I did not want to be rude, sorry.
I only wanted to improve the text!
Changed "ie" to "i.e.".

 

TinyPortal © 2005-2018