Uncertainty in programming – the lochness of the programming world
March 11, 2009 at 5:09 pm | In Tips,Tricks and code, python, rant | 1 CommentProgramming has come many a mile since the 70’s. A wide array of languages, methodologies, frameworks and other similar artifacts have made the life of a programmer really simple. These artifacts have incrementally solved problems faced by programmers and slowly, but steadily, wrapped the programmers view of a program into a set of abstractions. One of the first abstractions that was built, looking at the history of programming languages, was the ability to hide the underlying differences in hardware, system software and present a unified way of programing and manipulating the system. This is what we call modern day high level programming language.
If the programming language, an abstraction of the real machine code, ever helped solve a problem, it was that of uncertainty. Take an example of the piece of code given below.
// sample code to add two numbers
int a=10,b=20,c=0;
c= a+b;
Console.WriteLine(c.toString());
When I run this code on any machine, I am assured to get the value of c to be equal to be 30. I know when I access the variable “c” the next time, I will find it contains the value of 30. I know that two instructions from now, variables a,b,c will be available for further manipulation.
My recent attempts at programming on the cloud has taught me several lessons, the most important one being, programming to deploy on a cloud is almost like writing programs that you can never be certain about. You can never maintain application state. This means no static variables, no relational datastore, no freedom to write into the filesystem etc. Think about it for a second and it will make sense why these seemingly harmless actions are prohibited. Filesystem access is a big no-no anywhere, but as for static variables, persistent classes, singletons etc, running this on many actual/virtual machines means, all these entities with their values have to be moved/replicated across the cloud. This becomes a non trivial problem especially when the state keeps constantly changing. I could live with all these restrictions by coding, painful but effective, workarounds. What I can’t do is, work with uncertainty. Here is an example :
from google.appengine.api import memcache
def get_greetings(self):
"""get_greetings()
Checks the cache to see if there are cached greetings.
If not, call render_greetings and set the cache
Returns:
A string of HTML containing greetings.
"""
greetings = memcache.get("greetings")
if greetings is not None:
return greetings
else:
greetings = self.render_greetings()
if not memcache.add("greetings", greetings, 10):
logging.error("Memcache set failed.")
return greetings
The code is an example on using the built in caching mechanism on appengine. Notice the line of code given below; its supposed to return the value of the item in the cache with the key greetings
greetings = memcache.get("greetings")
Here’s the question: what is the guarantee that the value, which I inserted into the cache with a large timeout, is actually available. Whenever I write this line of code, do I have to write the failsafe code also(line 15,19) ? I am trying to model state using variables in the cache, mainly because its the next best thing to persistent classes and is less expensive (computationally and financially) than the key/value datastore. How do I reliably do this ? I cant trust that the cache will be available and have to keep on constantly updating the failsafe mechanism ( in case of appengine, the datastore) which is inefficient and highly taxing on the application. What has given rise to this situation is the environment of the cloud. Its not a new problem by any means. With the introduction of new languages, language constructs and other programmatic abstractions, this kind of uncertainty in programming has always reared its ugly head. The lochness of the programming world. And it will continue to do so; which is why we will have constructs like the assert(). My greatest worry is that I don’t see an elegant solution in the foreseeable future.
New Programming Paradigms
March 11, 2009 at 5:06 pm | In Tips,Tricks and code, rant | Leave a CommentOver the last two or three years, I have seen introduction of many new psuedo programming languages(if I can call it that) that help users build applications over the web. Most of these languages are built to work with or as a service. I shall wildly switch between a web service and also the langauge to interact with that webservice; so get the message when I switch from one to another. Let me take one of these languages called YQL. A sample instruction would look like this:
/* Get the latest 10 photos from flickr where the photo name contains cat */ select * from flickr.photos.search where text='Cat' limit 10
As you can clearly see the language makes querying a service and receiving its response really really simple. This is how most new psuedo languages are. They work with service end points and emulate an existing programming language’s syntax to do that. These languages are built with mashup’s in mind. The dangers of such an offering are already imminent. Services are good as long as they are up and live. Take for example any of the Google or yahoo Api’s and you will find wrappers written by people in such pseudo langauges to make your life simple. Even in the enterprise space there are such languages being built which query custom services and makes building applications really really simple.
Another observation of mine involves loose typing in these languages. Most new languages are loosely typed. Most of them take from python which lets the user take care of the typing. SQL by far has been the most emulated language amongst these pseudo langauges. Take for example JoSql to add SQL like capabilities to operations like file handling or Linq in .NET which exposes a sql like interface to datastructures. These improvisations have dramatically reduced time to turn ideas into code and rapidly prototype the application.
There are limitations to using such improvisations; some that even I can vouch for. Loosely typed and unstructured languages are good as long as you are not working on large scale systems. If you are hacking up a solution to a problem that you are facing, these pseudo languages look to be real problem solvers but when it comes to working in teams, projects that need to go into production, you start getting into big problems. Though I am a python fanboy, I faced problems when I was working on python and perl on a large project with a team. Interfaces would be unclear, poor documentation would literally spell doom and tons of other problems that we never thought we would face. There are others who complain of the very same thing. I am guessing we will see a flood of such languages in the future thanks largely to applications evolving slowly into services and it will be difficult to guage the quality of these services. Twitter’s API tried to make their service more stable but the mechanism they chose didn’t satisfy many developers. Lets hope we figure out a way to make these more reliable and stable. I guess its the developers call to be judicious about what language and service to choose when building applications.
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.

