“Everyone’s got an API. I want mine!”

First of all, for the record, I didn’t say “Everyone’s got an API. I want mine!”; it’s just the title of this post. Secondly, that is the wrong frame of mine for anyone to have in anything because it’s not good to go into creating/building something if you are primarily motivated to be “second best.” I shouldn’t divert from the main topic here. I’m writing to shed some light on some API business. I’m mainly concerned about the REST API Web Service because it is by far the most popular and useful Web Service out there. This Web service is very popular among JavaScript programmers because JSON is one of the formats by which REST API’s transfer/relay state. SOAP does not support JSON!

Some people might have heard about the SOAP and REST Web Services but might be puzzled on what services these two really provide and which to choose to solve some specific problems.  SOAP stands for Simple Object Access Protocol while REST stands for Representational State Transfer. So that I don’t bore you with so many technical details as would some others, I would say that the main pragmatic difference between these two is that REST as a service ships in more versatile formats like JSON, XML, YAML (sometimes) while XML is the message format that SOAP ships in and depends on. Applications that implement a RESTful architecture are usually said to be RESTful.

Who uses REST and why do people use it? A lot of companies! All of Yahoo’s web services use REST, including Flickr. Del.icio.us API uses it, pubsub, bloglines, technorati, and both eBay, and Amazon have web services for REST. Here are the defining qualities that make REST stand out:

  • Lightweight – excludes much of the redundancy that accompanies SOAP.
  • Easy to build – no special toolkits required.

Now let’s get to the real business: How do you build a REST API (I hope you are convinced enough that REST is easier to produce and use than SOAP). I could write a bunch of pages on how to write a REST API using WSDL (Web Services Description Language) or a server-side language like PHP or Ruby but would be reinventing the wheel by doing so. I have a list of tutorials that I believe people can benefit from just as I did and learn how to create their own REST API’s. Please remember that when following these tutorials, you should take note of third-party libraries like SoapServer in PHP. It is very tedious, slow, and not wise to start building your own library from ground up without using any helper libraries. Take a look at this list of resources on API creation and development:

Ok, that’s it folks! Follow more than one of these tutorials (make sure you listen to the google tech video; it’s priceless!).

Trees: CS stuff

I wander if the nerds that invented the trees data structure thought about standards when they invented it. I don’t think they did.

Don’t get me wrong! They are innovators who changed the computer science scene and revolutionized the industry by inventing such data structure that we ease some solutions to some problems. The trees data structure lets us search for keys and values faster. And they also have so many advantages in terms of deletions and insertions, and searching. They are prototypes to forms like AVL TREE, sets, multi sets, and dictionaries. Plus, the concept of the tree alone makes us think about other interesting and challenging concepts in computer science in a more intuitive way. For example, the study of trees inevitably introduces the programmer to hard-to-grasp concepts like recursion, depth-first search, breadth-first search, data structure traversal, mathematical induction, fractals, to mention a few.

The only problem with the data structure is that its implementation varies. And this can be bewildering sometimes. For example, I have read in some encyclopedias and textbooks that trees cannot have duplicates. However, some other sites and textbooks claim otherwise. The stanford library at cslibrary.stanford.edu gives some examples of cloning a tree within a tree– that is, making duplicates in the tree. In particular, they claim that duplicates of a value should be added to the left of that value such that if a, b, c represent the left subtree, root, and right subtree respectively, if a new node d (b==d or a ==d or c==d) where d is equal in value to one of the nodes already present in the tree, d, the new node, is added to the left of the node equal in value. This contradicts with other textbooks that claim that binary search trees should not have duplicates values. To further perplex us, the wikipedia article on binary trees and BST’s straddle between both views. In fact, it is self-contradictory in how it says that trees should have duplicates in a section of the article but still in another section says that trees should never contain duplicates. I’m perplexed. I need clarification on this. Which should I follow. Should I implement trees that allow duplicates or not. Which implementation is better? And how do I know?

Or maybe it just happens that we can make our own implementation. Or do whatever we like in computer science concerning data structures in CS. That’s why I love computer science. We can blaze the trail!

So I think for now I will just stick with the BST that allows duplicates because there are more interesting problems I can solve on such BST. GOOD WAY TO PRACTICE FOR THE ACM!