10 thoughts on “There are a number of neat changes in C# 6.

  1. Roland Kossow It’s just syntax sugar for being able to initialize auto properties in the constructor. Because usually you need a private setter for them which is not required with this new syntax.

    In the end most of the C# features are just syntax sugar but they will make code way shorter and more readable at the same time. Just look at the null propagating operator. It saves lots of null checks while being safe at the same time.

  2. Stefan Glienke  … yes … or the “Expression Bodied Members”

    If it would be difficult for the compiler team to implement such sugar in Delphi? Would be nice.

    BTW … am I misreading or is the code below “That’s the equivalent of writing the following C# today:” in the link wrong?

    The constructor needs to be named Person – not?

  3. Roland Kossow Syntax sugar is not very high on the priority list for Delphi as obviously not enough people are asking for it (just look at similar features on https://delphi.uservoice.com/forums/4433-language-features – interface helpers only have 15 upvotes! I guess most people don’t understand the benefit and potential of having them)

    Many Delphi developers are used to RAD so they don’t care for syntax sugar because they mostly work in the designer and object inspector.

    And yes, the code is obviously wrong – the constructor needs to have the same name as the class.

  4. A. Bouchez I am so glad that I can write windows applications with Smart Pascal… oh wait, I can’t.

    “Smart Pascal does not support generics.”

    Oh, thanks, move on. 🙂

    Don’t get me wrong, some syntax in SP is nice but that does help me as a Delphi developer as much as it helps me when C# gets new things. As long as the majority of Delphi developers still does not want to use new language features because they are slow, verbose, cryptic, too c-ish or any other flimsy excuse EMBT does not waste their resources for the 5% (*) devs actually enjoying these.

    * some randomly picked small number

  5. Stefan Glienke 

    Come on… Smart Pascal can write Windows applications, in several ways, and some much better integrated than Delphi with the “native” platform!

    1. As a regular AJAX/HTML5 stand-alone app (plain index.html without server) running in any modern Browser.

    2. Thanks to  node-webkit http://www.delphitools.info/2012/12/13/desktop-html5-apps-game-changer-node-webkit

    3. Via the upcoming Jon’s project http://jonlennartaasenden.wordpress.com/2014/09/02/smart-mobile-studio-goes-native which targets also Windows 8 new UI, on any kind of processor

    4. Via DelphiWebScript (which is the core compiler of Smart, and has a JIT which is faster than Delphi compiler for some – specific – floating point task) http://www.delphitools.info/dwscript and here you can use regular Delphi code for full access to the Win32/Win64 API

    5. Directly writing an Windows 8 HTML5 app, and its JavaScript API

    Note that 3+4 gives full access to the Win32/Win64 API, whereas 3+5 gives access to the new WinRT API, whereas Delphi does not (and is not planned to do, AFAIK).

    Yes, SmartPascal does not support generics yet.

    But it is tempered by the fact that it has an awesome array support, and you have the classic object pascal factory pattern of “type of class” and virtual constructors.

    In practice, its support of “variant”, which maps any Javascript native object, allows to write snippets of code which are as powerful as TDoSomeThingWith.

    But I’m quite confident Eric would be able to add generics to DWS/SMS, when he would like to, and have time to refactor the compiler AST somewhat deeper. Do you remember your own discussions on http://www.delphitools.info/2012/11/21/pascalish-looking-generics-poll ? 🙂

    BTW,  are all Delphi compiler restrictions about generics (unexpected internal errors, huge exe size, slowness…) fixed with XE7?

    IMHO generics are not mandatory.

    I understand Lars Fosdal when he wrote that “Once you go Generics, there is no way back”.

    But I used to spend a lot of time in C# generics and several awesome C# libraries (pretty close to your great library, Stephan), (ab)used (of) LINQ queries, fight against WCF, RhinoMock, and Unity XML configuration files, and I still prefer “classic” object pascal code, without generics.

    Today, if I need something like a template system, I use Mustache, and generates code. If I need a factory lazy pattern for classes, I use virtual constructors. If I need stubs/mocks or factories for interfaces, a TypeInfo(IAnyInterface) does the job, without the generics overhead.

    I can see almost nothing I could do with Generics, which I could not do with regular code. Yes, I agree I can’t make my code looks like C#, but I can still follow SOLID principles, without being lost in some language-level “design patterns”, which sounds more like Lego bricks than true computer science.

    IMHO as programmers, we should +focus on data structures, not on code+. I’m sure you know the Linus’ quote, and is what I learnt by reading Knuth and others.

    Of course, this is a matter of taste.

    I spend hours in SMS for a new project, and also on latest versions of Delphi. From the syntax point of view, what I can do with SMS syntax is highly compatible with Delphi code (I can share 95% of my code with Delphi), and when I need it, the 5% SMS-specific part can unleash the power of SmartPascal over JavaScript.

    Beyond the syntax, what is amazing with Smart is that you can unleash the “good part of JavaScript” (I’m sure you read that book), when you need it.

    And even in JavaScript, thanks to Object Pascal, I can focus on data structures (like classes, arrays or records definitions), follow SOLID principles, and still have pretty good performance -even with JavaScript as intermediate language.

  6. A. Bouchez I am not saying that you cannot do quite some nice things with SMS but the point is that I am developing native windows applications (i.e. some exe with dlls that run on a windows machine) And afaik that cannot be done with SMS. And even if I can compile some application to some exe can I use DevExpress and all the other 3rd party libraries we are using for our application (several million lines of code) in it? Afaik the answer is no. So even if SMS offered the most awesome pascal syntax ever and the most advanced IDE out there it would be of no benefit to me.

Leave a Reply