As a Programmer, you'll probably find yourself having to learn a number of programming languages whether it be for work or just for fun. In this blog, I will share what is the best way to learn a new language provided you're fairly proficient in one of the same paradigm. I'll be taking a stab at learning C# with prior knowledge in Object-Oriented programming with languages like Java, TypeScript, and C++.
So whenever we learn something the majority of us head to YouTube or grab a book or use some learning website to get stuck in. But for us programmers who already know the basic principles of programming, watching tutorials telling us how to do an if statement can be quite laborious. However, I know there are books and even tutorials out there which cater to people who already understand the basic principles of programming, but I'd like to share an alternate approach which works well for me.
is a brilliant website which has community made programming challenges called Katas in which are split by their difficulty.
They've also got a pretty awesome leveling system!
I encourage you to check it out if you've not heard of it as my description is only brief!
Getting started 8kyu
In Codewars the easiest type of problem is an 8Kyu and this is where I always start when learning a new language.
And I'm sure the majority of you are looking at the kata thinking it is far too easy and potentially a waste of time, but the beauty of this approach is it forces you to ask questions, and these questions are vital for sculpting your mental model of the language.
Setting up the environment
Codewars has its own built-in editor, but for us, we will be wanting to use our own so we can get knee-deep in the language using tools such as the debugger and setting up our own tests!
After some googling I've found out that .NET Core is the framework which works on Windows, Linux and macOS, so I guess I'll start with that. I downloaded the .NET core SDK.
With .NET you can create the project using the command line, so I'll cd into ReverseWords and DotNET new console (A console app will do the job here).
Yup, my assumption was right you pop your nuget
packages in here, by either adding through the .NET cli:
dotnet add package NETCore.Encrypt --version 2.0.7
or plonking in the package reference directly.
"The obj/ folder is used to store temporary object files and other files used in order to create the final binary during the compilation process." -splattne
Running the thing
Just playing around with the DotNET command there is a DotNET run command. Let's give that a shot:
PS \8kyu\src\ReverseWords> dotnet run
Brilliant stuff, let's actually try and solve this kata then. Let's grab the function they have for us to solve.
Now add the example tests, my current test folder is empty, how do I create a test project?
After some research it seems a lot of people use xunit:
dotnet new xunit
Xunit is not apart of .NET Core and looking in my .csproj this further solidifies my findings earlier about referencing nuget packages!
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
I can't seem to reference our actual program, how do I do that?
dotnet add reference ..\..\src\ReverseWords\ReverseWords.csproj
Now I'm getting a compile-time error saying the class is the wrong protection level, okay, I know this from other OO languages, I suspect it's not been set to public
I was right, I made the class public and now when I run all the tests they fail, time to code!
Okay so I've learnt about StringBuilder, which is pretty much the same as Java, the for each statement is pretty different and I enjoy the implicit types!
It is a very naive solution but it passes all their example tests.
Recap, what have I learned from doing this one problem?
- What .NET core is
- There's power in dotnet commands!
- What .cs is
- What the obj/ folder is
- What the csproj is
- What Nuget packages are and how to reference them
- How to set up a simple project
- How to set up a testing project
- How to reference a project from another project
- What xunit is and how to use it
- How to add tests
- The type system, value, and reference types
- The string builder
- The Array class filled with useful static methods
- The string class also has static methods in