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. :)
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. :)
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?
ReplyDeleteexplicit dependency of units/uses is me favourite features.
ReplyDeleteI miss....8 bit strings :D
string handling, if you worked with C "strings", you know why.
ReplyDeleteAlso, using an array[TMyEnum] of SomeType is also realy realy nice.
I miss LINQ.
ReplyDelete/sub
ReplyDeleteFavorite: Attributes, and the advanced RTTI
ReplyDeleteMissing: Lambda expressions, Bit-fields (C++), a more advanced Template functionality
Also missing the ability to specify capturing of variable by value in anonymous methods (Available in C++ as example)
ReplyDeleteBrian 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)
ReplyDeletebit fields in record
ReplyDeleteI miss generic constraints by intrinsic types (ie T should be an Integer, Double, String etc) so you can then use operators with T data.
ReplyDeletenullable types
ReplyDeleteI love the fact that I can do this in Delphi but not available in CSharp.
ReplyDeletetype
TAnimal = class
TCatClass = class of TAnimal;
end;
Unfortunately, I miss the 'yield return' keyword found in CSharp.
it makes enumeration more fun.
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
ReplyDeleteI love: RTTI, PPL, class/record helpers.
ReplyDeleteI miss: Task Continuations and Cancellation Token, better lambda syntax, implicit type variables, interface/generic helpers, inheritance and aliasing support for helpers.
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
ReplyDeletesort of thing
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)
ReplyDeleteGod... where do I start... Ok, I will have to divide this in four sections: historical pascal, historical Delphi, modern and what I miss :D
ReplyDeleteHistorical 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
Having usable with would be much appreciated.
ReplyDeletewith MyHugeIdentifier as id do begin
id.DoSomething;
id.DoSomethingElse;
end;
/features
ReplyDeleteLingering dream:
ReplyDeleteClass Operator Initialize; (advanced records)
Class Operator Finalize; (advanced records)
Class Operator Copy; (advanced records)
Namespaces; Real. Working.
Partial Classes
I miss full RTTI, interface helpers, NameOf, rock solid compiler and compiler debugger integration. I love the super fast non LLVM compilers.
ReplyDeleteMissing - records inheritance,
ReplyDeleteDefault record constructor
Variable declaration inside the block
Boian Mitov there is object inheritance. Not sure if objects allow operator overloads.
ReplyDeleteI miss the fact that I can not reference a project in another project as I do in csharp.
ReplyDelete* generic methods for interfaces (not an easy task for emba, I know)
ReplyDelete* 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?)
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.
ReplyDeleteBoian Mitov He wrote object not class. ;)Jeroen Wiert Pluimers I would not recommend using object at all. They are a dying feature.
ReplyDeleteStefan 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...
ReplyDeleteTClass, virtual constructors and class-scope methods.
ReplyDeleteOh 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)
ReplyDeleteWhat 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
ReplyDeleteHowever 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.
Oh yeah and ?:, just don't fuck it up like Python did.
ReplyDeleteFrom the current Delphi language, I love Generics. And what I missing, here is the list:
ReplyDelete- 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!!!!
Juan C. Cilleruelo Why would you want C++ style object creation? Then you lose named constructors, which are a valuable language feature in Delphi.
ReplyDeleteA small nice thingy in dwscript is I can declare variables almost anywhere. Not a superadvanced thing but with lambdas it can be really neat.
ReplyDeleteI 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.
Mason Wheeler What I want is a syntax more near to Delphi Prism. (You can read C#).
ReplyDeleteOK. 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.
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.
ReplyDeleteFavourite: Pascal string handling.
ReplyDeleteWhat I miss: Interfaces like other languages (e.g. C#, Java), free of all COM and TInterfacedObject stuff.
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
ReplyDeleteMissing: 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
Nested procedures are a heaven, no need to create extra classes to nest scopes.
ReplyDeleteLike: Anonymous methods (even if they are too verbose), Generics, virtual ctor, TFooClass = class of TFoo
ReplyDeleteMissing: Real ternary operators, not this IfThen shit :-(
And even its IDE related: moar betta fasta productivity tools
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?
ReplyDeleteWe'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.
I really like the clear and easy syntax of Delphi's RTL, VCL and FMX.
ReplyDeleteI 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.
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?
ReplyDeleteI would like to be able to do what is possible with Smalltalk or C++ templates that is impossible with generics.
ReplyDeleteWillo 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 :)
ReplyDeleteAre you collecting info for a marketing purposes? I miss not tying having to type "then". Its just useless, and should be optional.
ReplyDeleteI miss the rooted type system too :D
ReplyDeleteMultiple inheritance without the use of interfaces
ReplyDeleteMiss: Multiple interface inheritance.
ReplyDeleteTo have better and more flexible consts, even lightweight two phase compiler would be nice. (Just to maybe mark regions that would be precompiled etc)
ReplyDeleteI 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.
ReplyDeleteI 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.
ReplyDeleteLikes:
ReplyDelete* 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
Markus Ja I hate the fact that private sections can be accessed in the same unit :P I think it's bad :D
ReplyDeleteA
Andrea Raimondi
ReplyDeleteYou can use strict private instead.
I like the mix between high level features and low level ones down to asm.
ReplyDeleteMeta 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).
Eric Grange +1 for your list except that I don't care for GC of any kind :)
ReplyDeleteDalija 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.
ReplyDeleteAnd 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.
Eric Grange I currently hate GC so much that I am not capable of taking objective look at it in any context ;-)
ReplyDeleteI miss variable declaration inside the block
ReplyDeleteDalija 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
ReplyDeleteHorácio Filho I don't use Xamarin. I am using Android Studio and plain Java for Android apps.
ReplyDeleteDalija Prasnikar Kind of feel the same :-D
ReplyDeleteLike, from one that I was using today:
ReplyDelete1. 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.
Girish Patil Doesn't/wouldn't the following work also?
ReplyDeleteTMyConstArrayNames: array[TMyEnum] of string = ('One', 'Two', 'Three');
TMyConstArrayClasses: array[TMyEnum] of TMyClass = (TEdit, TButton, TMemo);
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 :)
ReplyDeleteDalija Prasnikar
ReplyDeleteI 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.
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.
ReplyDeleteNo 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.
Dalija Prasnikar Just curious, what is it that you dislike but the Android GC?
ReplyDeleteNicholas 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.
ReplyDeleteI 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.
Dalija Prasnikar Thanks for explaining to me - a bit of an eye opener (for someone that hasn't played around mobile applications).
ReplyDelete/sub. I'd love to know if the new management will push this area of Delphi - it's sorely needed. I'm hopeful!
ReplyDeleteLooks like multiple line string is not mentioned yet, it's very handy, for example:
ReplyDeleteconst
cSql = '''
select * from
tableA
inner join Table B on...
where...
order by..
''''
* Property expressions
ReplyDelete* Lambdas
* Java-style interfaces (not refcounted)
* for/while/repeat/etc... -scoped variables
* templates
* LINQ
* inline if-then/conditional operator (ala ?: in C#)
I'd say the thing I like most is properties.
ReplyDeleteThings 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