What is an API and What good is it?
Jan04

What is an API and What good is it?

Welcome to CodeSpread! Did you anytime hear these questions? What is an API? Why it is required? How to make it? People have googled, few were satisfied and others came out perplexed. So why not we also try! We searched for the same on Google again and enlisted some definitions from top 10 results available across the web. We will also add our own spices to explore more. Wikipedia says “An application programming interface (API) specifies how some software components should interact with each other.” Howstuffworks.com says “An application-programming interface (API) is a set of programming instructions and standards for accessing a Web-based software application.” One answer from stackoverflow.com, “An application programming interface (API) is a particular set of rules (‘code’) and specifications that software programs can follow to communicate with each other. It serves as an interface between different software programs and facilitates their interaction, similar to the way the user interface facilitates interaction between humans and computers.” Let’s see one real-world example so that a layman can easily understand the concept of API.   Think of two conditions, one when there is no remote control available to change the settings of TV and other is when the remote control is available. Obviously remote control condition is much favored as only few clicks are required for any setting change. Here, remote control acts as an API where the settings of TV can be changed without directly interacting with TV knobs. While sitting on a sofa few feet away from TV, you can control your TV. Life is easy!! Few lines for our tech persons also.   We have two applications having their own independent implementations. Now if they need to access information from each other or one way flow then they need to expose their logic but hide the implementations, so for that, they need to create API for their application. An API is nothing but an interface which has only definitions but no implementation logic exposed. Each programming language has their own syntax to do it but the idea remains the same. What good is API? Answer is simple use. Also, one question, did we talk anywhere about creating a proxy? J Where we are using API? Yo may recall, we are using Google analytics to know the daily visits, facebook API to know the number of likes, twitter API to know the tweets, and so on. Any more...

Read More
Comic: Real Christmas & New Year Celebrations
Dec25
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
Sunday Splash: IT News
Dec15

Sunday Splash: IT News

Are we ready for this? Of course we are!! This is repeated every year. Enjoy!!

Read More
Tips and Tricks: C# Code Surround-with Snippets
Dec12

Tips and Tricks: C# Code Surround-with Snippets

We have discussed Code Snippets and one of the two types, expansion snippets in our previous article: Tips and Tricks: C# Code Expansion Snippets Now, we will discuss Surround-with snippets. Surround-with snippets are added around a selected block of code. How to use Surround-with snippets? Select the lines of code you want to surround with a snippet. class CodeSpread { void printname() { Console.WriteLine(“CodeSpread”); } }   Now Either press CTRL + K, CTRL + S OR select one of the option from “Surround With” in Intellisense. Here, if we select “if” snippet, then it will wrap the selected code snippet with the “if” statement. class CodeSpread { void printname() { if(true) { Console.WriteLine(“CodeSpread”); } } } Is Surround-with feature available for front end? Yes, it can be used in HTML markup also. Follow the same steps as above. With the help of this feature, you can surround the HTML markup with a snippet like “div” snippet, “form” snippet or more. Even in case of asp.net control, same steps can be used to surround the control with snippet like “Panel” snippet, “Repeater” snippet. Isn’t it...

Read More
Tips and Tricks: C# Code Expansion Snippets
Dec12

Tips and Tricks: C# Code Expansion Snippets

“Ever felt like not writing the same code again? Yes! But what is the solution? Solution is Code Snippets.” What is a Code Snippet? Code snippets are small blocks of reusable code which contains commonly-used code blocks such as property, try-finally or if-else blocks. We just have to type a few letters and then press tab twice [TAB TAB]. This is one of the useful ways to reduce our efforts of writing repetitive code again. Do we need any special configuration? No, as it is a feature available in Visual Studio. There are two kinds of code snippet: Expansion snippets, are added at a specified insertion point and may replace a snippet shortcut, Surround-with snippets are added around a selected block of code. We will talk about expansion snippets in this article and Surround-with snippets in the next article. Expansion Snippets: Try Catch Finally: In C#, the shortcut tryf is used to insert a try-finally block: class CodeSpread { tryf } type tryf and press TAB + TAB. The result will be class CodeSpread { try { } finally { } } Property: In C#, the shortcut prop is used to insert an automatically implemented properties block: class CodeSpread { prop } type prop and press TAB + TAB. The result will be class CodeSpread { public int MyProperty { get; set; } } Full Property: In C#, the shortcut propfull is used to insert a full property block: class CodeSpread { propfull } type propfull and press TAB + TAB. The result will be class CodeSpread { private int myVar; public int MyProperty { get { return myVar; } set { myVar = value; } } } Using: In C#, the shortcut using is used to insert using-statement block: class CodeSpread { static void Main() { using } } type using and press TAB + TAB. The result will be class CodeSpread { static void Main() { using (resource) { } } } Class: In C#, the shortcut class is used to insert class definition block: class type class and press TAB + TAB. The result will be class CodeSpread { } Constructor: In C#, the shortcut ctor is used to insert parameterless public constructor block: class CodeSpread { ctor } type ctor and press TAB + TAB. The result will be class CodeSpread { public CodeSpread () { } } do-while loop: In C#, the shortcut Do is used to insert do-while code block: class CodeSpread { static void Main() { do } } type do and press TAB + TAB. The result will be class CodeSpread { static void Main() { do { } while (true);...

Read More
Page 1 of 6123456