Teaching C# and toplevel statements

timdams

New member
Joined
Dec 23, 2021
Messages
1
Programming Experience
10+
With the arrival of toplevel statements in C# 9 and Visual Studio 2022, the default console projects basically start out with an empty Program.cs file. Gone are the , for beginners, strange things likes class Program, namespace, endless curly braces, etc.
From the perspective of “luring” potential future C# developers into the language, toplevel statements are an interesting choice (one we’ve also seen in for example Python).
From the perspective of teaching C# however, I have some reservations, and I was wondering what other peoples insights in to this are.
Allow me to elaborate some of the upcoming pitfalls and problems I now see approaching:
  • Existing body of knowledge is suddenly outdated: 99% of all online solutions and projects are based on C# code that never had toplevel statements for more than 20 years now. For a beginner, simple looking for simple information, they will almost always immediately be confronted with non toplevel statements code examples. Thousands of good books, tutorials and videos have been made throughout the years, all teaching C# with console projects in the ‘old ways’.
  • Toplevel statements simply push a barrier a bit further down the road: in then end, beginners will have to learn to work with methods, and next up classes (note: I first teach structured programming (variables, decisions, methods) and then continue into object oriented programming (classes, interfaces, and the likes)). Leaving out the main(){} code and class program{} code at the start gives beginners the idea that C# is easy from the getgo, the moment however they then discover methods, let alone oop, they will (I’m afraid)
    • A) start writing local methods and not really grasping the core concept of why methods can be so powerful.
    • B) start screaming about the sudden appearance of all the things toplevel statements left out.
I might be old fashioned, but I feel like that it helps that student see the correct structure/relation of methods and classes from thet getgo and immediately learn that it’s not a good practice to start dumping methods anywhere you’d like.
  • Console application template in VS is fundamentally changed: Again, I understand why toplevel statements exist. But I frankly don’t understand that the default console application solutions now start with this new concept at its core. In my opinion Microsoft/VS should leave console application templates as they are, and simply create a new type template, called for example “Rapid console application prototype”. Basically, the new VS2022 console application template makes my previous two points more in your face and force everyone (using/teaching with console applications) to embrace toplevel statement, whether you want to or not.
So my rant/question is
a) How do other teachers and professionals feel about this concept
b) How do people look at toplevel statements, in conjunction with the new console application template.
c) Am I simply a 40year old C# dinosaur who should suck it up and embrace every new thingy C# throw at us (the difference with before was that new features always could be ignored more easily) ?

Wishing you a happy new year!
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,251
Location
Chesapeake, VA
Programming Experience
10+
Yes, top level statements are meant to entice the beginner, but it is also of use to old time users who just need to quickly prototype something without having to do all the ceremony to just get some procedural steps put together to see how it works and be able to step through with the debugger.

I do agree that it delays the teaching of object-oriented programming until later. Consider thought that some parts of C# is starting to lean towards doing more functional programming and immutable data structures where the procedural part within the functions matters more, does it really matter if teaching object-oriented programming and its preference for mutable objects is delayed? And also consider the other end of C# which is progressing with its use of Span<T> and Memory<T> to get speed improvements, but at the cost of writing less object-oriented code, and more procedural code. It feels like C# is breaking away or growing away (you decide?) from its object-oriented roots.

There is always a learning curve when transitioning over from writing academic code to production level code. I think that you are trying to prepare your students for that learning curve by getting them used to those with the minimal about of jarring visual and conceptual changes. Thank you for preparing future programmers this way!
 

Katherinegf

New member
Joined
Mar 25, 2022
Messages
2
Programming Experience
Beginner
Hi Skydiver, I`m looking for a teacher in c# . I have a test for a NET developer course and lokking for someone that can explain for me on a pedagogically how I do it. Thanks
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,251
Location
Chesapeake, VA
Programming Experience
10+
Sounds like @timdams is your man. I'm not really a teacher. If you have specific questions, start a new thread in the C# General subforum and I'm quite sure some people will jump in and respond.
 
Top Bottom