The "why" is clear, we're supporting a need the programmer will have for creating service instances. The "what" is clear, the function returns an instance of the specified generic type T. The "how" is clear, there are four function calls that describe how this function works.
Beginner to code - Are you a programmer? Web Developer? do you know How to Write Good Code and make you a professional programmer? This article is simply about how do to write good code. Bad habits from a programmer especially in Indonesia very often to forget this. In fact, just by adding a bit of writing in your code, you will look like a Professional Programmer.
Here i will show you how to do that. First in your application you must you need to explain some point, WHY, WHAT, HOW. For example, Please see source code below (i will write using C#) :
Now, why you don't write a beauty code look like this one :
it's better than the first code.
In other words, when you could write a comment in the body of the code that answers one of those questions, you need to move that code into a function that answers the "what". Recurse that process until the function's name answers "what" and the body of the function clearly describes "how", then for each function you created, write an intelligent "why" comment. Now go forth and code better!
References : http://www.codeproject.com/Tips/1058613/How-to-Write-Good-Code
Here i will show you how to do that. First in your application you must you need to explain some point, WHY, WHAT, HOW. For example, Please see source code below (i will write using C#) :
// usually you will describing why the function exists
public void AnyFunctions()
{
// do anything!.
}
Now, why you don't write a beauty code look like this one :
/// <summary>
/// The user can get an instance of a service implementing
/// the specified interface, but only if the service is
/// registered as supporting instance creation.
/// </summary>
public virtual T GetInstance()
where T : IService
{
VerifyRegistered();
VerifyInstanceOption();
IService instance = CreateInstance();
instance.Initialize(this);
return (T)instance;
}
it's better than the first code.
If your function has "how" fragments that would benefit from "how", "what" or "why" comments, then this is great indicator that you should move those fragment into separate functions where the the function name describes "what" and embodies "how."The "why" is clear -- we're supporting a need the programmer will have for creating service instances.
The "what" is clear -- the function returns an instance of the specified generic type T.
The "how" is clear -- there are four function calls that describe how this function works.
In other words, when you could write a comment in the body of the code that answers one of those questions, you need to move that code into a function that answers the "what". Recurse that process until the function's name answers "what" and the body of the function clearly describes "how", then for each function you created, write an intelligent "why" comment. Now go forth and code better!
References : http://www.codeproject.com/Tips/1058613/How-to-Write-Good-Code
COMMENTS