[OT] What are D's values?
Paulo Pinto
pjmlp at progtools.org
Sat Oct 9 06:50:19 UTC 2021
On Saturday, 9 October 2021 at 00:59:42 UTC, Greg Strong wrote:
> On Saturday, 9 October 2021 at 00:30:21 UTC, Adam Ruppe wrote:
>> D is realistically best suited to be a more fun C#.
>
> Yes, absolutely! I made the move from C++ to C# about 15 years
> ago. The C# ecosystem is really a pretty good place to be.
> But its metaprogramming capabilities, while once competitive,
> are now pretty unimpressive. The programming language
> state-of-the-art has come a long way in the last 20 years (even
> if most people are still using old tech.) The D language's
> CFTE is really THE game changer. I know of nothing else like
> it, and I could make some really good use of that in my C# code
> base...
>
> So I'm using D for some new projects. Of course, it has some
> other pretty innovative things too. For example, the
> scope(exit) construct. That's soooo much better than needing
> to enclose things in layer after layer of try-catch blocks.
> Other languages should all be copying this construct.
>
> Anyway, yes, D is a very compelling option for experienced C#
> developers who want to be more on the cutting edge.
I still find Roslyn compiler plugins and the code generators
quite good.
You can simulate scope(exit) with an helper struct.
```csharp
using System;
#nullable enable
// ensure this is a stack only struct
ref struct ScopeExit {
public ScopeExit(Action cleaner)
{
this.cleaner = cleaner;
}
public void Dispose()
{
try
{
cleaner();
}
catch {
// maybe do something interesting here
}
}
private Action cleaner;
}
public class Example {
public static void Main() {
using var netSocket = new ScopeExit(() => { /* clean
somethig */});
}
}
```
Naturally D's scope(exist) is cleaner to write.
More information about the Digitalmars-d
mailing list