Something you think you should have known earlier? That thing that made it all click? Tips that made your life easier?
Not about C# specifically, but I wish I had known how important the separation of concerns/single responsibility principle was a couple of decades ago. So many production bugs… I also wish I had been more confident in my knowledge so I could complain about such infractions in code reviews with people who had more experience than I did.
I wish I had known the evils of inheritance and relied more on interfaces. Inheritance has its place, but it is evil and should be used with extreme caution lest the evil get out.
I wish I had known about unit tests in the beginning. I went for years copying my code out into a console app to test it.
Visual Studio specific, but I wish I had known more about the debugging tools that come with Visual Studio. Some of them like break points, watches and the immediate window are pretty obvious, but there are a bunch of stats windows that pop up. All of them have uses. I spent many years ignoring them because I didn’t think they were useful – or at least not useful to me. Study them, figure out what they do and why they are there. They may save your ass one day like they did mine.
If you catch an exception and then rethrow it like throw ex;
you lose your stack trace. If you want to rethrow an exception, just use throw;
As a beginner, I didn’t know about the debugger at all. I only just started learning C#, and after I thought I had a handle on the syntax, I built a winforms calculator app. The code became surprisingly complex quite quickly, and issues were taking longer and longer to trace. I decided to add controls to the form to show the value of various variables during execution, but then luckily I discovered the debugger and it make fixing issues so much quicker!
I wish I had known the evils of inheritance and relied more on interfaces. Inheritance has its place, but it is evil and should be used with extreme caution lest the evil get out.
My goodness yes. My brother is learning to code at the moment and I’m amazed that inheritance is still given such a huge amount of prominence in teaching materials, yet interfaces and compositional techniques are barely mentioned (if at all).
I’m also still pissed off that C# is one of the few modern languages that is yet to include some proper kind of traits (and no, DIMs don’t count š”).
OOP.
OOP and SOLID Principals
if C# is his 1st language, then this seems weird.
I wish they taught me it at school instead of python. OOP didn’t click for me (while i could implement it, I couldn’t understand it) until I did it in a c# class for the first time. The cat that goes meow just didn’t make any sense in python but it was completely clear in c#.
I think too much of ASP.NET is not taught but implied. One example: How the hell am I supposed to know which constructor will be used to make a controller? It just did not make sense to me and debugging doesn’t make it clear. I had to experiment to figure it out and the tutor I had on an ASP.NET course could not give a good example also.
In addition async await took a while for me to “get” because the tutor didn’t put enough emphasis on declaration and intialization.
In winforms DataGridView is better than ListView.
Reusable controls.
Obfuscation is crap.
Automation for my backups.
Retry on file read errors. A thing you always need to consider.
Winforms apps built for .Net 2 can run on 4.x
Winforms apps built for .Net 2 that can run on 4.6.2 don’t have long paths support. Apps need be built for 4.6.2
Doing more by coding less. Always fun.
For me, the biggest pivot in my fundamental thinking was reading Clean Code by Robert C. Martin. If I look back at my programming career, there is a clear line separating my time before and after this book.
It’s written in Java, and as I recall, not everything in it is either relevant to C# or even advisable for .NET development. (For example, off the top of my head, he advocates for not prefixing interfaces with I
. And while his logic made a bit of sense, I don’t think it’s advisable for C#.NET development.) But it made me think much more about programming as a craft than just “getting the job/feature done” with whatever garbage code that would run. But that said, most of the code and samples are directly applicable to C# and the general concepts are game changing if you don’t already know about them.