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
18/12/2013: 10 Best Practices of programming from CodeSpread(21-30)
Dec18

18/12/2013: 10 Best Practices of programming from CodeSpread(21-30)

We love programming and having a knowledge of best practices always helps in writing beautiful code. We have shared first 20 random best practice in our previous articles 1-10, 11-20. More best practices from CodeSpread. Best Practice #21, A single huge EDMX file may hit the performance. So split the EDMX into multiple EDMXs. Best Practice #22, Perform minimum operations possible within one sql transaction Best Practice #23, Use more than one DataContext where each one can represent a single unit of work. This can remove the database objects that are not used frequently. Best Practice #24, SQL Query plans should be reused whenever possible as this can avoid unnecessary query compilation costs. Best Practice #25, Prefer DateTime.TryParse method over try/catch blocks. if (DateTime.TryParse(text, out result)) { // code } else { // throw error } Best Practice #26, While using select LINQ Query, return IQueryable and not a ‘var’ object. Best Practice #27, Do not use the unnecessary demo code which is available by default, while creating a new application. Best Practice #28, Place all the Scripts to the end of webpage. This will get downloaded once browser has downloaded all the other content and will help in progressive rendering of the page. Best Practice #29, ORDER BY,DISTINCT, TOP etc. operations may degrade query performance as they are performed only after the resultset is retrieved, so use them only when there is clear requirement. Best Practice #30, Use namespaces while defining contracts in WCF service. This will help with versioning and interaction of the application with other services. We would love to hear from our users about the best practices used by them. Please write to...

Read More
17/12/2013: 10 Best Practices of programming from CodeSpread(11-20)
Dec17

17/12/2013: 10 Best Practices of programming from CodeSpread(11-20)

We love programming and having a knowledge of best practices always helps in writing beautiful code. We have shared first 10 random best practice in our previous article here, now we are sharing few more best practices. Best Practice #11, Use StringBuilder instead of String, as any concat operation on String will create unnecessary successive string objects. In case of StringBuilder, any append operation will mutate the same object and will not create any successive objects. Best Practice #12, Use Integrated Mode in IIS 7.0 and above. This will avoid two separate application pipelines to handle native and managed components Best Practice #13, Use app_Offline.htm file, it is a user friendly way of keeping the application offline while doing some modification to the application. It also forces an application restart. Best Practice #14, Indexed views can increase performance of certain common queries without having to make temporary tables. Best Practice #15, Create a Custom Error page to show user friendly page while handling exceptions. The redirection logic can be written at the Page_Error event or the Application_Error event in Global.asax. Or use the below logic of web.config. Best Practice #16, Catch specific Exceptions in a try catch block. Create multiple catch block in a try-catch, and each catch block can be used to handle a specific exception type.  Last Catch should be base Exception. Best Practice #17, Use Try Catch Block in SQL Server to catch exceptions. Refer the screenshot. Best Practice #18, Use Regex class, if validation is required for controls other than server controls. Best Practice #19, While using Linq queries to retrieve a single item from a data collection, go with SingleOrDefault() instead of Single() to provide a fail-safe option. Best Practice #20, Avoid ‘using’ block in WCF and replace it with try/catch block. ‘using’ block can mask the faulted state of Service. In catch block, use close() or abort(). Although , all points above are debatable and it should be like this way, as only discussion can help to evolve best practices every time. One of our friend and fellow writer Rajaraman R have shared one of the best practice used by them, “I would also go for using capitalized letters in SQL Statements. That is a good practice.” Please refer comment section of our last...

Read More
16/12/2013: 10 Best Practices of programming from CodeSpread
Dec16

16/12/2013: 10 Best Practices of programming from CodeSpread

We love programming and having a knowledge of best practices always helps in writing beautiful code. Here, we have few best practices shared by professionals. Best Practice#1, Use foreach loop instead of for loop wherever required.* Best Practice#2, To make your file compact, right click on namespaces and select remove unused strings. It will remove all the unused namespaces, which are not used in your code anytime. Best Practice#3, Create a separate config for connection strings and include it in web.config. Best Practice#4 , Dispose unmanaged objects explicitly for ex: COM Objects Best Practice #5, Create automatic properties and use either get or set, try to avoid both get and set together, if not required.* Best Practice #6, Never append your stored procedure with ‘sp_’ as it might be treated as a system stored procedure and will lose its scope. Best Practice #7, Please write each SQL verb on a new line as shown in the image.   Best Practice #8, During Exception Handling, Always use finally block to clear the objects while using try catch blocks. Best Practice #9, Streaming interfaces, like XmlTextReader, give better performance and scalability, compared to loading large XML documents into the XmlDocument or XPathDocument classes and then using DOM manipulation Best Practice #10, Keep EnableViewState Property as false for the page and enable it only for the required controls. It will minimize the page size. *Conditions...

Read More
Why Multiple Inheritance is discouraged?
Dec27

Why Multiple Inheritance is discouraged?

Hi Guys, This is Sathish Again,Today we will discuss why most of the higher languages eliminates Multiple Inheritance? Most of you guys already know that multiple inheritance is not available for development but what you might not know is the reason as why it is not possible. First of all,we will revisit few basics of inheritance. What is Inheritance? Wikipedia says “In object-oriented programming (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both, depending upon programming language support.” In simple words, Inheritance forces reusability where a class reuses the functionality of another class by inheriting all its traits.We can take an example to understand more: In real life, We inherit some of our behavior from our parents,so we can deduce our parents as Base class,and ourselves as Derived class. What are the types of Inheritance? Single Level Inheritance: It is the basic type of Inheritance where child class B inherits/extends the behavior of a base class A. For ex: We can have a child class like TV which extends base class like Electronics. Multi Level Inheritance: Here, Single inheritance is captured at different levels and called as multi-level inheritance. We have a derived class C which extends class B, which is a child class of base class A. For ex: Can we say Ipad extends Laptop and Laptop extends Desktop? Multiple Inheritance: The concept of multiple inheritance is a derived class C extends more than one base class like class A and Class B. Multiple inheritance is not supported by many languages and can be achieved by using interfaces. For ex: Child extends behavior of Father and Mother. Now we will move to our basic question, Consider the c++ program mentioned below , where I have created 3 classes,Two of them are base class and third one is the derived class, Base1 and Base2 are Base classes Derive is the Derived class /*Program about multiple inheritance */ class Base1 { public : void Display() { cout<<"We are in Base class1 " ; } } ; class Base2 { public : void Display() { cout<<"We are in Base class2 " ; } } ; class Derive :public Base1,public Base2 { } ; If we focus on Base1 and Base2, then it is clearly visible that, Base1 class has a method called Display Base2 class also has a method called Display, We extend these base classes with our derived class. Let’s move forward and create an instance of derived class, int main () { Derive d; d.Display(); return 0 ; } When we call the Display method,then the...

Read More
Page 1 of 3123