Hack Your Mind Right Now....!

  • Home
  • Android
  • C Language
  • Facebook Hacking
    • 20 FB Tricks
    • Animation in FB
  • DeadlyHacker

Good Programming practices With C #

Posted by Unknown at 11:59 AM
1.     Avoid writing very long methods. A method should typically have 1~25 lines of code. If a method has more than 25 lines of code, you must consider re factoring into separate methods.

2.     Method name should tell what it does. Do not use mis-leading names. If the method name is obvious, there is no need of documentation explaining what the method does.

Good:
              void SavePhoneNumber ( string phoneNumber )
              {
                            // Save the phone number.
              }

Not Good:

              // This method will save the phone number.
              void SaveDetails ( string phoneNumber )
              {
                            // Save the phone number.
              }

3.     A method should do only 'one job'. Do not combine more than one job in a single method, even if those jobs are very small.

Good:
              // Save the address.
              SaveAddress (  address );
             
              // Send an email to the supervisor to inform that the address is updated.
              SendEmail ( address, email );                           
             
              void SaveAddress ( string address )
              {
                            // Save the address.
                            // ...
              }
             
              void SendEmail ( string address, string email )
              {
                            // Send an email to inform the supervisor that the address is changed.
                            // ...
              }

Not Good:

              // Save address and send an email to the supervisor to inform that
// the address is updated.
              SaveAddress ( address, email );

              void SaveAddress ( string address, string email )
              {
                            // Job 1.
                            // Save the address.
                            // ...

                            // Job 2.
                            // Send an email to inform the supervisor that the address is changed.
                            // ...
              }

4.     Use the c# or VB.NET specific types (aliases), rather than the types defined in System namespace.

              int age;   (not Int16)
              string name;  (not String)
              object contactInfo; (not Object)

             
Some developers prefer to use types in Common Type System than language specific aliases.

5.     Always watch for unexpected values. For example, if you are using a parameter with 2 possible values, never assume that if one is not matching then the only possibility is the other value.

Good:

If ( memberType == eMemberTypes.Registered )
{
              // Registered user… do something…
}
else if ( memberType == eMemberTypes.Guest )
{
              // Guest user... do something…
}
else
{
                            // Un expected user type. Throw an exception
                            throw new Exception (“Un expected value “ + memberType.ToString() + “’.”)

                            // If we introduce a new user type in future, we can easily find
// the problem here.
}

Not Good:

If ( memberType == eMemberTypes.Registered )
{
                            // Registered user… do something…
}
else
{
                            // Guest user... do something…

// If we introduce another user type in future, this code will
// fail and will not be noticed.
}

6.     Do not hardcode numbers. Use constants instead. Declare constant in the top of the file and use it in your code.

However, using constants are also not recommended. You should use the constants in the config file or database so that you can change it later. Declare them as constants only if you are sure this value will never need to be changed.

7.     Do not hardcode strings. Use resource files.

8.     Convert strings to lowercase or upper case before comparing. This will ensure the string will match even if the string being compared has a different case.

if ( name.ToLower() == “john” )
{
                  //…
}

9.     Use String.Empty instead of “”

Good:

If ( name == String.Empty )
{
              // do something
}

Not Good:

If ( name == “” )
{
              // do something
}


10. Avoid using member variables. Declare local variables wherever necessary and pass it to other methods instead of sharing a member variable between methods. If you share a member variable between methods, it will be difficult to track which method changed the value and when.
Email ThisBlogThis!Share to XShare to Facebook

0 comments:

Post a Comment

Newer Post Home Older Post
Subscribe to: Post Comments (Atom)

Like Me On Facebook Mr. Deadly Hacker

About The Author

Unknown
View my complete profile
Aman Badhania writes this blog to help computer users with problems related to web services and getting the most out of their own websites.
Feel The Power Of Cyber Hacking Mr. DeadlyHacker

Popular

    List of google dorks for sql injunction List of google dorks for sql injunction
    Get Serial Number Of Any Software - Using Google Get Serial Number Of Any Software - Using Google
    How to Increase Facebook Fan page Likes How to Increase Facebook Fan page Likes
    5 Most Important Software Tools for Bloggers 5 Most Important Software Tools for Bloggers
    DRIL – Domain Reverse IP Lookup Tool: DRIL – Domain Reverse IP Lookup Tool:
    What is Windows.old folder and How to remove it. What is Windows.old folder and How to remove it.
    no image sql injection dorks

TemplateHits

  • Home
  • About Me
  • Serial Keys 1million
  • Password Hacking
  • Telnet
  • Hacking
  • Download
  • C Language Tips and Trick
Feel The Power Of Cyber Hacking Mr. DeadlyHacker

Hacking Tricks

Hacked Window Hacking Tools Window Software Window 8 Window Tips How To Make Window Genuiene Window 7 Hacking tutorial IP Tips Internet USB Hacking Hardware IGI 3 Internet Tricks Torrent HD movie HTML Hacker Types Hacking Game Hacking Tips Happy Deepawali Hard Disk Hardware Hacking HitMan Game HoneyPot Hosting IGI 2013 Image 2 Text Information Intrusion Detection System (IDS) Tekken 6 Telnet Terminator RAT TrueCaller UserName VLC Player Hacking Virus Visual Script Tricks Window 10 Window 8 Hack Window 9 Window News Window Server Youtube Tips Zombie iPhone

Crack Skull

Crack Skull
Shiiiiiiiiiiiiiiii.....Don't Live This

Followers

Deadly Tricks

Android Android Tips Android Apps Android Hack AntiVirus Hack Aman Badhania About Keylogging Backtrack Blogger Tips Backup Trick Batch Programming Browser APT Access Block Sites Advance Persistant Threat Albert Einstein Android Code Android Games Android Smart Phone Angry birds Application Assassin’s Creed III AutoCad Batch Hacking Blogger tools Bolloywood Movie HD
Facebook Hacking Firefox Imp. Addons Facebook Tips Download Facbook hack Deadly Hacker Desktop Hacking Exploits Email Hacking Data Recovery Desktop Apps Disable Mouse Dos Tools Drawing Arts Drive Icon Change Ethical Hacking Learn File hosting Firefox Download Flash Software

More Tricks

Software Proxy Server Password Hacking Software hacking Opreting System Partition Make Programming Of linux Remix Hacking Reverse Engineering Samsung Mobile Hacking Skin Pack For Window 7 System Hacking Open Source Code PC Hack PenDrive Bootable PenDrive Hacking Phishing Attacks Phreaking Proxy Sites RainMeters Recover Recover Deleted Files Red Hat Registry Hack Reinstall Your All Drivers In 5 MinutesThis is a featured page Resume Spear Phishing
Computer Hacking Backtrack Blogger Tips Command Hacking Crash Computer Cross Site Scripting (XSS) Backup Trick Batch Programming Browser CRIMINAL HACKED Computer trick Batch Hacking Blogger tools Bolloywood Movie HD C# CSS Check Password Coin Box Calling Hacking Cryptography
Aman Badhania
Copyright © 2012 Hack Your Mind Right Now....! - and Deadly Hacker.