Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make C# more beginner friendly #1469

Closed
gulshan opened this issue Apr 21, 2018 · 16 comments
Closed

Make C# more beginner friendly #1469

gulshan opened this issue Apr 21, 2018 · 16 comments

Comments

@gulshan
Copy link

gulshan commented Apr 21, 2018

As great as the language C# is, currently I don't see it is being used for introduction to programming that much. Beginning programming with some language increses it's mindshare and markertshare in my opinion. So, I would like to raise some points which I think will make C# more "beginner friendly". Many of these are found from comparison with Python (which is kind of first choice for beginners nowadays'). And while some of them are language issues, some others are about tooling or library. But I'm keeping all of them together here.

  • Acquisition
    The first thing one has to do to get start with C# is to install C#/.net sdk. And the easiest acquisition is no acquisition at all. Some languages like python comes bundled with various OSes. It will be most convenient for a beginner if the dotnet sdk comes bundled with various OSes. I think Microsoft can (and should) bundle it with Windows and talk to Linux distributions to bundle it. And then, .net sdk should be officially available from apt, brew, chocolatey and likes for easier distribution/acquisition/update.

  • Running in browser
    Another way to get started is running in browser. This is an important option as this also does not require any installation and run on devices with limited development support like iOS/Android devices. Currently there are various third party services and even 1st-party solutions from Microsoft. But the process should more readily available, adopted and highlighted in various ways where appropriate like documentation and tutorials (both first party and third party).

  • Run single file
    When someone is just starting to learn programming, creating a "project", whether visually or through command line dotnet new is a hurdle s/he has to overcome. So, it will be helpful for beginners if a single file can be run with a single command. Something like dotnet run file.cs will be useful.

  • Focus on scripts
    Even more convenient for a beginner to start with scripts instead of code files. In hello world is a one liner and what it does is quite obvious from the code itself. While in a source file, a beginner have to use using, class, static and other constructs without knowing what they mean just to start. Also with scripts(and convenient configuration), the file itself is executable, which will be easier for a beginner to run. Current scripting support in .net sdk is almost invisible.

  • More textual constructs
    Programming languages resembling more to human language(English to be specific) is easier to begin with. So, if not(...) and while not(...) will be much more easier to understand than if(!(...)) and while(!(...)). Then again there can be an until loop in place of while not. Then there can be do until like do while. There can be a loop{...} forever loop. And some textual alternative to conditional ?: operator will also be easier to catch. even there can be try when in the place of try catch etc. We can look for some other such constructs.

  • list and dictionary syntax
    In the beginner level, before learning custom and complex data types, programmers usually learn and use lists and dictionaries. These are the two most fundamental collections types. But in C# using these two types are not very ergonomic for the beginners IMHO. One has to use new and generic angle brackets <> for using lists and dictionaries without much or any idea. So, I would suggest to improvise list dictionary syntax, much like what was done for tuples. Currently (1, "a") is a tuple and the type is (int, string). So simple matching between declaration and type. Same should be done for lists and dictionary- [1, 2, 3] should be a list of type [int] and [1:"a", 2:"b"] is a dictionary of type [int:string]. Or, curly braces can be used in the place of square brackets- {1, 2, 3} is a list of type {int} and so on.

  • Immutability
    How something like x = x + 1 is a valid statement is one of the most common questions beginners ask. Immutability make things easier to make sense of. Clear distinction between mutable and immutable variables in syntax helps a lot. So, local immutables with let will make the life easier for beginners IMO.

  • Basic graphics and chart/graph library
    It's very common to use graphics for making programming more interesting for the beginners. So, availability of a cross platform easy to use basic (2D) graphic library in .net/C# will be awesome. So will be a readily available chart/graph library.

Most of these are already proposed. I am just posing them together with a focus on simplicity for the beginners.

@HaloFour
Copy link
Contributor

HaloFour commented Apr 21, 2018

  • Acquisition - Not an concern of the language, take it to CoreCLR
  • Running in browser - Same as above
  • Focus on scripts - C# Scripting exists already, unless you're claiming that C# scripting syntax should also be compilable, which it's currently not as C# scripting does have that very relaxed REPL syntax that you describe
  • More textural constructs - This is a highly subjective statement. Having more keywords would make the language more complicated, not easier to learn. Having many different ways to do the same thing is generally not a good thing.
  • list and dictionary syntax - literals could be a good idea, but at the same time they enshrine only specific types and make those types opaque which I don't think is necessarily a good thing. C# has initialization syntax which makes creating/populating collections simple and doesn't lock you into any particular implementation.
  • Immutability - C# is a mutable language, that's not going to change. There's nothing about immutability that makes a language easier to learn, unless you're coming from another immutable language. Coming from another mutable language it would make C# much more difficult to learn. I think that the debate and design around tuples clearly describes how the language designers feel about trying to enforce something like immutability.
  • Basic graphics and chart/graph library - Not a concern of the language, take it to CoreFX

This repository is specifically about changes to the language specification. Most of your "proposals" don't involve language changes and the others I feel are already covered by other proposals so I don't think that your meta-proposal is particularly necessary.

@svick
Copy link
Contributor

svick commented Apr 21, 2018

I think Microsoft can (and should) bundle [.net sdk] with Windows

Which version of the SDK and runtime? A Windows installation can live for many years, but an important feature of the .Net Core SDK is that various versions of it can live side-by-side (and are not interchangeable). So what policy should Windows use to decide which version of the SDK and runtime to install and upgrade?

I think Microsoft can (and should) […] talk to Linux distributions to bundle it

I think one reason why this hasn't happened yet is that .Net Core SDK wasn't buildable from source (it required some binary assets). But fixing that is underway at dotnet/source-build, so I hope .Net Core SDK will start showing up in official repositories of Linux distributions in the near future.

But the process [of running in browser] should more readily available, adopted and highlighted in various ways where appropriate like documentation and tutorials (both first party and third party).

The official docs gained the ability to run code in the browser fairly recently. I expect more and more documentation will be converted to use that approach over time (and you can help by submitting PRs).

When someone is just starting to learn programming, creating a "project", whether visually or through command line dotnet new is a hurdle s/he has to overcome. So, it will be helpful for beginners if a single file can be run with a single command. Something like dotnet run file.cs will be useful.

I think running a single .cs file doesn't make much sense, but running a .csx (C# script) file is a great idea. According to https://github.com/dotnet/cli/issues/2336#issuecomment-259597011, scripting is not going to be part of .Net Core SDK itself.

But .Net Core 2.1 will have better support for tools like filipw/dotnet-script. With that, you should be able to do this:

dotnet install tool -g dotnet-script
dotnet script file.csx

I think that's good enough.

Focus on scripts

I mostly agree, see above.

Programming languages resembling more to human language(English to be specific) is easier to begin with.

I don't think this is a good idea. Even if it made learning the language slightly easier, I think it would still make the language worse overall.

list and dictionary syntax

There are proposals for that: #1238 or #1399.

So, local immutables with let will make the life easier for beginners IMO.

Isn't learning two different syntaxes (var and let) actually harder? Whether you like it or not, mutable variables are and will be an important part of programming in C#. I think beginners should learn about them, even if good support for immutable variables existed in C#.

@svick
Copy link
Contributor

svick commented Apr 21, 2018

@HaloFour

This repository is specifically about changes to the language specification. Most of your "proposals" don't involve language changes and the others I feel are already covered by other proposals so I don't think that your meta-proposal is particularly necessary.

Do you know of a good place where such overarching discussions can take place?

While ensuring that discussion stays on-topic is to some degree necessary (especially when it comes to details about issues that belong to some other repo), I think being too strict about isolating discussions into their respective repos can be harmful to the community.

@HaloFour
Copy link
Contributor

@svick

Do you know of a good place where such overarching discussions can take place?

Out of the dotnet repos I honestly don't know. They all seem to direct unrelated conversations to the other repos to keep their Issues section on topic. Some direction from MS might be a good idea here.

That said, in this case I don't necessarily think there is an overarching theme. Each of the proposals above are disparate and orthogonal and only loosely bound by the subjective notion that they would make C# easier to learn.

@ufcpp
Copy link

ufcpp commented Apr 21, 2018

Running in browser: https://try.dot.net/ https://github.com/dotnet/try
list and dictionary syntax: #414 #1238

@sharwell
Copy link
Member

The interesting thing about beginners is they never stay that way for long. One of the following will happen:

  1. They lose interest and stop using the language
  2. They stop being beginners and move on to "advanced"

It's important to keep the second in mind while trying to avoid the first¹. Features aimed at beginners should only be implemented if they continue to be useful features of non-beginners. Otherwise the whole situation becomes a bait-and-switch, making it much harder to move on from being a beginner.

¹ It's fine to lose interest if programming isn't what you want to do in life, but we want strong retention for programmers interested in solving problems for which C# is a good fit among one or more available options.

@gulshan
Copy link
Author

gulshan commented Apr 21, 2018

Features aimed at beginners should only be implemented if they continue to be useful features of non-beginners.

Agreed. But usefulness is subjective IMO.

@sharwell
Copy link
Member

sharwell commented Apr 21, 2018

@gulshan Here's my initial comments on the original post:

@KathleenDollard
Copy link
Collaborator

I agree that C# can be easier for beginners.

Some of the language changes you propose are already available in VB. Why not encourage beginners there?

I have watched several beginners struggle with x = x + 1. However, I think this moment of rethinking is a really important first step. I'd like to make the language around it easier to find (maybe Try.dot.net), but I think it's a speed bump folks need to address.

I wonder if for many programmers the "basic graphics" isn't really "something I can see." Do you think Unity may play a role here? Or just simple WinForms programs that are much simpler than a website?

@svick
Copy link
Contributor

svick commented Apr 24, 2018

@KathleenDollard

I have watched several beginners struggle with x = x + 1. However, I think this moment of rethinking is a really important first step. I'd like to make the language around it easier to find (maybe Try.dot.net), but I think it's a speed bump folks need to address.

This reminds me of SharpLab's recently added Explain mode. It takes a piece of C# code, explains all the features used in it and links to their documentation. I think it could be useful for beginners looking at unfamiliar piece of code.

Currently, it doesn't explain the basics like =, but that's something that could be added.

@DavidArno
Copy link

I have watched several beginners struggle with x = x + 1

Then don't teach them it. Mutating variables in that fashion is counter-intuitive to beginners and hard for even experienced developers to follow in their heads when the code gets more complex. So encourage immutability of variables:

var x2 = x + 1; // problem solved

@KathleenDollard
Copy link
Collaborator

It depends on what is going on.

You're right that it's sensible to learn assignment (the hard part, that was an equality operator since Kindergarten) separate from mutability.

When the underlying thing is changed, it should mutate. Reusing a variable other than to indicate the inherit mutability of the thing (a loop counter, for example) is not helpful.

I suspect we agree, but lack context due to x's, which is probably a more important thing for beginners - work with something they know or can see - moving things around on screen (Winforms, Unity, etc) is my go to.

@DavidArno
Copy link

@KathleenDollard,

I suspect we agree...

I suspect we do, too. But I tell you what, I'll add your functional C# talk at SDD in a couple of weeks to my list of talks to attend and will let you know afterwards 😀

@KathleenDollard
Copy link
Collaborator

I look forward to meeting you at SDD! Be sure to track me down.

That talk is definitely not a beginner's talk :)

@LeonG-ZA
Copy link

It's already extremely beginner friendly. The most beginner friendly compared to everything else in my opinion.

@ahdung
Copy link

ahdung commented Oct 30, 2018

agree, need do until

@gulshan gulshan closed this as completed Jul 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants