Quantcast
Channel: Scott Hanselman's Blog
Viewing all articles
Browse latest Browse all 1148

Tiny top-level programs with C# 9 and SmallSharp and Visual Studio

$
0
0

One of the things I'm always working on and am always excited about is making C# simpler for new folks.

With .NET 5, today, this works, as it includes C# 9

> dotnet new console

The template "Console Application" was created successfully

> echo System.Console.WriteLine("Hello World"); > program.cs

> dotnet run
Hello World

That's C# 9 top level programs. We should be able to remove even more. Skip the first command completely and do it all on one line, one file.

A hello world is either

using System;


Console.WriteLine("Hello World!");

or

System.Console.WriteLine("Hello World!");

or, scandalously

using System;

using static System.Console;

WriteLine("Hello World!");

Not sure how I feel about that last one. Regardless...would this work in Visual Studio 2019? What if I was teaching a class and wanted to have one file per homework assignment, for example? Right now Visual Studio only supports one top-level program per project. Make sense why, but for learning, why not allow folks to choose from the run/debug menu?

I'm going to add a reference to SmallSharp like this (or in Visual Studio)

> dotnet add package smallsharp

Now here's what my homework looks like in Visual Studio 2019! There's one menu item per top level program!

One menu item per top level program

This lovely prototype was done by Daniel Cazzulino (kzu) and you can learn more at https://github.com/devlooped/SmallSharp, or just try it out as I have here!

What do you think? How can small top-level programs help new people?

What about this?

> dotnet new microservice

> dotnet run

Sound off in the comments. How tight and simple would that be?


Sponsor: Tired of not finding the code you're looking for? Get Sourcegraph universal code search and search code across ALL your repos, languages, and code hosts. Find and fix code fast with Sourcegraph. Try it now!



© 2020 Scott Hanselman. All rights reserved.
     

Viewing all articles
Browse latest Browse all 1148

Trending Articles