C# Hard Truths: Program.cs was a Lie, Startup.cs is a Waste of Space, and more...

preview_player
Показать описание

Recently, I have heard from a number of seasoned developers that they dislike the simplification of C# in .NET 6 and beyond. The thought is that top level statements and other major changes hid too much and that the original way was better.

In this video, I am going to show you why the new ways of doing things in .NET 6 and beyond actually promote better programming practices.

Рекомендации по теме
Комментарии
Автор

Firstly, I love how both old and new conventions are perfectly valid. Zooming back to when I graduated from BASIC/QBASIC to C++... circa 1994, armed with only a book to reference and no internet... I recall struggling to learn what the heck all the boilerplate stuff meant-- #include stdio.h, using namespace std, etc. Being young and just starting out at the time, it was all pretty intimidating. I always felt there were some basic concepts that I was missing that my book wasn't covering. I remember throwing lots of time at trying to understand concepts that were really too advanced when I was starting out. As a result, it sort of pushed me away from C++ at the time, and into Visual Basic. So, although as a Sr Engineer, sometimes I appreciate the ceremony, certainly for someone just starting out, simple is better.

codefoxtrot
Автор

I completely disagree with why you think this is a good thing. Developing software is defined by a structure and proper syntax. When you are trying to learn something new and all the aspects of a C# application are missing and you don't have to put those things there, you run into issues when you need to expand on those magic things you keep talking about. Now a new user gets confused when they create a class file that has all the files, when you remove the basic structure of an application and make it happen magically, you make it harder for people to learn and follow the code.

Like you pointed out about the Args missing and I have to magically know about them, makes me upset. Magic is now how I learn. I need it to have structure and make sense. I need to easily follow the code. This new way is not easy following the code and understanding what is happening. I know you think its less code, but it doesn't flow real well when it comes to the basic structure of a C# code of Namespace, Class and Methods.

My first thought is how do I create that as an Async Main method? Do I have to go back to the old way? Now I would have to spend time trying how to figure out how to make the Main method Async when there is no Main method.

coryjorgensen
Автор

The program Entrypoint is set in the project properties, and is easy to change.

Recursion is an extremely valuable technique.

Calling Main() can be useful in certain situations, especially when you're CLI-focused, and not GUI focused.

You absolutely can reference and call this method, and there's no rules that say you can't.

I'd say this is a terrible primer for a new developer, as it makes a lot of categorically false statements.

peter.dolkens
Автор

I am an "old schooler" who thought the top-level statements feature was senseles.

However, you have made a compelling argument and you have converted me.

jasonrichmeier
Автор

Oh wow, this video is a great explanation of the changes/features happening with C#. I'm new to both C# & OOP and I've been using PHP while coding in a procedural style for about 95% of the time. At first glance, this seems like a good idea to introduce coding in a gentle way by avoiding a lot of OOP and its syntax namespaces, class, using etc, but in the long run, this method could teach beginners the bad and very hard-to-break habits I picked up while in procedural code land while in the PHP camp and this could do more harm than good for beginners like myself who wants a career in development one day.

chriswinslow
Автор

MS decided to have own Java and made C#, and now like to move to language as Python:)

vencislavvidov
Автор

I love the new structure since .NET 6. I have worked on versions from .NET 1.1 and I can say that this is so much better. It did take me some time to get used to it though.

The new structure is less clutter and more readable(no unnessary braces and indentations throughout the file). I also like how it hides not so essential details to writing your application but does not completely remove them to the point that those who want to learn the inner workings cannot access the information.

It's DRY, it's abstraction, it's simplicity. It's just great.

jsgovind
Автор

One unfortunate thing about top-level-statements is that they are a bad way to learn about accessibility as top-level variables are visible in (local) methods which they would'nt be in the classic way.

peterb.
Автор

Generics, Linq, async-await... Those were great improvements. But the latest changes to the C# language are mainly about saving a few characters. It's ridiculuous and just getting on my nerves to spend precious developer time just to find out what useless changes have been added this time again to the C# language. At least I get paid for it by my employer. And then there are those colleagues who rewrite the whole code because they think these useless changes would improve their code quality.

Munde
Автор

Im a relatively new developer and still have a good memory of how i learned to code. For me the static void main and his friends was a huge help and motivation to learn. Every time when i had to create a learning project these keywords(static, void, public ect..) were right there and yes it was annoying and scary first but then i was able to track my learning progress with these. These keywords were like a path for me to take and understand them one by one. Im a bit sad that the new generation will not have the feeling when they sit down one day and look on the main method and be proud for understanding all of it. This feeling gave me a big boost at the time and a good milestone for the learning process.

axmart
Автор

Well, that explains a lot, I saw this weird logic, I was confused but it worked so I did not care.
Thanks again Tim!

davidbaity
Автор

Not a "lie". Just a place indicating where to start. If you prefer the new way then that is fine. That's what this comes down to. Preference. Just don't call it a "lie". Comes across as clickbait.

topher
Автор

I know it’s unwarranted, but it freaks me out to not see using statements. It’s like “Hey, I can’t run this without using statements.” I know that’s not true, but still weirds me out.

ElCidPhysics
Автор

From a learning perspective IE someone who learned C# within the past year for work, the old program was more useful for learning. Especially since I was relatively new to OOP. I do like the convenience of the new program file, but I think for beginners that boilerplate is actually important to understand.

DanLockwood
Автор

I don’t like how you can write functions effectively inside of your main.

ufailowell
Автор

As someone who has recently been learning C# on my own, I will say that whatever advantages these changes might have had for new learners are pretty heavily offset by the fact that now all the tutorials from before a certain cutoff point don't work the way the websites and books say they will. Learning how C# has changed and how to modify tutorials to accommodate those changes is pretty exhausting when you're brand-new and don't understand the documentation yet.

chris
Автор

they could have left the static void/int Main(string[] args) at top level because having a return 0/1/2/-1 ... at top level is really weird.

on the global using thing. the reason I don't like them is because they remove the "file can compile on its own" philosophy.

PierreVONDERSCHER
Автор

Yeah, At the start, I was getting frustrated with the new way of .NET 6.
However, the more new project I started, the more it make sense.
It is just the same, but cleaner.

hankai
Автор

I've been on the fence and one of your other videos you talked about this didn't really sell me. This was much more compelling, and I can't think of a reason not to agree. Good job.

TheVentureaaron
Автор

I'm afraid I disagree. Top level and implied usings are not an improvement. They hide certain constructs that newcomers really should understand. Not everyone that learns C# has a computer science degree. It also makes the transfer to/from C, C++ and Java more traumatic. I could just be getting old but I believe change should make things clearer and I don't think this does. Still keep up the great work. 🙂

shaunstewart