What are your favourite features of Object Pascal (I mean Delphi, no FPC, no SmartPascal, Oxygene or others) and what do you miss the most that you might know from other languages?

What are your favourite features of Object Pascal (I mean Delphi, no FPC, no SmartPascal, Oxygene or others) and what do you miss the most that you might know from other languages?

Please only pure language features, no IDE things or "I can put stuff together very fast using RAD" (which can be great, no doubt). Looking for a constructive conversation. Flames will be removed by me. :)

Comments

  1. one thing I miss from VS is that it highlights a variable that you have declared but not used (green squiggle underneath) and code completion and hints you could argue are better?

    ReplyDelete
  2. explicit dependency of units/uses is me favourite features.

    I miss....8 bit strings :D

    ReplyDelete
  3. string handling, if you worked with C "strings", you know why.
    Also, using an array[TMyEnum] of SomeType is also realy realy nice.

    ReplyDelete
  4. Favorite: Attributes, and the advanced RTTI
    Missing: Lambda expressions, Bit-fields (C++), a more advanced Template functionality

    ReplyDelete
  5. Also missing the ability to specify capturing of variable by value in anonymous methods (Available in C++ as example)

    ReplyDelete
  6. Brian Hamilton That's actually an IDE feature but since it's tightly coupled to the compiler I give you that (I also miss a smarter code highlighting - love that types have their own color in VS)

    ReplyDelete
  7. I miss generic constraints by intrinsic types (ie T should be an Integer, Double, String etc) so you can then use operators with T data.

    ReplyDelete
  8. I love the fact that I can do this in Delphi but not available in CSharp.
    type
    TAnimal = class
    TCatClass = class of TAnimal;
    end;

    Unfortunately, I miss the 'yield return' keyword found in CSharp.
    it makes enumeration more fun.

    ReplyDelete
  9. I like how it has "sections" for public, private, protected, and published so that you don't have to put those specifiers on EVERY member in a class

    ReplyDelete
  10. I love: RTTI, PPL, class/record helpers.
    I miss: Task Continuations and Cancellation Token, better lambda syntax, implicit type variables, interface/generic helpers, inheritance and aliasing support for helpers.

    ReplyDelete
  11. another nice thing with C++/C# is with declaring variables to be used in the procedure...its actually nice in that don't have to scroll up to the start of the procedure to check on your variables used etc
    sort of thing

    ReplyDelete
  12. Horácio Filho PPL is a runtime piece and not language related - until we talk about the missing integration into the language itself (async/await)

    ReplyDelete
  13. God... where do I start... Ok, I will have to divide this in four sections: historical pascal, historical Delphi, modern and what I miss :D

    Historical pascal:
    1) General tidiness of source code
    2) Strings
    3) Pointers (incl. arithmetic)
    4) Array indexing on custom types (enums, value ranges, etc.).

    Historical Delphi:
    1) Call conventions
    2) Ability to make DLLs
    3) OLE support

    Modern:
    1) strict mode
    2) Classes inside classes (I don't use this often, but when you need it... :D)
    3) Generics (has almost completely removed the need for case statements)
    4) Anonymous methods

    What I miss:
    1) The ?: combination. While it comes from C, it is very short and handy. I would also be very happy with a more pascal-ish "when" ( ex. MyVar := when FlagSet then 1 orelse 2; ). Orelse would have to be one keyword :)

    2) More "java-ish" interfaces where you can cast between the implementation and the interface (again, this is a fringe case, but sometimes...). I would also be very happy with an intrinsic "Instance" property for IInterface that points to the underlying object. This would - in fact - be extremely good for debug :)

    A

    ReplyDelete
  14. Having usable with would be much appreciated.
    with MyHugeIdentifier as id do begin 
      id.DoSomething;
      id.DoSomethingElse;
    end;

    ReplyDelete
  15. Lingering dream:

    Class Operator Initialize; (advanced records)
    Class Operator Finalize; (advanced records)
    Class Operator Copy; (advanced records)
    Namespaces; Real. Working.
    Partial Classes

    ReplyDelete
  16. I miss full RTTI, interface helpers, NameOf, rock solid compiler and compiler debugger integration. I love the super fast non LLVM compilers.

    ReplyDelete
  17. Missing - records inheritance,
    Default record constructor
    Variable declaration inside the block

    ReplyDelete
  18. Boian Mitov there is object inheritance. Not sure if objects allow operator overloads.

    ReplyDelete
  19. I miss the fact that I can not reference a project in another project as I do in csharp.

    ReplyDelete
  20. * generic methods for interfaces (not an easy task for emba, I know)
    * helpers for interfaces (should be easy to implement -> syntax sugar)
    * yield for enumerators (one word will eliminate a lot of code)
    * ARC for all platforms (not only to eliminate some memleak bugs from RTL - do they know there is also NONARC?)

    ReplyDelete
  21. Jeroen Wiert Pluimers yes, but there are cases when you need record inheritance, as example when you use records to map communication protocols. Objects can't be used as they have Virtual table etc. and don;t map properly in the memory. In C++ this is easy, in Delphi you have to play tricks by embedding the parent record into a field etc. Doable but then it makes it difficult to perform common operations by pointer etc.

    ReplyDelete
  22. Boian Mitov He wrote object not class. ;)Jeroen Wiert Pluimers I would not recommend using object at all. They are a dying feature.

    ReplyDelete
  23. Stefan Glienke Yeah... I forgot about those, but thy have been obsolete and deprecated feature for years, I agree with you, not a good idea to use them...

    ReplyDelete
  24. TClass, virtual constructors and class-scope methods.

    ReplyDelete
  25. Oh I missed the support for real namespaces - but that is far, far away in the future - if ever (this feature is not possible for a single pass compiler)

    ReplyDelete
  26. What I usually miss the most when working with other languages are sets and properties. After spending some time with C++, what I miss the most in Delphi is C++ :P

    However I'll settle for something very concrete: 
    - a more concise way to write lambdas. I think Delphi could do with borrowing Python's lambda keyword, ala "f := lambda x: x.ToString();"
    - way, way better type deduction when dealing with generics.

    ReplyDelete
  27. Oh yeah and ?:, just don't fuck it up like Python did.

    ReplyDelete
  28. From the current Delphi language, I love Generics. And what I missing, here is the list:
    - I want that "function" and "procedure" keywords become both "method".
    - I want that the constructors invocations take the form: "MyInstance := New TMyClass();"

    I hate "with" statement. BRRRRRRR!!!!

    ReplyDelete
  29. Juan C. Cilleruelo  Why would you want C++ style object creation?  Then you lose named constructors, which are a valuable language feature in Delphi.

    ReplyDelete
  30. A small nice thingy in dwscript is I can declare variables almost anywhere. Not a superadvanced thing but with lambdas it can be really neat.

    I would also like all sorts of arrays and records to be easier to initialize with values. The syntax is messy now. And const arrays to be handled properly.

    ReplyDelete
  31. Mason Wheeler What I want is a syntax more near to Delphi Prism. (You can read C#).
    OK. If you want named constructors, you can use: "MyInstance := New MyClass.Constructor();" or we can ask for overloaded constructors.

    There are only esthetic changes, what I want. The language, I think, is very expressive. And is not as cryptic as all the 'C' like languages.

    ReplyDelete
  32. Mason Wheeler After we got overloading, my need for differently-named constructors has been approaching zero and has so for quite a while. In fact I can't recall the last time I used it.

    ReplyDelete
  33. Favourite: Pascal string handling.

    What I miss: Interfaces like other languages (e.g. C#, Java), free of all COM and TInterfacedObject stuff.

    ReplyDelete
  34. Likes: COW strings including 8-bit ones, separate interface and implementation section, delegation of interfaces with implements keyword, records, procedural types, case that doesn't need break after every statement

    Missing: weak references for interfaces in non-ARC compiler, partial classes or extensions, better generics constraints and code generation, nullable types with full support (operators), string case

    ReplyDelete
  35. Nested procedures are a heaven, no need to create extra classes to nest scopes.

    ReplyDelete
  36. Like: Anonymous methods (even if they are too verbose), Generics, virtual ctor, TFooClass = class of TFoo
    Missing: Real ternary operators, not this IfThen shit :-(
    And even its IDE related: moar betta fasta productivity tools

    ReplyDelete
  37. What I miss from c# - Lambdas, LINQ, type inference, inline variable declaration(and block scope), inline loop index variable declaration (with block scope), case statement on strings, local variable initialization at declaration, shortcut property declaration, interface helpers, multiple helpers per type (currently 1), non ref counted interfaces, weak references for interfaces, teirnery operator... I could go on all day, but what's the point?

    We've been asking for language improvments for years... and what do we get instead, zero based strings!  

    I'd really love for embarcadero/idera to focus on the one thing that none of us can do, the compiler/language. Anyone can write libraries, interface with IoT etc... but only they can work on the compiler.

    ReplyDelete
  38. I really like the clear and easy syntax of Delphi's RTL, VCL and FMX.

    I recently got involved in an Android project and the verbosity and hoops you have to jump through to do simple things, really had me longing for my good ' ol Delphi.

    ReplyDelete
  39. Asbjørn Heid I still use it a lot. It helps to make your code more readable. When using the Active Record pattern for instance you might have Create, CreateFromDb, CreateFromFile, etc. Sure, you could probably override it, but would it be as clear?

    ReplyDelete
  40. I would like to be able to do what is possible with Smalltalk or C++ templates that is impossible with generics.

    ReplyDelete
  41. Willo van der Merwe For things like that I usually pass some interface which abstracts away the source, hence I don't need different names. Anyway not saying it's a bad feature, just saying I wouldn't miss them much if they went away :)

    ReplyDelete
  42. Are you collecting info for a marketing purposes? I miss not tying having to type "then". Its just useless, and should be optional.

    ReplyDelete
  43. Multiple inheritance without the use of interfaces

    ReplyDelete
  44. To have better and more flexible consts, even lightweight two phase compiler would be nice. (Just to maybe mark regions that would be precompiled etc)

    ReplyDelete
  45. I miss the feature of passing optional parameters to functions by names, and more concise and flexible syntax of using dictionaries - ie. without having to declare, create and free the TDictionary<>  objects, and I can use any types of data for the keys and values.

    ReplyDelete
  46. I miss RAII and template "duck typing" from C++. While there are a number of advanced features in delphi the ones that I miss the most when working with a different language are properties and sets.

    ReplyDelete
  47. Likes:
    * I like the string handling, and that strings cannot be nil.
    * As well as nested procedures/functions
    * Sets
    * Properties
    * And that private sections can be accessed from other classes in the same unit :)
    Missing:
    * Stack trace when an exception occures.
    * Sometimes it would be handy to write: x := y:= z := 0 and += as in C++
    * nameof(), for properties and methond. To return the name as string, like .ClassName

    ReplyDelete
  48. Markus Ja I hate the fact that private sections can be accessed in the same unit :P  I think it's bad :D

    A

    ReplyDelete
  49. Andrea Raimondi
    You can use strict private instead.

    ReplyDelete
  50. I like the mix between high level features and low level ones down to asm.

    Meta classes are the key feature other languages do not have
        class of TSomething
    and the ability to have virtual class methods to leverage meta-classes.

    I miss a STABLE Win64 compiler+debug environment.
    I miss a Linux compiler.
    I miss templates, generics are just too limited and annoying for a statically compiled language, and to boot their C-like syntax is atrocious and looks alien among the rest of Pascal code.
    An opt-in GC would be nice (a tracing one, not ARC).

    ReplyDelete
  51. Eric Grange +1 for your list except that I don't care for GC of any kind :)

    ReplyDelete
  52. Dalija Prasnikar GC goes with my first point, being high-level: sometimes you just want something that works, and do not care about performance because it is not performance critical.

    And when you care, ARC is just not there: it "mostly" automates memory management, and it is "mostly" efficient, but it is not automatic enough to work well on its own (a simple parented tree or graph is enough to make it barf), it is not efficient enough for use in performance-critical sections of code, and it just does not scale for heavy multi-threading.

    Jack of all trades, master of none comes to mind.

    ReplyDelete
  53. Eric Grange I currently hate GC so much that I am not capable of taking objective look at it in any context ;-)

    ReplyDelete
  54. I miss variable declaration inside the block

    ReplyDelete
  55. Dalija Prasnikar Don't you like Xamarin? It uses Tarjan Garbage Collector for Android targets, have you surfed on problems using it? Memory peaks or something related? I didn't mean GC is better than ARC :D

    ReplyDelete
  56. Horácio Filho I don't use Xamarin. I am using Android Studio and plain Java for Android apps.

    ReplyDelete
  57. Dalija Prasnikar Kind of feel the same :-D

    ReplyDelete
  58. Like, from one that I was using today:
    1. the classic feature of const arrays indexed by enums that can hold specific types, for example:
    type
    TMyEnum = (meOne, meTwo, meThree);
    TMyClass = class of TObject;
    const
    TMyConstArrayNames: array[Low(TMyEnum)..High(TMyEnum)] of string =  ('One', 'Two', 'Three');
    TMyConstArrayClasses: array[Low(TMyEnum)..High(TMyEnum)] of TMyClass = (TEdit, TButton, TMemo);

    I probably have to use a dictionary type for this in C#, but it would not be so flexible?

    2. Set type
    3. Published properties
    Miss: inline loop index variable with scope limited to the loop, LINQ.

    ReplyDelete
  59. Girish Patil  Doesn't/wouldn't the following work also?

    TMyConstArrayNames: array[TMyEnum] of string =  ('One', 'Two', 'Three');
    TMyConstArrayClasses: array[TMyEnum] of TMyClass = (TEdit, TButton, TMemo);

    ReplyDelete
  60. Nicholas Ring Sure it does. That's actually how I would do it normally - I'm not sure why I did that this time. Thanks for pointing out :)

    ReplyDelete
  61. Dalija Prasnikar
    I read that you are using Android Studio. Since you don't like Java, did you already try RemObjects Oxygene? So, you could use the object pascal languge for Android, iPhone and WinPhone.

    ReplyDelete
  62. Markus Ja Well, that was my initial intention. But using Oxygene also has it's gotchas so I went for native tools all the way.

    No matter how much I prefer Pascal, using different language is only minor comparing to using new frameworks and getting used to new platform. And all platform documentation and examples cover native languages (Java, Objective-C, Swift). Reading documentation and translating it to Pascal turned out to be more nuisance than help. 

    Also, while I do dislike Java, it is GC on Android that annoys the hell out of me. And Oxygene on Android would not help in that regard because it also operates under GC.

    ReplyDelete
  63. Dalija Prasnikar Just curious, what is it that you dislike but the Android GC?

    ReplyDelete
  64. Nicholas Ring First GC always uses more memory than you need at some point. When you write apps that run under serious memory constraints that is bad. Next thing is that when GC kicks in, more often then not user will see serious hiccup in you app. And then various Android systems on various Android devices can have bugs in their GC systems. First, you have to be aware of them, and next you have to deal with them.
    I have such buggy device caught in action http://stackoverflow.com/q/30776779/4267244

    To workaround all above issues you have to manually call System.gc() at places you see fit. What is the good of having automatic memory management when you have to fight it all the way.

    And GC in constrained memory environment means that you have to avoid creating objects at all costs, since Java is "everything is an object" language, avoiding that is not an easy task. For instance, in Delphi creating temporary object in Control paint method is fine, because creating and disposing it does not cost much, but in Android you cannot do the same, unless you like you controls working in slow motion. So every local temporary object that you would want to create in some performance critical method has to be class member, instead of local one. That has serious impacts on code readability.

    ReplyDelete
  65. Dalija Prasnikar Thanks for explaining to me - a bit of an eye opener (for someone that hasn't played around mobile applications).

    ReplyDelete
  66. /sub. I'd love to know if the new management will push this area of Delphi - it's sorely needed. I'm hopeful!

    ReplyDelete
  67. Looks like multiple line string is not mentioned yet, it's very handy, for example:

    const
      cSql = '''
    select * from
    tableA
    inner join Table B on...
    where...
    order by..
    ''''

    ReplyDelete
  68. * Property expressions
    * Lambdas
    * Java-style interfaces (not refcounted)
    * for/while/repeat/etc... -scoped variables
    * templates
    * LINQ
    * inline if-then/conditional operator (ala ?: in C#)

    ReplyDelete
  69. I'd say the thing I like most is properties.

    Things I like least / missing are mostly things I miss in C++:

    * a way to define simple methods inline in properties
    * a way to initialize local class vars in class decls
    * lambdas and anon funcs need to be provided in a simpler way, like what Java 8 does
    * declare vars anywhere
    * NameOf() for everything (esp. properties)
    * a simpler way to initialize structured objects that are essentially run-time constants, particularly where strings are involved
    * the ability to split the interface and implementation sections into separate files, and the ability to spread methods across multiple files
    * actually, I wish the entire file-based paradigm would go away

    ReplyDelete

Post a Comment