Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. .Net Core 6 jumps the shark

.Net Core 6 jumps the shark

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpdotnetjavascriptasp-netwpf
41 Posts 14 Posters 235 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • raddevusR Offline
    raddevusR Offline
    raddevus
    wrote on last edited by
    #1

    File this one under Weird. I just built a new project in .NET Core 6 using the command:

    c:\> dotnet new console -o SuperConsole

    This produced a basic console app that outputs "Hello, World!" Then I took a look at Program.cs and noticed that the entirety of the code is:

    // See https://aka.ms/new-console-template for more information
    Console.WriteLine("Hello, World!");

    No Main Function!?! Yep, that's right. There is no main function!! Here's the link that explains it. C# template changes in .NET 6 - .NET | Microsoft Docs[^] Here's a bit of explanation from the site:

    Explanation at link:

    You can look at the code for the new application and imagine that it contains the statements inside the Main method generated by earlier templates. You can add more statements to the program, just like you can add more statements to your Main method in the traditional style. You can even add functions. They're created as local functions nested inside the generated Main method.

    I'ma no on that. Functions nested in Main? :| And it tells you that you can still add in the Main method the old way yourself and use it that way. Is C# trying to be JavaScript?

    D R S E D 9 Replies Last reply
    0
    • raddevusR raddevus

      File this one under Weird. I just built a new project in .NET Core 6 using the command:

      c:\> dotnet new console -o SuperConsole

      This produced a basic console app that outputs "Hello, World!" Then I took a look at Program.cs and noticed that the entirety of the code is:

      // See https://aka.ms/new-console-template for more information
      Console.WriteLine("Hello, World!");

      No Main Function!?! Yep, that's right. There is no main function!! Here's the link that explains it. C# template changes in .NET 6 - .NET | Microsoft Docs[^] Here's a bit of explanation from the site:

      Explanation at link:

      You can look at the code for the new application and imagine that it contains the statements inside the Main method generated by earlier templates. You can add more statements to the program, just like you can add more statements to your Main method in the traditional style. You can even add functions. They're created as local functions nested inside the generated Main method.

      I'ma no on that. Functions nested in Main? :| And it tells you that you can still add in the Main method the old way yourself and use it that way. Is C# trying to be JavaScript?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      This actually comes in handy for something I have planned for a new version of a tool I wrote for work. C# scripting support built into another DSL script.

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      raddevusR 1 Reply Last reply
      0
      • D Dave Kreskowiak

        This actually comes in handy for something I have planned for a new version of a tool I wrote for work. C# scripting support built into another DSL script.

        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
        Dave Kreskowiak

        raddevusR Offline
        raddevusR Offline
        raddevus
        wrote on last edited by
        #3

        Something that generates a separate EXE? So you don't have to generate the boiler-plate Main() method etc? Is that how it helps?

        D 1 Reply Last reply
        0
        • raddevusR raddevus

          File this one under Weird. I just built a new project in .NET Core 6 using the command:

          c:\> dotnet new console -o SuperConsole

          This produced a basic console app that outputs "Hello, World!" Then I took a look at Program.cs and noticed that the entirety of the code is:

          // See https://aka.ms/new-console-template for more information
          Console.WriteLine("Hello, World!");

          No Main Function!?! Yep, that's right. There is no main function!! Here's the link that explains it. C# template changes in .NET 6 - .NET | Microsoft Docs[^] Here's a bit of explanation from the site:

          Explanation at link:

          You can look at the code for the new application and imagine that it contains the statements inside the Main method generated by earlier templates. You can add more statements to the program, just like you can add more statements to your Main method in the traditional style. You can even add functions. They're created as local functions nested inside the generated Main method.

          I'ma no on that. Functions nested in Main? :| And it tells you that you can still add in the Main method the old way yourself and use it that way. Is C# trying to be JavaScript?

          R Offline
          R Offline
          RickZeeland
          wrote on last edited by
          #4

          Noticed that too during my escapades with VS Code and .NET Core 6.0 on Zorin OS last thursday. But at the end of the day I was glad I got the example working ... :-\

          raddevusR 1 Reply Last reply
          0
          • raddevusR raddevus

            Something that generates a separate EXE? So you don't have to generate the boiler-plate Main() method etc? Is that how it helps?

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            Kind of. The C# script would be compiled and executed without generating an .EXE on disk. It would all be in-memory. At least, that's the plan. The "script" support for previous C# versions sucks as I recall. It's been a few years since I've dabbled with it.

            Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
            Dave Kreskowiak

            J M P J 4 Replies Last reply
            0
            • R RickZeeland

              Noticed that too during my escapades with VS Code and .NET Core 6.0 on Zorin OS last thursday. But at the end of the day I was glad I got the example working ... :-\

              raddevusR Offline
              raddevusR Offline
              raddevus
              wrote on last edited by
              #6

              You were able to install VS Code & dotnet core SDK etc on Zorin and create & compile a C# program on that OS? Very interesting.

              R 1 Reply Last reply
              0
              • raddevusR raddevus

                You were able to install VS Code & dotnet core SDK etc on Zorin and create & compile a C# program on that OS? Very interesting.

                R Offline
                R Offline
                RickZeeland
                wrote on last edited by
                #7

                Yes, but Zorin OS Lite was apparently not a good choice for bleeding edge things like .Net Core 6.0. Things probably would have been easier on the newer Zorin OS full version using the "Snap package manager". Btw. in this video the new and strange ways of .NET Core 6.0 are explained: Hello World: .NET 6 and .NET Conf - YouTube[^]

                raddevusR 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  Kind of. The C# script would be compiled and executed without generating an .EXE on disk. It would all be in-memory. At least, that's the plan. The "script" support for previous C# versions sucks as I recall. It's been a few years since I've dabbled with it.

                  Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                  Dave Kreskowiak

                  J Offline
                  J Offline
                  Jon McKee
                  wrote on last edited by
                  #8

                  I use dotnet-script. No real complaints from me. Easy to install dotnet tool install -g dotnet-script Easy scaffolding in VS Code (for debug support) dotnet script init Easy to execute dotnet script You can skip the second step if you just want to execute stuff with no debug support.

                  D 1 Reply Last reply
                  0
                  • J Jon McKee

                    I use dotnet-script. No real complaints from me. Easy to install dotnet tool install -g dotnet-script Easy scaffolding in VS Code (for debug support) dotnet script init Easy to execute dotnet script You can skip the second step if you just want to execute stuff with no debug support.

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #9

                    Not usable in my situation. I have to include any libraries in the resulting .EXE and distribute a single executable. Using any "dotnot" commands will not work for me.

                    Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                    Dave Kreskowiak

                    1 Reply Last reply
                    0
                    • R RickZeeland

                      Yes, but Zorin OS Lite was apparently not a good choice for bleeding edge things like .Net Core 6.0. Things probably would have been easier on the newer Zorin OS full version using the "Snap package manager". Btw. in this video the new and strange ways of .NET Core 6.0 are explained: Hello World: .NET 6 and .NET Conf - YouTube[^]

                      raddevusR Offline
                      raddevusR Offline
                      raddevus
                      wrote on last edited by
                      #10

                      Thanks for the link directly to that section of that longer video. that was great addt'l info on this. :thumbsup:

                      1 Reply Last reply
                      0
                      • raddevusR raddevus

                        File this one under Weird. I just built a new project in .NET Core 6 using the command:

                        c:\> dotnet new console -o SuperConsole

                        This produced a basic console app that outputs "Hello, World!" Then I took a look at Program.cs and noticed that the entirety of the code is:

                        // See https://aka.ms/new-console-template for more information
                        Console.WriteLine("Hello, World!");

                        No Main Function!?! Yep, that's right. There is no main function!! Here's the link that explains it. C# template changes in .NET 6 - .NET | Microsoft Docs[^] Here's a bit of explanation from the site:

                        Explanation at link:

                        You can look at the code for the new application and imagine that it contains the statements inside the Main method generated by earlier templates. You can add more statements to the program, just like you can add more statements to your Main method in the traditional style. You can even add functions. They're created as local functions nested inside the generated Main method.

                        I'ma no on that. Functions nested in Main? :| And it tells you that you can still add in the Main method the old way yourself and use it that way. Is C# trying to be JavaScript?

                        S Offline
                        S Offline
                        Super Lloyd
                        wrote on last edited by
                        #11

                        Are you new to C#? this has been in C# since C#7 / .NET.. err.. 4.7? [Local functions - C# Programming Guide | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/local-functions)

                        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                        Richard DeemingR 1 Reply Last reply
                        0
                        • raddevusR raddevus

                          File this one under Weird. I just built a new project in .NET Core 6 using the command:

                          c:\> dotnet new console -o SuperConsole

                          This produced a basic console app that outputs "Hello, World!" Then I took a look at Program.cs and noticed that the entirety of the code is:

                          // See https://aka.ms/new-console-template for more information
                          Console.WriteLine("Hello, World!");

                          No Main Function!?! Yep, that's right. There is no main function!! Here's the link that explains it. C# template changes in .NET 6 - .NET | Microsoft Docs[^] Here's a bit of explanation from the site:

                          Explanation at link:

                          You can look at the code for the new application and imagine that it contains the statements inside the Main method generated by earlier templates. You can add more statements to the program, just like you can add more statements to your Main method in the traditional style. You can even add functions. They're created as local functions nested inside the generated Main method.

                          I'ma no on that. Functions nested in Main? :| And it tells you that you can still add in the Main method the old way yourself and use it that way. Is C# trying to be JavaScript?

                          E Offline
                          E Offline
                          Eusebiu Marcu
                          wrote on last edited by
                          #12

                          I think they are going after two main areas: be more like python (REPL approach) and be more like node (see the new asp.net 6 project templates).

                          Eusebiu

                          1 Reply Last reply
                          0
                          • S Super Lloyd

                            Are you new to C#? this has been in C# since C#7 / .NET.. err.. 4.7? [Local functions - C# Programming Guide | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/local-functions)

                            A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                            Richard DeemingR Offline
                            Richard DeemingR Offline
                            Richard Deeming
                            wrote on last edited by
                            #13

                            Super Lloyd wrote:

                            .NET.. err.. 4.7?

                            The version of .NET is irrelevant; it's the compiler and language version that matters. The compiler turns local functions into code that would work in pretty-much any version of .NET - either static functions, instance functions, or functions on a closure class, depending on what you've referenced in the local function. Eg:

                            void Foo()
                            {
                            int Bar() => 42;
                            Console.WriteLine(Bar());
                            }

                            becomes something similar to:

                            [CompilerGenerated]
                            internal static int <Foo>g__Bar|0_0()
                            {
                            return 42;
                            }

                            void Foo()
                            {
                            Console.WriteLine(<Foo>g__Bar|0_0());
                            }


                            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                            1 Reply Last reply
                            0
                            • raddevusR raddevus

                              File this one under Weird. I just built a new project in .NET Core 6 using the command:

                              c:\> dotnet new console -o SuperConsole

                              This produced a basic console app that outputs "Hello, World!" Then I took a look at Program.cs and noticed that the entirety of the code is:

                              // See https://aka.ms/new-console-template for more information
                              Console.WriteLine("Hello, World!");

                              No Main Function!?! Yep, that's right. There is no main function!! Here's the link that explains it. C# template changes in .NET 6 - .NET | Microsoft Docs[^] Here's a bit of explanation from the site:

                              Explanation at link:

                              You can look at the code for the new application and imagine that it contains the statements inside the Main method generated by earlier templates. You can add more statements to the program, just like you can add more statements to your Main method in the traditional style. You can even add functions. They're created as local functions nested inside the generated Main method.

                              I'ma no on that. Functions nested in Main? :| And it tells you that you can still add in the Main method the old way yourself and use it that way. Is C# trying to be JavaScript?

                              D Offline
                              D Offline
                              den2k88
                              wrote on last edited by
                              #14

                              BASIC -> QBASIC -> VisualBasic -> C# -> BASIC -> ... VB7?

                              GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                              1 Reply Last reply
                              0
                              • raddevusR raddevus

                                File this one under Weird. I just built a new project in .NET Core 6 using the command:

                                c:\> dotnet new console -o SuperConsole

                                This produced a basic console app that outputs "Hello, World!" Then I took a look at Program.cs and noticed that the entirety of the code is:

                                // See https://aka.ms/new-console-template for more information
                                Console.WriteLine("Hello, World!");

                                No Main Function!?! Yep, that's right. There is no main function!! Here's the link that explains it. C# template changes in .NET 6 - .NET | Microsoft Docs[^] Here's a bit of explanation from the site:

                                Explanation at link:

                                You can look at the code for the new application and imagine that it contains the statements inside the Main method generated by earlier templates. You can add more statements to the program, just like you can add more statements to your Main method in the traditional style. You can even add functions. They're created as local functions nested inside the generated Main method.

                                I'ma no on that. Functions nested in Main? :| And it tells you that you can still add in the Main method the old way yourself and use it that way. Is C# trying to be JavaScript?

                                M Offline
                                M Offline
                                Member 9167057
                                wrote on last edited by
                                #15

                                That's a simple continuation of the "pay for play" philosophy. While the unavailability of the Main function is a thing I really hate about Python (how the hell am I supposed to know where complex code starts operating), it's absence is a huge win for small code bases. Don't get me wrong, for a kLoC of code, spread across 4 or so different modules, the lack of structure which this particular C# template brings to the table would be a bloody nightmare (which is why I'm not using this style for my kLoC-multimodule project). But for something of only mild complexity, that's a win. Boilerplate code, like any other overhead, starts paying off eventually, but if you have something not nearly huge enough for that overhead to pay off, low-overhead alternatives rule. Take file system as an example. NTFS (or ext, if you're so inclined) is by orders of magnitude more advanced, than FAT. Yet, FAT (be it FAT32 or exFAT) got it's own raison d'etre, which is low-requirements-low-overhead. PS: that part that you highlighted, namely local functions, is older, than .NET 6. They started with C# 7.0 which started it's life with .NET 4*x.

                                1 Reply Last reply
                                0
                                • raddevusR raddevus

                                  File this one under Weird. I just built a new project in .NET Core 6 using the command:

                                  c:\> dotnet new console -o SuperConsole

                                  This produced a basic console app that outputs "Hello, World!" Then I took a look at Program.cs and noticed that the entirety of the code is:

                                  // See https://aka.ms/new-console-template for more information
                                  Console.WriteLine("Hello, World!");

                                  No Main Function!?! Yep, that's right. There is no main function!! Here's the link that explains it. C# template changes in .NET 6 - .NET | Microsoft Docs[^] Here's a bit of explanation from the site:

                                  Explanation at link:

                                  You can look at the code for the new application and imagine that it contains the statements inside the Main method generated by earlier templates. You can add more statements to the program, just like you can add more statements to your Main method in the traditional style. You can even add functions. They're created as local functions nested inside the generated Main method.

                                  I'ma no on that. Functions nested in Main? :| And it tells you that you can still add in the Main method the old way yourself and use it that way. Is C# trying to be JavaScript?

                                  M Offline
                                  M Offline
                                  MSBassSinger
                                  wrote on last edited by
                                  #16

                                  There are a number of shorthand changes (but little innovation) that have been made to C# over the years that are of limited or questionable value. It is a good idea to test out these shorthand C# changes, then look at what the compiler does with them by looking at the generated MSIL. As one example, having done that, it is why I no longer use "using" for IDisposable objects. If you like a particular shortcut, use it. But my advice is to at least know what the compiler does with it. In the case of the OP, just make your own Main() and go with it.

                                  J 1 Reply Last reply
                                  0
                                  • D Dave Kreskowiak

                                    Kind of. The C# script would be compiled and executed without generating an .EXE on disk. It would all be in-memory. At least, that's the plan. The "script" support for previous C# versions sucks as I recall. It's been a few years since I've dabbled with it.

                                    Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                                    Dave Kreskowiak

                                    M Offline
                                    M Offline
                                    MSBassSinger
                                    wrote on last edited by
                                    #17

                                    I did that a few years ago. It makes a nice scripting utility. I had to figure out what shortcuts in the IDE were not in the compiler, but that did not take long. Mine worked out well, and I used it in a production app. I added in some safeguards, like making sure the C# script had not been tampered with (lots of opportunity for a disgruntled employee to alter an existing script to wreck havoc on production systems).

                                    1 Reply Last reply
                                    0
                                    • raddevusR raddevus

                                      File this one under Weird. I just built a new project in .NET Core 6 using the command:

                                      c:\> dotnet new console -o SuperConsole

                                      This produced a basic console app that outputs "Hello, World!" Then I took a look at Program.cs and noticed that the entirety of the code is:

                                      // See https://aka.ms/new-console-template for more information
                                      Console.WriteLine("Hello, World!");

                                      No Main Function!?! Yep, that's right. There is no main function!! Here's the link that explains it. C# template changes in .NET 6 - .NET | Microsoft Docs[^] Here's a bit of explanation from the site:

                                      Explanation at link:

                                      You can look at the code for the new application and imagine that it contains the statements inside the Main method generated by earlier templates. You can add more statements to the program, just like you can add more statements to your Main method in the traditional style. You can even add functions. They're created as local functions nested inside the generated Main method.

                                      I'ma no on that. Functions nested in Main? :| And it tells you that you can still add in the Main method the old way yourself and use it that way. Is C# trying to be JavaScript?

                                      Z Offline
                                      Z Offline
                                      zezba9000
                                      wrote on last edited by
                                      #18

                                      Even VS 2022 does this. I hate it & its not the correct way to be writing anything in C#.

                                      1 Reply Last reply
                                      0
                                      • M MSBassSinger

                                        There are a number of shorthand changes (but little innovation) that have been made to C# over the years that are of limited or questionable value. It is a good idea to test out these shorthand C# changes, then look at what the compiler does with them by looking at the generated MSIL. As one example, having done that, it is why I no longer use "using" for IDisposable objects. If you like a particular shortcut, use it. But my advice is to at least know what the compiler does with it. In the case of the OP, just make your own Main() and go with it.

                                        J Offline
                                        J Offline
                                        Jon McKee
                                        wrote on last edited by
                                        #19

                                        Could you expand on what you meant by the using example? From what I can see, these end up equivalent:

                                        using (SomeResource res = new SomeResource())
                                        {
                                        //using block
                                        }
                                        //-------------
                                        SomeResource res = new SomeResource();
                                        try
                                        {
                                        //using block
                                        }
                                        finally
                                        {
                                        if (res != null)
                                        ((IDisposable)res).Dispose();
                                        }

                                        which seems right to me.

                                        M 1 Reply Last reply
                                        0
                                        • J Jon McKee

                                          Could you expand on what you meant by the using example? From what I can see, these end up equivalent:

                                          using (SomeResource res = new SomeResource())
                                          {
                                          //using block
                                          }
                                          //-------------
                                          SomeResource res = new SomeResource();
                                          try
                                          {
                                          //using block
                                          }
                                          finally
                                          {
                                          if (res != null)
                                          ((IDisposable)res).Dispose();
                                          }

                                          which seems right to me.

                                          M Offline
                                          M Offline
                                          MSBassSinger
                                          wrote on last edited by
                                          #20

                                          In short, the using statement swallows constructor errors. Since the actual code being executed is a try … finally, why not just use try … finally (or better yet, try… catch … finally) and use your own code for capturing and logging all exception? And given the unpredictability of the GC, scalability is better served by following the principle, “if you create an object, clean it up when done with it”. Relying on the GC and using shortcuts like the using statement are things I consider poor engineering choices in the context of the SDLC. Others may disagree, but I have yet to see a reasoned argument against my approach that ends in better software.

                                          J 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups