Learning Custom Types in OOP/New Codebases
-
I love C#. The only time I really struggle is when looking at a new codebase, with datatypes. So, for example, I'm now learning a lot of Identity/OAuth related stuff, and code which is actually quite simple, becomes harder for me to understand when I am not familiar with the data types used. See this example:
public class ApplicationUserManager
: UserManager
{
public ApplicationUserManager(IUserStore store)
: base(store)
{
}public static ApplicationUserManager Create( IdentityFactoryOptions options, IOwinContext context) { var manager = new ApplicationUserManager( new UserStore(context.Get())); // Configure validation logic for usernames manager.UserValidator = new UserValidator(manager) { AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = true }; // Configure validation logic for passwords manager.PasswordValidator = new PasswordValidator { RequiredLength = 6, RequireNonLetterOrDigit = true, RequireDigit = true, RequireLowercase = true, RequireUppercase = true, }; var dataProtectionProvider = options.DataProtectionProvider; if (dataProtectionProvider != null) { manager.UserTokenProvider = new DataProtectorTokenProvider( dataProtectionProvider.Create("ASP.NET Identity")); } return manager; } }
What this code is doing is actually very simple, and I get that. But, there are a lot of types thrown around that I'm not familiar with... And then when I learn this particular codebase, the same thing will happen with another when I'm new to it. This was just a small example, but for example with the standard value types like int, double, string, it would be much more straightforward. That said, my current strategy is usually to just hit ALT+F12 in Visual Studio to take a peak at the code and just try to memorize it... But s
-
I love C#. The only time I really struggle is when looking at a new codebase, with datatypes. So, for example, I'm now learning a lot of Identity/OAuth related stuff, and code which is actually quite simple, becomes harder for me to understand when I am not familiar with the data types used. See this example:
public class ApplicationUserManager
: UserManager
{
public ApplicationUserManager(IUserStore store)
: base(store)
{
}public static ApplicationUserManager Create( IdentityFactoryOptions options, IOwinContext context) { var manager = new ApplicationUserManager( new UserStore(context.Get())); // Configure validation logic for usernames manager.UserValidator = new UserValidator(manager) { AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = true }; // Configure validation logic for passwords manager.PasswordValidator = new PasswordValidator { RequiredLength = 6, RequireNonLetterOrDigit = true, RequireDigit = true, RequireLowercase = true, RequireUppercase = true, }; var dataProtectionProvider = options.DataProtectionProvider; if (dataProtectionProvider != null) { manager.UserTokenProvider = new DataProtectorTokenProvider( dataProtectionProvider.Create("ASP.NET Identity")); } return manager; } }
What this code is doing is actually very simple, and I get that. But, there are a lot of types thrown around that I'm not familiar with... And then when I learn this particular codebase, the same thing will happen with another when I'm new to it. This was just a small example, but for example with the standard value types like int, double, string, it would be much more straightforward. That said, my current strategy is usually to just hit ALT+F12 in Visual Studio to take a peak at the code and just try to memorize it... But s
It is just a fact of life. Nobody expect you to hit the ground running when you are dropped in a totally new project!
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
I love C#. The only time I really struggle is when looking at a new codebase, with datatypes. So, for example, I'm now learning a lot of Identity/OAuth related stuff, and code which is actually quite simple, becomes harder for me to understand when I am not familiar with the data types used. See this example:
public class ApplicationUserManager
: UserManager
{
public ApplicationUserManager(IUserStore store)
: base(store)
{
}public static ApplicationUserManager Create( IdentityFactoryOptions options, IOwinContext context) { var manager = new ApplicationUserManager( new UserStore(context.Get())); // Configure validation logic for usernames manager.UserValidator = new UserValidator(manager) { AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = true }; // Configure validation logic for passwords manager.PasswordValidator = new PasswordValidator { RequiredLength = 6, RequireNonLetterOrDigit = true, RequireDigit = true, RequireLowercase = true, RequireUppercase = true, }; var dataProtectionProvider = options.DataProtectionProvider; if (dataProtectionProvider != null) { manager.UserTokenProvider = new DataProtectorTokenProvider( dataProtectionProvider.Create("ASP.NET Identity")); } return manager; } }
What this code is doing is actually very simple, and I get that. But, there are a lot of types thrown around that I'm not familiar with... And then when I learn this particular codebase, the same thing will happen with another when I'm new to it. This was just a small example, but for example with the standard value types like int, double, string, it would be much more straightforward. That said, my current strategy is usually to just hit ALT+F12 in Visual Studio to take a peak at the code and just try to memorize it... But s
I understand and sympathise with you being dropped in the deep end, but creating and using custom types, or classes, is a very fundamental rennet of OOP. Even C allows the use of custom types via the use of
struct
, even if that is miles from OOP.Do what thou wilt shall be the whole of the Law. - Liber AL vel Legis 1:40, Aleister Crowley
-
I love C#. The only time I really struggle is when looking at a new codebase, with datatypes. So, for example, I'm now learning a lot of Identity/OAuth related stuff, and code which is actually quite simple, becomes harder for me to understand when I am not familiar with the data types used. See this example:
public class ApplicationUserManager
: UserManager
{
public ApplicationUserManager(IUserStore store)
: base(store)
{
}public static ApplicationUserManager Create( IdentityFactoryOptions options, IOwinContext context) { var manager = new ApplicationUserManager( new UserStore(context.Get())); // Configure validation logic for usernames manager.UserValidator = new UserValidator(manager) { AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = true }; // Configure validation logic for passwords manager.PasswordValidator = new PasswordValidator { RequiredLength = 6, RequireNonLetterOrDigit = true, RequireDigit = true, RequireLowercase = true, RequireUppercase = true, }; var dataProtectionProvider = options.DataProtectionProvider; if (dataProtectionProvider != null) { manager.UserTokenProvider = new DataProtectorTokenProvider( dataProtectionProvider.Create("ASP.NET Identity")); } return manager; } }
What this code is doing is actually very simple, and I get that. But, there are a lot of types thrown around that I'm not familiar with... And then when I learn this particular codebase, the same thing will happen with another when I'm new to it. This was just a small example, but for example with the standard value types like int, double, string, it would be much more straightforward. That said, my current strategy is usually to just hit ALT+F12 in Visual Studio to take a peak at the code and just try to memorize it... But s
That is the real complexity in any project. It's not the 40ish C++/Java keywords or the standard Bohm-Jacopini flows, nor usually are the algorithms. It's the net of data types and their relationships, which must be learned and should be well documented.
GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver When I was six, there were no ones and zeroes - only zeroes. And not all of them worked. -- Ravi Bhavnani
-
I love C#. The only time I really struggle is when looking at a new codebase, with datatypes. So, for example, I'm now learning a lot of Identity/OAuth related stuff, and code which is actually quite simple, becomes harder for me to understand when I am not familiar with the data types used. See this example:
public class ApplicationUserManager
: UserManager
{
public ApplicationUserManager(IUserStore store)
: base(store)
{
}public static ApplicationUserManager Create( IdentityFactoryOptions options, IOwinContext context) { var manager = new ApplicationUserManager( new UserStore(context.Get())); // Configure validation logic for usernames manager.UserValidator = new UserValidator(manager) { AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = true }; // Configure validation logic for passwords manager.PasswordValidator = new PasswordValidator { RequiredLength = 6, RequireNonLetterOrDigit = true, RequireDigit = true, RequireLowercase = true, RequireUppercase = true, }; var dataProtectionProvider = options.DataProtectionProvider; if (dataProtectionProvider != null) { manager.UserTokenProvider = new DataProtectorTokenProvider( dataProtectionProvider.Create("ASP.NET Identity")); } return manager; } }
What this code is doing is actually very simple, and I get that. But, there are a lot of types thrown around that I'm not familiar with... And then when I learn this particular codebase, the same thing will happen with another when I'm new to it. This was just a small example, but for example with the standard value types like int, double, string, it would be much more straightforward. That said, my current strategy is usually to just hit ALT+F12 in Visual Studio to take a peak at the code and just try to memorize it... But s
TheOnlyRealTodd wrote:
I'll implement something like this and then not even have to mess with it for a while (month or more), then start to forget it..
It is for this reason that I am really starting to like Sandcastle. It requires a lot more effort when writing XML comments but the end product is worth it. I love having a code documentation website with the exact look and feel of MSDN but features my code. It even links forward to the official documentation of .Net classes.
if (Object.DividedByZero == true) { Universe.Implode(); } Meus ratio ex fortis machina. Simplicitatis de formae ac munus. -Foothill, 2016