10 tips for ASP.net developers



Becoming a good and proficient programmer is ofter about the little things. There are small good habits that make an ok programmer golden, and bad little habits that make a code genius a nightmare to work with. Here are some humble tips for the aspiring dotnet programmer on his way...

  1. Simple redirect – Response.Redirect(“path-goes-here”) can be used to redirect a user to a new page. By extension, to reload or refresh the same page after posting back you can use Response.Redirect(Request.RawUrl);
  2. Use relative and dynamic links. Try as much as you can setup all your links as relative/dynamic links, NOT just relative. This will make it a lot easier to move pages and resources within your app without breaking functionality. For server controls this simple involves using the “~/” notation when specifying paths e.g. Response.Redirect(“~/UserControls/FacultyBioPOD/Page1.aspx”) for JavaScript and CSS read ‘How to setup Relative links in ASP.NET’.
  3. Make “Collapse to Definitions” a button in your toolbar or a shortcut. It is simply one of the best ways to read code-heavy pages by starting at the top level.
  4. Foreach loops are a joy and can be used in a many circumstances to loop through all sorts of collections. I think they are much more preferable than For or While loops. When you need to loop through a data collection or object collection this is a very easy way to do it! Learn it, love it, use it!
  5. Almost anything is better than writing your data access code in your page! Almost anything. It’s messy, makes your application/website hard to read and maintain, makes it almost impossible to re-use your code else where. Alternative? Put your data access logic in a class, use TableAdapters which allow you to store multiple queries in single class files and call them from anywhere in your code, LINQ-to-SQL, LINQ-to-Entities, or well written parametrized SQL encased in using statements. Which to the next tip…
  6. Learn to organize your code, and keep it organized. The more organized your code is, the more excited you will be about returning to it time and again to add new features, fix bugs, enhance usability, borrow functionality, refactor, etc. The more disorganized a code base is, the higher the chances are that it will be left to gather dust and die a lonely death. There are many techniques for cleaner, maintainable code that anyone can learn. Here are a few
    1. Group similar files in folders /CSS, /JS, /UserControls, /Images, /App_Code, /Admin etc.
    2. Keep your methods(functions) short. <20 lines if possible. If your code gets longer than that you should ‘refactor it’.
    3. Use classes to group similar methods together, and more importantly define your application objects.
    4. Quick fixes have been know to cause more problems than they solve. Before you implement a solution, let it marinate in your mind for 5 mins.
  7. Sometimes you may need to check if a String is null or otherwise blank/empty "". Instead of writing 2 blocks of code to check for this, simply use string.IsNullOrEmpty(crazy-string) to check for both conditions at once.
  8. Read ‘other’ code written by other programmers. The .net community is huge and there are fantastic projects everywhere. Your knowledge and growth as a developer gets on the super-fast track the more you learn to learn from the work of others. Check out the tons of projects on Codeplex, or some of my favorite open-source projects dotnet BlogEngine and N-Layered Web Applications with ASP.NET 3.5 Part 1: General Introduction by Imar Spaanjaars.
  9. Visual Studio’s Debugger. Love it, learn it, use it! When confronted with a bug in your code, set some break points and launch your debugger. Inspect your variables as you applications run. Become a master bug slayer! Some people fix their bugs in minutes, others will live with their bugs for weeks, years or forever? Which will you be?
  10. Learn proper database design. It easy, but it’s not ‘optional’. No matter how much C# you can sling at the blackboard, not knowing what an identity column or foreign key is will close many-a-door in your face. And if you do get the job, you may lose it quickly enough. SQL is easy to learn. While a good programmer is not a substitute for a good DBA (Database Administrator), the force is strong with the one who knows his or her way around SQL queries, inserts, deletes etc.

- Efosa Oyegun



Tags: , , ,

ASP.NET Tutorials | Programming | Visual Studio

Comments

10/10/2009 6:27:42 PM #

trackback

10 tips for ASP.net developers

You've been kicked (a good thing) - Trackback from DotNetKicks.com

DotNetKicks.com |





Powered by BlogEngine.NET 1.5.1.30, Original theme by Mads Kristensen
Web Analytics