Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 02/12/20 in all areas

  1. I've been using Delphi for 25 years, I'm working on a 20 year old code base, I'll let you know when I'm done refactoring
  2. Even Chuck Norris refactors his code (with a roundhouse kick though but still...)
  3. Much of the development I do is refactoring. Not for its own sake, but to enable a new development. Typically this means refactoring existing code, relying heavily on the testing of that code, so that the new development can be added easily. Often the bulk of the time is spent refactoring and then the new development is trivial. In other words, even when code is well factored, it often needs to be refactored. Also, its not at all the case that replacing standalone functions with classes always makes your code better. Don't be afraid to have standalone functions if that is the right design.
  4. I think we all recognize that our skills evolve. And so does our thinking. Moreover, today's "best practices" will someday probably be superseded. Any non-trivial code can be improved.
  5. Code is never perfect. You just revisit code months later and some things will inevitably draw attention. Sometimes, improvements are just minor tweaks, sometimes you are like "what was I thinking, this whole thing has to go". Sometimes, you just leave all the horror untouched because you don't have time. It is a never ending story.
  6. Primož Gabrijelčič

    Any Good tutorial on Parallel Programming Library?

    My book Hands-On Design Patterns with Delphi covers a Pipeline pattern which I fully implemented in PPL. It may give you some ideas on how to approach your problem. The source code is freely available on GitHub.
  7. David Heffernan

    Spell Checker implementation?

    http://hunspell.github.io/
  8. Uwe Raabe

    TTimer equivalent with smaller interval

    AFAIK, that has been true for Windows 95. According to the WinApi SetTimer function, which is internally used by a VCL TTimer, the minimum value for Interval is 10 ms:
  9. Stefan Glienke

    array of weak references

    Nope, that would be an array of unsafe references - an important characteristic of a weak reference is that it will be cleared when the referenced instance gets destroyed. Since you cannot declare TArray<[weak]IInterface> or something like that you need to make a record type with a weak reference field. Since Object ARC will be history with 10.4 I don't care - but weak reference for interfaces will still be a thing: {$APPTYPE CONSOLE} uses System.SysUtils; type weakref = record [weak] ref: IInterface; class operator Implicit(const value: IInterface): weakref; inline; class operator Implicit(const value: weakref): IInterface; end; class operator weakref.Implicit(const value: IInterface): weakref; begin Result.ref := value; end; class operator weakref.Implicit(const value: weakref): IInterface; begin Result := value.ref; end; procedure Test; var refs: TArray<IInterface>; weaks: Tarray<weakref>; intf: IInterface; begin SetLength(refs, 3); refs[0] := TInterfacedObject.Create; refs[1] := TInterfacedObject.Create; refs[2] := TInterfacedObject.Create; SetLength(weaks, 3); weaks[0] := refs[0]; weaks[1] := refs[1]; weaks[2] := refs[2]; refs := nil; Writeln(Assigned(IInterface(weaks[0]))); Writeln(Assigned(IInterface(weaks[1]))); Writeln(Assigned(IInterface(weaks[2]))); end; begin Test; end. FWIW Spring4D has Weak<T> that works for interfaces and objects and has the added feature that when used for objects on non ARC platform it also clears then and thus protects against dangling references.
  10. Vincent Parrett

    Tool to fix up uses clause unit namespaces?

    I just got done with this and it just worked! I did have to modify the hard coded path for the UsesHelper.SearchPath to match the delphi version I'm using. I tested first by specifying an output directory, and after checking with beyond compare to see how it did, I just processed the original files. It did also introduce some compilation errors, where I have prefixed function calls with the unit names (e.g SysUtils.DeleteFile ), simple to fix though. Thanks @Uwe Raabe
×