dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.9k stars 4.01k forks source link

Beginner Friendly Compiler Error Tooltips #50013

Open vsfeedback opened 3 years ago

vsfeedback commented 3 years ago

This issue has been moved from a ticket on Developer Community.


I teach C# for a living and one of the things I routinely see in students who are new to programming is that they see compiler errors and their brain shuts down due to the spartan nature of the error messages.

I think that you should look at the most common types of compiler errors (and potentially run-time errors as well) that new developers face and improve the error message tooltips in Visual Studio to give the new developer context-sensitive help on the error they're seeing, a beginner-friendly description of the error, some simple example bad code, and a matching fixed version.

See the below mockup for what this might look like with CS0161: Not all code paths return a value

![image](https://user-images.githubusercontent.com/46729679/102412951-10deec80-3fa9-11eb-9c2c-df194938cd5d.png)

You have no idea how far these types of changes would go to improving the accessibility of the C# language for those without a programming background. This would go a long way to improving the diversity of C# developers as well as many try to learn on their own and get discouraged by things like the existing messages

For reference, I discuss this more as well as some other issues I see new programmers having with learning C# in a blog post I wrote for the 2020 C# Advent series.


Original Comments

Patrick Kelly on 12/8/2020, 11:54 AM:

As a self-taught programmer with over a decade of experience and contributions to some major well known projects, I can back this up. When I was learning, I tried out numerous languages/compilers, and quickly became frustrated and gave up on any that had unclear error messages. This shaped what languages I was exposed to first more than any other factor. I couldn't've been the only newcomer who felt this way. Having also gone on to do some training/tutoring, although to less of an extent than Matt here, I can further attest to this being an absolute game changer in regards to training and boosting student confidence.

Feedback Bot on 12/8/2020, 11:14 PM:

Thank you for taking the time to provide your suggestion. We will do some preliminary checks to make sure we can proceed further. We'll provide an update once the issue has been triaged by the product team.

Matt Eland on 12/10/2020, 02:23 PM:

Compiler errors this would be most helpful for:

#### Iain Shepherd on 12/12/2020, 10:52 PM:

I think this would be amazing for newbies.

Have you found the corners of GitHub where .net team do their .net 6 planning? IIRC, providing an excellent experience for newbies is an explicit goal. You may find a champion for this suggestion over there

#### Stu Toms on 12/13/2020, 01:30 AM:

Such a great idea!

#### Afonso Vicente on 12/13/2020, 02:57 AM:

Excellent idea!

#### mohammad ali moaddeli on 12/13/2020, 04:04 AM:

Brilliant idea 💡

#### Ron Lease on 12/13/2020, 06:57 AM:

I taught C# at a local college for 5 years. Useful, helpful complier errors would've made learning and teaching much less frustrating. Helping new developers find a NullReferenceException is incredibly tedious, for instance.

#### Matt Eland on 12/13/2020, 08:59 AM:

@Iain Shepherd I did find that. I referenced that in a full article on this concept at Making C# More Welcoming - Kill All Defects

#### Matt Eland on 12/13/2020, 09:01 AM:

@Ron Lease NullReferenceExceptions are definitely one people struggle with. I deliberately limited the scope of this suggestion and the associated article to compile-time issues vs run-time issues since my experience has been that the compiler errors are more demoralizing and frustrating to beginners, but yes, more detailed exception details on NullReferenceException, IndexOutOfRangeException for arrays and data readers, and better verbiage around ASP .NET dependency injection errors are some of the things I'd like to see improved on the run-time error front.

mikadumont commented 3 years ago

Relates to #49993

Youssef1313 commented 3 years ago

Feels like this should be covered by the error message docs that's linked to via F1 (e.g. https://docs.microsoft.com/dotnet/csharp/misc/cs0161)?

TheArPee commented 3 years ago

Awesome idea to give clear examples!

RikkiGibson commented 3 years ago

Feels like this should be covered by the error message docs that's linked to via F1 (e.g. https://docs.microsoft.com/dotnet/csharp/misc/cs0161)?

47310 would make these docs more discoverable.