C# 9 top-level programs and target-typed expressions
171–180 of 188 posts
Re: C# 9 top-level programs and target-typed expressions
#172Earlier quoted context omitted.
Consistency, mostly. It's all methods on classes everywhere else, why make it different here? Even with "top level statements" the startup code is wrapped in a "main" method, it's just compiler-generated in this case. The CLR insists that code statements are always in method on classes, I believe. In cases where it appears otherwise (e.g. a lambda) the compiler is generating a wrapper class.
Because it’s just noise that doesn’t mean anything to me, so why keep it? Same as type inference, expression-bodied members, and other LOC savers.
I guess the point is that your substantial program will also have plenty of classes and methods elsewhere, so the idea that "you can do a one-liner without having to first learn about declaring classes and methods and namespaces" isn't relevant to you. You save a few LOC 1 time over in your top-level entry point though. OK.
Re: C# 9 top-level programs and target-typed expressions
#173Earlier quoted context omitted.
Because it’s just noise that doesn’t mean anything to me, so why keep it? Same as type inference, expression-bodied members, and other LOC savers.
So you're going to go with a top-level entry point even with a substantial program? OK, I can see that happening. I guess the point is that your substantial program will also have plenty of classes and methods elsewhere, so the idea that "you can do a one-liner without having to first learn about declaring classes and methods and namespaces" isn't relevant to you. You save a few LOC 1 time over in your top-level entr…
Re: C# 9 top-level programs and target-typed expressions
#174Earlier quoted context omitted.
> top level is mostly going to be nice when teaching new programmers. You can just get on with hello world Yeah it seems like kind of a weird thing? “Here’s marginally less boilerplate once , if someone is going to learn to use the language, they may as well learn how it actually works instead of hiding stuff that they’ll soon see anyways...
This isn't a REPL but the benefits are almost identical Good for beginners, good for removing the overhead of "trying just one quick thing real quick"
Re: C# 9 top-level programs and target-typed expressions
#175Earlier quoted context omitted.
The C# language design process is very much in the open, so anybody can go and take a look at the rationale etc. https://github.com/dotnet/csharplang
I think it suffers from the design by a self-selected committee now. Very little of recent changes have long-term vision behind them now, and seem to be quick patches. Specifically, I just tried disabling 7.0+ features in an open source project I run, and we only actively used pattern matching for "is MyType inst", ref structs (hi Rust!, that one is really fundamental), and natively sized integers (which are still po…
And it's not surprising that an existing large C# codebase wouldn't use many of those features. But for new projects, they are very nice.
Re: C# 9 top-level programs and target-typed expressions
#176Earlier quoted context omitted.
I think it suffers from the design by a self-selected committee now. Very little of recent changes have long-term vision behind them now, and seem to be quick patches. Specifically, I just tried disabling 7.0+ features in an open source project I run, and we only actively used pattern matching for "is MyType inst", ref structs (hi Rust!, that one is really fundamental), and natively sized integers (which are still po…
You don't consider the more advanced pattern matching stuff to be "long-term vision"? And it's not surprising that an existing large C# codebase wouldn't use many of those features. But for new projects, they are very nice.
Re: C# 9 top-level programs and target-typed expressions
#177Earlier quoted context omitted.
What's your go to boiler plate for a new TypeScript project?
The three most popular kinds of TypeScript projects I create are: - Node.js services built with Serverless framework targeting AWS Lambda - Create React App front-ends - Gatsby front-ends For the first, I have a single shared webpack config that I reuse for all my serverless services. For the front-end projects, I just followed the few steps to add TypeScript support to CRA and Gatsby.
- Lambda Authorizers for token auth (or use the built-in stuff if you can get away with it)
- Lambda w/ API Gateway for individual endpoints
- Aurora for relational dbms
It's really a nicely put together ecosystem.
Re: C# 9 top-level programs and target-typed expressions
#178Earlier quoted context omitted.
Why not bother? This mindset is one of the core features of .NET-land - Microsoft just goes ahead and implements anything useful. It's why we have a gigantic standard library ("framework") filled with every function under the sun and some multiple times. We didn't have to wait until C++20 to get string.Contains. Sometimes the features Microsoft implements are more useful than others but most of them are a little usef…
It's not without its downsides though, the language and ecosystem is quite big now. I don't envy people starting out and having to learn it all from scratch.
Most of the improvements that have been made in the last 10 years (aside from maybe async/await, but that pattern is pretty ubiquitous at this point) have served to reduce the amount of idiosyncrasies, not increase them.
In general, web programming has increased across-the-board in complexity manifold, regardless of your server-side language. Aside from that I find writing C# to be very succinct and logical these days compared to the past, even taking into account my own learning.
Re: C# 9 top-level programs and target-typed expressions
#179Earlier quoted context omitted.
Oh, I get it. You mean install some sort of interpreter that is called by the OS for that language. Sorry, I live in real world, where customers don't allow you to install a gazzilion files just to run your application, they expect a proper installer that is under strict supervision by their admin team and you only deliver executables.
I don’t think the use case for this is anything you’re shipping to “customers”... more for just personal code you can use as scripts/playgrounds. To use the swift example, often I want to double check whether something in the language works as I expect, so I write a quick test.swift and run it. It’s a useful thing even if you don’t personally want it.
Re: C# 9 top-level programs and target-typed expressions
#180I really love c# - one of my favrorite languages, but can any one explain the benefit of this new syntax? Person p1 = new(); Person p2 = new("Tom"); Person p3 = new() { FirstName = "Tom" };
public class SignPost {
public List Messages { get; set;} = new();
private List Errors = new();
}
In both of the above usages var is not allowed. Often-times instead of a simple list you have something like an IReadOnlyCollection or an equally-abominable custom type that is just a pain to write out 2x for every time you add it as a dependency somewhere.