I am mentoring an Apprentice who has never done C# before and this is his first programming job. So this is a diary of some-sort of his progression and my ability to mentor.
I found an example on the Code Review section of Stack Exchange by someone who was writing their very first C# program. I thought it was a good example to give to my Apprentice to test him out.
So I showed him the code, and asked him to explain to me what it was trying to do, if he could suggest improvements or spot any bugs. Basically doing a Code Review.
I thought he explained the code fairly well and struggled in places where the code wasn’t well-written. He did point out one bug and did hint at a few areas of improvement but didn’t seem sure on how exactly to improve it.
I then took him through some changes, and explained how the code could be improved. Most of the code was jammed inside one method so it was 300 lines long. I showed him how you can easily refactor the code into smaller methods using Visual Studio, and how to rename variables (with the advice of choosing descriptive names). The end result is code that is self-describing.
You can read the popular book Clean Code by Robert C Martin which discusses more ideas along these lines.
I told him it’s an important skill to read other developer’s code, since maybe you end up spending 90% of your coding time reading existing code (not sure of the exact statistic there, but it must be high). Also you will be doing it in the code review process.
He seemed to really enjoy it, and was grateful for my tips. I told him I will probably be testing him with more of these challenges, and I also expect to see him put my advice to use in his own code.