What do you miss in the Delphi language? Which features ?

What do you miss in the Delphi language? Which features ?

I miss the "return" statement and good reference-counting memory management for objects (doing it through interfaces is a bit uncomfortably for me)

Comments

  1. I miss the C-ish ? : which is very useful in some cases :-)

    ReplyDelete
  2. I miss i++ and i-- shortcuts, they are often very handy )

    ReplyDelete
  3. 1. String with vars in it: s := "This string contains local var with value:@localVar. Compiler expand this stuff."
    2. More type inferring for anonymous method: signature is known either from type of variable it assigned to or type of method arg it passed to. Remove "begin" & "end" keywords if anonymous method contains single statement.

    ReplyDelete
  4. I like the removal of begin/end for one liners

    ReplyDelete
  5. Krom Stern I don't get the usefulness of that

    ReplyDelete
  6. For example:
    const
      Procs: array [0..1] of record
        Names: string;
        Typ: array of Byte;
        Dir: array of TPSParameterMode;
      end =
      (
      (Names: 'ONHOUSEDESTROYED';  Typ: (0, btS32, btS32,  btEnum); Dir: (pmIn, pmIn, pmIn)),
      (Names: 'ONHOUSELOST';       Typ: (0, btS32, btEnum);      Dir: (pmIn, pmIn))
      );

    ReplyDelete
  7. - Local variables inside begin/end bloc.
    var
      I : Integer;
    begin
      WriteLn('Start');
      for I := 0 to 10 do begin
          var Temp : Integer;
          Temp := I + 1;
          WriteLn(Temp);
      end;
    end;

    - Local variable initialisation in their declaration
      var Count : Integer = 5;

    - Local variable declared ad hoc
    procedure Foo;
    begin
      WriteLn('Start');
      var Count : Integer;
      Read(Count);
      for var I : Integer = 0 to Count do
        WriteLn(I);
    end;
     
    - Automatic counting of array element in typed constant:
          const MyArray : Integer = array (1, 2, 3);

    ReplyDelete
  8. 1) the "step" in "for loop"
    for index := _start to/downto _end step _inc/_dec_value do

    Eric added it to DWS and it's awesome

    2) array slice, should be very easy to implement

    type TMyByteArray = array of Byte;
    TMyByteArray = slice of TMyByteArray; // the compiler takes care of the rest
    TMyByteArrayLimit = slice[ 10 ] of TMyByteArray; // slice that references only 10 elements from start index

    now, I should also be able to do in/decrement a "slice", if I happen to access an element out of bounds => AV

    3) ability to include C and C++ headers in my project, I'm pretty sure that almost all of you had to do it at least once, well, EMB also has the CB compiler, that seems to be tightly integrated with some delphi features, this makes me think that we can have something like:

    {$INCLUDE_HEADER 'my_cool_c_header.h'}
    or the shorter form
    {$IH 'my_cool_c_header.h'}

    var SomeVar: struct_from_my_cool_c_header_t;

    4) ability to define multiple record/class helpers for a type, without losing another one defined in a different unit

    5) each procedure should return the reference, easily achievable

    type TMyCoolClass = class...
    var mcc: TMyCoolClass;
    ...
    mcc
        .DoThis
        .DoThat
        .AllGood;
        //.Free; <- mwa-ha-ha!!

    Love to have:
    - since D7, the compiler is slower and slower, I'm thinking that the compiler is wasting time freeing memory rather than do it's job quickly and exit, maybe an option to say "compiler, don't free memory, compile like chuck norris on crack!"

    - better warnings in compiler, there are many times when you go "wtf", the compiler(maybe added in XE3) should warn me that there are two units in uses that have a function with the same description and that I should use preferred_unit.function_name(args) explicitly

    ReplyDelete
  9. François Piette the "local" variable is a bad idea, cool for scripting languages, bad for big projects. There's a reason for the "variable declaration section".

    ReplyDelete
  10. re the warning with multiple units with the same routine name: imho it should be a compiler error, meaning it should be made mandatory. A

    ReplyDelete
  11. Dorin Duminica I disagree on all counts :-) I think it would make code more readable and compact. It would be great especially for prototyping. A

    ReplyDelete
  12. Andrea Raimondi if compact code is what you want, then OK.
    I, for one, prefer easy to follow code, it's enough that many times we have to cut corners with the pocket knife, now, what you're saying is: replace the pocket knife with a handgun, so that when it hurts, it hurts really bad! ((:

    ReplyDelete
  13. Dorin Duminica I think that, sometimes, you just can't avoid big pieces of code. In those cases, having local var declarations would be easier and neater. When you're done, you can refactor and remove them. The bottom line is that this would allow really cool stuff like more precise refactorings. There are plenty of scenarios where this would be a good thing.

    ReplyDelete
  14. Existing language features are good enough for me.

    I miss "Declared but never used" for global variables/types/classes/procedures across the project/project group :)
    I miss cross-reference usage table.
    I miss "Extract duplicate code" refactoring :)
    I miss assembly language representation of Delphi code as option to the command-line compiler.

    ReplyDelete
  15. Andrea Raimondi agree that you can't avoid big pieces of code, but you still have to refactor -- if not done properly, surprises arise, and in 11/10 cases you'll have surprises (: anyhu', we went off topic, sorry.

    ReplyDelete
  16. I miss string for case of. Now it only work with numbers.

    ReplyDelete
  17. No no no no no!!!!

    No Case on strings please!!!

    Give me string as array indexes instead :)

    Regards,

    A

    ReplyDelete
  18. Thomas Mueller Exit(5); is already supported since Delphi 2009

    ReplyDelete
  19. That's what I wanted to say with my comment: A "return statement" is already there, it's called exit. Uwe Schuster

    ReplyDelete
  20. I miss almost everyday fast property declaration , and less often  a compact object querying syntax like Linq.... and a "declare variable" refactoring that works all the time ...

    ReplyDelete
  21. Olivier SCHWAB what do you mean by "fast property declaration", how would you envision it?

    ReplyDelete
  22. Dorin Duminica   in several languages , when you need to declare a classical property you can declare it in a single line 

    ex in C# :   property  Name { get ; set ;}
    or             property  Name { get  ;}
    for read only property;

    OK one can say : but in delphi, it's one declaration line for property, and one for the field.  Yes ! But I still prefer faster code to produce and to read.....

    ReplyDelete
  23. Type the property declaration and press Ctrl+Alt+c Olivier SCHWAB
    What's wrong with that?

    ReplyDelete
  24. Olivier SCHWAB ah, but you can also "forget" about the "protected/private field" and declare it as "Name: string;" and voila, when you need specialized getter and setter, just update it. Anyhu', I wasn't able to wrap my head regarding the "fast declaration", thank you for making it clear.

    ReplyDelete
  25. For one, I'd like for the language to be case sensitive. Generic free functions would be nice. In general though, after 5 years coding C++, I've come to prefer most of the C++ syntax.

    ReplyDelete
  26. Daniela Osterhagen I always prefer a short syntax to handful of keyboard shortcuts ....

    ReplyDelete
  27. Asbjørn Heid  Ahhh a case sensitive lover ! Can you explain why you love it ? I regulary shout after Linux for that, and for me , case sensitive languages is nonsense ; if you want to variable with same name to store different things, something is wrong, no ?

    ReplyDelete
  28. Asbjørn Heid if you where to frequently change between language syntax, it would be a different story, I get what you mean tho, if you write a lot in a language, it becomes second nature.

    ReplyDelete
  29. I wish

    With could be redefined to scope local variables
    with Current: TMyType = SomeList.Param[ix],
      Target: TMyType = OtherList.Item[jx]
    do begin
      if Current.Value = Target.Value
      then ...

    With could define local variables
    with ix: Integer = 25
    do while ix > 0
      do begin
        ...
        dec(ix);
      end;
    // ix is out of scope here

    With could define local variables with implicit try/finally/destroy
    with Obj: TMyBaseClass = TDerivativeClass.Create;
    do while Obj.NotDone
      do Obj.DoProcess
    // Obj is out of scope and destroyed here

    For loop index variables could be locally declared to ensure no reuse
    for ix:Integer = 0 to Max

    RTTI would move towards CTTI
    I.e. the same conceptual use, but stuff like property validation via constant string literals done at run time, would be done at compile time instead.  Yes, that would most likely require a two pass compiler.  Alternatively, that there was a magic compiler function that emitted a property, method or type name as a string by calling %MemberName( TMyType.SomeProperty) or %QualifiedName(TMyType.SomeProperty).

    ReplyDelete
  30. Lars Fosdal I'm having trouble wrapping my head around the [with] part's value, can you elaborate on the gain?

    ReplyDelete
  31. The first one is clarification. A With statement having multiple arguments today, leads to very obscure code.  You really don't know if the calls made are to argument1, argument2, a local function, a type function or a global function.

    The other two are for limiting the scope of helper variables, eliminating accidental references to helper variables that may be stale.

    ReplyDelete
  32. basically, the compiler will add a local variable for you...

    ReplyDelete
  33. A local variable which has a limited scope, and which hopefully lends clarity.

    ReplyDelete
  34. well, [with] and I don't make a good team... (:

    ReplyDelete
  35. I also avoid the current with, unless it can be used to add clarity.

    ReplyDelete
  36. Olivier SCHWAB I prefer it when variables have the same case everywhere. I find it harder to parse when you have code like
      var foo: integer; begin FOO := 42;
    In addition, it allows you to get around the silly T prefixes. Never liked those. I much prefer
      Array.Sort(...);
    to
      TArray.Sort(...);

    ReplyDelete
  37. Dorin Duminica True, however I wrote Pascal/Delphi for almost 15 years before that... so I don't think it's just that it's C++ I've worked most with recently. I really like the RAII concept for example, and I much prefer the inline variable declarations the way C++ does it.

    ReplyDelete
  38. Asbjørn Heid I'm pretty confident that it's because of getting used too, before writing any javascript, I couldn't think for a second that I would ever be able to like it, after about 1 year with it, I felt like home, basically it became second nature.
    (Note: this doesn't mean that I'm a js guru, not at all, but I got so used to it that enjoyed it)

    ReplyDelete
  39. Warning for unused units in uses statement.

    ReplyDelete
  40. Andrea Raimondi - The warning on multiple units with same overlapping method names would have to be optional.  I use this to override f.x. OutputDebugString to add timestamp, threadid and overload it to have a string argument instead of pChar.

    Unlike, Asbjørn Heid - I would like Delphi to remain case INsensitive, but I'd like hints (or autocorrects) for references that are in a different case than the declaration.

    I would prefer redefining with to create local variables over François Piette's inline declarations - with one exception - the for loop.

    ReplyDelete
  41. Lars Fosdal I think it should be made mandatory simply because it's way too easy to misuse it unknowingly.
    It's a source of very difficult to find bugs and therefore I think it would be awesome to have the compiler kick and scream on it. That said, it could be an option(ON by default) called "Stop on ambigous overlapping routines" or something like that. The main problem I see with it is it should be "intelligent", i.e for example not kicking and screaming if one of the two is only defined in an implementation section as opposed to an interface one - because there's a huge difference.

    Not easy to do, but would be awesome to have indeed :)

    A

    ReplyDelete
  42. Asbjørn Heid THEORICALLY the code formatter should format every variable with the case it has at its  declaration ...

    ReplyDelete
  43. Dorin Duminica I get what you mean, but I think it's deeper than that, at least in my case. Oh well, I'm now primarily coding Delphi again, so we'll see in a year or so :)

    Olivier SCHWAB Well yes, in theory ;) However I like that you can name your classes with uppercase and your variables with lowercase. It's one of the things I've never liked about Pascal, even tho it has been my first language and primary.

    ReplyDelete
  44. Lars Fosdal I would like the with statement to be removed! Or at least a compiler option to generate a warning for any with statement.

    ReplyDelete
  45. In it's current form, I agree - François Piette - I want to change it to something useful instead.

    ReplyDelete
  46. Lars Fosdal , François Piette : In VB6 the With keyword has an interest because it was used by compiler for optimizations. In Delphi, I agree it just make debugging more difficult ...

    ReplyDelete
  47. Olivier SCHWAB In Delphi compiler may generate optimized code for with too.

    ReplyDelete
  48. With statement has nothing to do with the optimization altough it is simpler for the optimizer to optimize the code with it.

    ReplyDelete
  49. Maxim Abramovich If unit has initialization, it can't be considered useless authomatically, though it's actually useless. Icarus provides more detailed information about units and it gives quite right advices to move units between interface and implemetation sections. I totally agree with you about compiler emulation, but it's better to use tools like Icarus than nothing :)

    ReplyDelete

Post a Comment