Exclusively for you!! Trial version of Google Apps, Apply Coupon-CNHPGX6T6QRWGV!!
Tip : Code Structure C#
Feb03

Tip : Code Structure C#

Welcome to CodeSpread! As a developer, I always stress on developing a habit of following the best practices to structure the code. It helps me to easily navigate through the code and also saves a lot of effort in searching for some particular items. Below is the sample structure and example: using statements Constants / Read-only fields Private Members Enumerations Public members Protected members Constructors Properties Public methods Private methods //using statements Using System Using System.Web namespace Controllers { public class SampleController {   //Constants / Read-only fields public const int numofitems=10; //Private Members private string _samplestring = string.Empty; //Enumerations public enum months { January = 1, February, March, April, May, June, July, August, September, October, November, December };   //Public members public  int StartDate =string.Empty;   //Protected members protected int EndDate ==string.Empty; //Constructors public SampleController () { }   //Properties public string Date { get; set; } //Public methods public string GetStartDate() { } //Private methods private int numOfItems() { }     Related articles across the web C# Coding Standards CLS Compliance?...

Read More
Consider Structs
Dec17

Consider Structs

While taking birth in programming world, we all had our own experiences of learning; begin working on a new language or OOPS concepts or experimenting with a new tool or compilers. One of such experiences is already available here. Let’s share one more personal experience and an embarrassing one. J I was just caught up with c# and begin traversing the beautiful journey of programming. I was very overwhelmed with my OOPS knowledge and coding skills. I was making applications, enjoying cups of coffees and playing ping-pong with my team. One day, for a requirement, I was asked to create a program and I created it using lot of meaningless lines of codes. Then during review, I came to know that it could have been done by structs. It was quite embarrassing that I could not recollect structs, just because we do not use it in our daily programming. It was my early phase so was not crucified. Happy go lucky!! I realized that my instant reaction to almost any requirement was class, oops and objects as though it is limited water in the pond. But programming is an ocean. So just to prove that I know structs, I will share structs syntax and knowledge here. What is Structs? A struct type is a value type that can contain constructors, constants, fields, methods, properties, indexers, operators, events, and nested types. [msdn] struct Example { public int x, y; public Example (int x, int y) { this.x = x; this.y = y; } } Few points about Structs: Structs are value types. Struct values are stored on the stack. Inheritance is not supported. Structs can implement interfaces. Structs can improve memory allocations in case of lightweight objects. Structs cannot have a default (parameterless) constructor. Let’s see an example to see structs’ value type nature. For the same struct declared above, we will use it in the below program. Class StructExample { public void AssignStruct(Example instance) { instance.x = 1; instance.y = 2; }   public static void Main() { Example example = new Example (); example.x = 3; example.y = 4; AssignStruct(example); Console.WriteLine(example.x); Console.WriteLine(example.y); } }   The result will be 3 4 Here, struct “Example” being a value type creates a copy and was passed to the AssignStruct method. So value of the struct field remains same in the output and will not have effect of AssignStruct Method. Few lines of code and lightweight object is what the requirement might be, so always consider structs before jumping to class based...

Read More
Interview Question: Why Garbage Collection required?
Dec13

Interview Question: Why Garbage Collection required?

What is garbage collection? In two words “Memory Management”. In two lines “Managing the lifetime of object starting from creation, allocation and release it back to free memory pool.” Why it is required? We have two scenarios here, Case 1: Where resources are not released. Scenario: Resources will keep on getting consumed and will result in memory leak. Case 2: Where resources are released irrespective of still being used in the code. Scenario: May result in null pointers exceptions, corrupted memory areas or loss of data. Garbage Collector manages the lifetime of all objects and avoids any early-release or late-release of...

Read More
ASP.NET and Web Tools 2013.1 for Visual Studio 2012
Nov21

ASP.NET and Web Tools 2013.1 for Visual Studio 2012

.NET Web Development and Tools group at Microsoft announces release of ASP.NET and Web Tools 2013.1 for Visual Studio 2012. Few of the features are: 1) Round tripping: With this update, developers working on Visual Studio 2012 and Visual Studio 2013 can collaborate on an ASP.NET MVC 5 application. It provides support for editing a Razor view like syntax highlighting and Intellisense. 2) ASP.NET MVC 5 and Web API 2 Templates. 3) ASP.NET Scaffolding: With this update, MVC’s scaffolding can be used within any ASP.NET project. 4) ASP.NET Razor Tooling: As discussed above, new features are available like syntax highlighting and Intellisense. 5) Entity Framework 6. 6) Bootstrap: Bootstrap is a responsive mobile first CSS framework for styling the pages. 7) NuGet 2.7. This can downloaded from here:...

Read More
YSlow is a nice addon to determine page performance
Nov09

YSlow is a nice addon to determine page performance

YSLOW is one handier tool for a developer. It is used to analyze web pages and get it tested on the rules identified which are explained below. I like the name “YSlow”as it more or less poses a question “why slow?”. It is available as an add-on to most of the popular browsers like Firefox,Chrome,Safari etc. or can be downloaded from yslow.org. Source: yslow.org Yahoo!’s Exceptional Performance team has identified 34 rules that affect web page performance. YSlow’s web page analysis is based on the 23 of these 34 rules that are testable. • Minimize HTTP Requests • Use a Content Delivery Network. • Avoid empty src or href. • Add an Expires or a Cache-Control Header. • Gzip Components. • Put StyleSheets at the Top. • Put Scripts at the Bottom. • Avoid CSS Expressions. • Make JavaScript and CSS External. • Reduce DNS Lookups. • Minify JavaScript and CSS. • Avoid Redirects. • Remove Duplicate Scripts. • Configure ETags. • Make AJAX Cacheable. • Use GET for AJAX Requests. • Reduce the Number of DOM Elements. • No 404s. • Reduce Cookie Size. • Use Cookie-Free Domains for Components. • Avoid Filters. • Do Not Scale Images in HTML. • Make favicon.ico Small and Cacheable. I know we have been lazy in optimizing codespread.com but in some way, we are lucky that we can run yslow against it and catch many test results as failures to explain them here. Let’s run it on codespread.com. First, we see the default screen of YSlow which gives us a slight idea about its operation. Here, we can see a dropdown to select a ruleset of tests against which we would like run our website. We have 3 options available but we will select only the default option here to test the website against the latest version of ruleset available. Overall, we have scored a D grade and a performance score of 70. Good news is, we have A grade in one or two instances like • Avoid empty src or href. • Put CSS at top. Alert news is, F grade in instances like • Make fewer HTTP requests. • Use a CDN. YSlow goes a step further and tells us the exact number of files and their types which are contributing to excess HTTP requests, plus what needs to be done to make it faster. That is the beauty of YSlow, It can make even an amateur understand the exact cause and also provides the suggestions for improvement. Here, we also see that not all rules are applicable in general case so we just need to look for the...

Read More
Page 1 of 212