Friday, January 14, 2005

Re: Did Microsoft lose the API war ?


Any of you used Google's Desktop search.

I haven't downloaded it (yet) because first, I don't have so much stuff that I can't find it using Explorer and second, I read some bad reviews about it - mostly having to do with making your system slow to a crawl.


My system hasn't begun crawling till now. Creation of the first index does take some time. In any case give it a shot. You will definitely find more stuff than you ever wanted. And its fun to try some 'delicate' keywords. (single quotes as I have been writing SQL queries of late!!). You can always uninstall the app later.


Are you sure Google is starting a local web server? Why would they need
to?


See this screenshot of Google Desktop in action. Notice the address bar. Thats what
tells me a local web server is started on port 4664. Also since results are shown in a web browser, html has to be puked from somewhere. Any of you guys have other info/ideas?

Talking about web servers check this


Microsoft threw everything they could at IE. And I'm not talking about UI or security etc..., I'm talking about support for DHTML, CSS, (X)DOM, XML, XSL within the browser. Plus they introduced Iframes, DHTML behaviors, XML data islands and XMLHttpRequest in IE 5.


Mohn mentioned a whole plethora of protocols enabled in IE. How many are supported my major browsers, and how many are standards. Coz co's will not use IE only functionality within their sites/web-apps (hopefully not in the next gen apps).

Do any of you know how Gmail works internally? We had this prof who told us a bit. Like server farms are maintained. And each email is saved in three locations on diff servers. Mohn - You think Gmail uses DHtml? Tried to analyse the source? Any info on the working of Google actually?


I dunno what the current numbers are but a couple years back, Windows and Office made something like 60-70% of their revenue. The other businesses weren't doing very well.


Any idea on the gaming front? MS is releasing a new XNA platform or something that unifies dev. Dinesh could probably provide loads of info on this. And other game dev stuff.


Plus, I think Apple is making a huge mistake (same that they made with their computer business), in only being compatible with their AAC format. You have to convert everything to AAC. Why would you want to when others can play them?


Dinesh has an iPod Mini. You can dump mp3 songs (read illegally dloaded) onto it. I am not sure if they are converted to AAC on the way. Don't think so coz the transfer was really really fast. As fast as it seems possible in Usb 2.0. Never tried retrieving the mp3's back again. Maybe iTunes songs are in AAC format.

Apple released some cool products recently. The mini Mac and iPod shuffle. Sure would want to own some apple product some day.(read apple.com product not juice)


I would actually say that MS is not that big with kids


Actually just overall exposure to the OS by using it is a good starter. Many co's/products just do not get noticed by the public eyes.


What I was confused about was backward compatibility vs forward compatibility. With generics I think Java is trying to accomplish this.


I think as discussed earlier, by forward compatibilty they mean that no new bytecodes were added to the language. The syntax has changed, but it is optional in Java 5.0 and is just a wrapper for doing the old things in a new way. The core language remains same. Had they added Generics without erasure, there would have been a break in compatibility. There is no way in which I can run 5.0 code on a <5.0 VM as the lib's will simply not be present.


Java 5.0 has made up a lot of ground


One problem is how long will co's take to adopt the newer version. One article mentioned that co's wait around 2 years. (I'll provide a link when net is ON).


The one place maybe that they are lacking is ASP.NET like functionality. It seems they haven't come out with anything to counter that. Any work going on towards that?


Which features of ASP.NET? Lots of dev stuff is going on with Jsp and related web tech in Java. Some advanced UI rendering libs are being built like Jsf though I am not sure thats a good defn. But by itself the Web Platform is very mature with loads of really advanced features. If I am right ASP was a joke comparatively.


In another defense of MS, it has to be said that they bend over backwards
to make Windows backwards compatible.


Some really good info provided which cleared a lot of MS stuff (almost). What was the author (Joel Spolsky) talking about? Was it a small set of real internal, unsupported features that just manage to break applications??

Also could Mohn provide some info on Web Services later some day? Are Java and .NET webservices compatible today? Longhorn wants to focuss majorly on Web Services. That should be slightly worse than the Web strategy.

Hey I am still blurting!!

Thursday, January 13, 2005

Re: Hacking Websites

Holy shite. I think I just hacked Blogger Dashboard. I'm getting the "You suck" message on the control panel. lol

Hacking Websites

I attended a talk recently at ADNUG (Austin .NET Users Group) which was supposed to be about Garbage Collection. Unfortunately, the dude who was supposed to give the talk couldn't make it in time so they had another guy present in his place. He didn't care much for Garbage Collection and instead gave a talk on hacking websites.

He talked about three basic ways people hack web sites...

1) Manipulating hidden form input elements
This one seems so simple. The web is a stateless protocol so everytime you need access to some data, you have to hit the server and retrieve data from a database. To avoid this, one trick many people use is to put this information in a hidden form input element. These elements are not shown in the browser but you have programatic access to them through client side scripting. So for example, a shopping cart has a final price value. This data can be stored in an hidden input element. If you change the quantity of an item, instead of hitting the server, changing the price and returning a new page with a updated price, you can just update the price client side.

Consider this simple example. When you change the quantity, the price is calculated on the client side, instead of hitting the server.

< script>
function updatePrice()
{
    var quantity = document.frmCart.txtQuantity.value;
    var price = document.frmCart.hdnPrice.value;

    var updatedPrice = quantity * price;

    document.frmCart.hdnPrice.value = updatedPrice;

    spnPrice.innerText = "$" + updatedPrice;
}
< /script>

< form name="frmCart" action="checkout.asp">

    < input type="hidden" name="hdnPrice" value="30">
    < input type="text" name="txtQuantity" value="1" onChange="updatePrice();">

    < span id="spnPrice">$30< /span>

< /form>

So a hacker can just save this page, manually change "hdnPrice" to any value he wants and then submit the page to checkout.asp. This is such an easy way to cheat. I mean who would ever use something like this on their site? Believe it or not, the presenter said that it's quite common. He said some dude was able to get airline tickets for 50 cents using this technique from a major airline company.

So, the solution he gave, was that you should put security first and forget performance. Take that hit on the server. Or if you must use client side scripting use it for more trivial things and not for financial stuff.

2) SQL injection
This is a bit more sophisticated in that you need to know SQL quite well. I don't, so I'll just give the simplest example. Maybe after Rahul and Dinesh finish their data module, they can invent new advanced attacks ;-)

Many sites have forms where they ask the user to enter some data and then use that data to make a query into a database. A very common example of this is the Login form. I'm sure everyone who uses the web has seen this one. You have two input boxes to enter your username and password. Generally, the page on the server will take these two pieces of data and form an SQL statement like so...

Dim strUserName = Request.QueryString( "txUserName" )
Dim strPassword = Request.QueryString( "txtPassword" )

"SELECT COUNT(*) FROM users WHERE username='" + strUserName + "' AND password='" + strPassword + "'"

This is a basic statement that counts the number of rows in the table (users) that have username=strUserName and password=strPassword. Here we are not validating the username and password the user enters. So if he knows SQL, he could enter ' or 1=1-- for username and leave the password blank.

This will result in the above SQL statement becoming

SELECT COUNT(*) FROM users WHERE username='' or 1=1-- AND password=''

This will always return true since 1 is always equal to 1. Everything after -- is a comment. So you can gain access to a site without entering a valid username and password.

The speaker gave more advanced examples where he was able to figure out the structure of the table (ie. what columns it contains) and using that information was able to access data contained in those columns. The SQL was advanced so I couldn't follow it, but it was this same technique.

Solution: Be paranoid and ALWAYS validate data coming from the client. And as far as possible use Stored Procedures. Besides getting a performance boost (since they are compiled vs SQL statements that are interpreted), they use typed parameters.

3) Cross site scripting.

This one is where you get your scripts to run on someone else's site. A lot of times sites will have forms for users to enter data and then they just display that data on the page. For example, consider a message board. In a very simple one, there is one page with message posts and at the bottom there is a form to fill out your username, subject and message. When you submit, the page probably enters this info in a database and then just spits out what you just entered along with the other messages. Now what if you include some html or script in your message? For example, if you entered < script> alert( "You suck" ); < /script>. When the page is displayed you will get a message box with your very welcoming message in it. Every visitor to the web page will get that message.

That was a simple dumb example. Here is another simple one. Browsers are pretty linient when it comes to html being well formed. As in, they won't choke if you pass in an opening tag and leave off the end tag. So if you had written < div> and not closed it in the message above, the page would show everything up to the < div> tag. The rest of the page would be blank. Or you could enter an < img> tag and link to some porn image. This will be posted on their site.

But you can see how it could potentially be more damaging. You can gain access to cookies through client side scripts (document.cookies) and you can change the location of the browser (document.location.href="www.mysite.com"). So you can combine these to retrive cookie information and pass it on to your site. This gets more sophisticated, but it's all possible.

The solution for this is to never ever blindly send back whatever the user has entered. ALWAYS encode the data before sending it down to the client. So instead of sending down < script> alert( "You suck" ); < /script>, you should encode it to &lt;script&gt; alert( "You suck" ); &lt;/script&gt; and then send it down. Many server side platforms offer utilities that do it for you. The encoded text will DISPLAY the script on the page, but won't execute it.

Anyway, hope this gave you some ideas of how sites are hacked. Now go forth and practice. And make sure to use someone else's computer.

You guys heard of any other techniques?

Re: Did Microsoft lose the API war ?

Any of you used Google's Desktop search. Amazing desktop app which starts a web server locally. I really wonder how they made the app !! Will more
apps be developed in this way?


I haven't downloaded it (yet) because first, I don't have so much stuff that I can't find it using Explorer and second, I read some bad reviews about it - mostly having to do with making your system slow to a crawl. My dad has it on his PC and he's said its been quite sluggish of late. I can't confirm if Google Desktop search is the culprit, but the timing seems more than just coincidental.

Anyway, desktop search became the hot new thing end of last year. Every big major "search" company and his brother released beta software for searching your hard drive. Most look to do the same thing. I guess they all create some sort of continual index of your drive. That's why they must hog system resources. Google presents its results in the browser using the same UI as it's website. I think Microsoft's solution is a Windows app (big suprise right?). Are you sure Google is starting a local web server? Why would they need to?

Also we discussed a bit on Rich Internet Applications before. It is easy to develop those such apps in a manner independent of the OS.. read flash. So that was one very valid point of the future apps being more internet oriented. That should hurt MS a lot.

I somehow just can't see Flash ever being taken seriously as a development platform. It's fine for animation, cartoons, cards, movies etc... but for actual applications, I'm skeptical. I have read about and seen demos/prototypes of potential applications that could be developed with Flash MX+, but no real apps. To me it feels quite unnatural inside of a browser. So I don't see Flash specifically as a huge threat to Microsoft. We have discussed this before and I know you disagree.

What the author mentioned, and I agree with, is that the Web as a platform is a threat. A few years ago, people didn't take HTML, CSS, Javascript, DHTML etc... seriously. It could not compete with the "richness" of Windows apps. And it is true today, but as he says, people have become tolerant of it. The web is not just a place to publish documents anymore... its become a development platform.

It's ironic that it turned that way because during 96-98 period, when Netscape was still leading, Microsoft threw everything they could at IE. It was a really great browser back then (much much better than Netscape). And I'm not talking about UI or security etc..., I'm talking about support for DHTML, CSS, (X)DOM, XML, XSL within the browser. Plus they introduced Iframes, DHTML behaviors, XML data islands and XMLHttpRequest in IE 5. It's just that since these wasn't standards back then, no one ever bothered to use them. Now, afer 5-6 years, when the major browsers support them, things like GMail are coming out which look quite revolutionary. Now suddenly you can replicate some "rich" functionality within the browser and you don't NEED a Windows app.

The author mentioned about Windows and Office being the main money-earners for MS. I had heard that before. But there other apps must be profitable too!! Any of you have an idea on the other hot-selling MS apps?

I dunno what the current numbers are but a couple years back, Windows and Office made something like 60-70% of their revenue. The other businesses weren't doing very well. In recent years, they've had some success with their Servers (SQL, Sharepoint, Biztalk etc...), development tools and MSN, but it seems like a drop in the bucket compared to the big two.

Its funny how the author mentioned Apple and Sun. Apple has just had a great year selling iPods and hope to translate that to better sales of
other products.


Yup, iPod is the best thing that could happen to Apple. It's the "cool" thing everyone wants. I think it's completely overpriced. You can get similar products from Creative and others at half the price. Plus, I think Apple is making a huge mistake (same that they made with their computer business), in only being compatible with their AAC format. So far it hasn't hurt them, but imagine if you want your existing music (which mostly likely has been illegally downloaded and is in MP3 format) to play on an iPod? You have to convert everything to AAC. Why would you want to when others can play them? Right now it's all about the coolness factor.

MS obviously is out there promoting the WMA format. It's not a standard but they are big and bad enough to get everyone else to support them (Check out playsforsure - Isn't it the dumbest name ever?). Sound familiar? Almost an exact repeat of what they did to Apple with Windows. So lets see what happens this time.

BEA is a Java company which make application servers and lots of very high end server stuff. They are the largest competitiors of IBM on a lot of Java apps. The reason given was simple. Kids don't get to play with BEA software. Seriously!! Devs were not exposed to BEA tools till in the co. and so were a little averse to learning new stuff. Why MS has has such a large developer community was that a lot of kid used MS. So that is an advantage for Java and Linux today. Java is being taught in a lot of courses and Linux has taken a lot of devs' mind share and "heart share".

Great point. I would actually say that MS is not that big with kids. Their languages aren't taught in (good) CS curriculums - Java is. Java is seen more of a standard and a good "academic" language/platform. If MS gets any exposure it's through C++. They are a big player with VC++. You won't see .NET anywhere. But they are doing something about it. The only reason I have Visual Studio .NET is because I got it for 30 bucks at my University computer store. They have some deal with Microsoft for students. The .NET framework and C# compiler are free.

As I must have mentioned a zillion times before, parts of the Java API which are changed to newer versions are not removed. Just marked as deprecated, but can still be used. Mohn had mentioned about a break wrt .NET 1.0 and 1.1. I was of the opinion that the .NET style of newer releases was better but the blog changed my views on the topic (but not completely).

From what I understand, the .NET method is the same. Nothing is removed. It is just marked deprecated. Everything you write with v1 will work with v2 of the framework - like Java. What I was confused about was backward compatibility vs forward compatibility. Backward is where older code works on newer framework. Forward is where newer code works on older framework. Forward is hard to accomplish 100% because if you add new things in v2, it will obviously NOT work on v1. With generics I think Java is trying to accomplish this (Can Rahul confirm this?). .NET generics is adding new types which WON'T work on v1.

I hope I haven't confused matters further - Check this page out on .NET backward/forward compatibility. They explain it nicely - about what a breaking change means and also about configuration files.

The Java camp was stagnating before .NET came into the
scene. Java 5.0 was released very fast to fix the imbalance, but still has
a long way to go.


Java 5.0 has made up a lot of ground. I don't see it as being a huge feature gap anymore. The one place maybe that they are lacking is ASP.NET like functionality. It seems they haven't come out with anything to counter that. Any work going on towards that? At the same time you can say that Java is leading with newer things like AOP etc... Maybe not as a standard from JCP, but it's there. I haven't read anything about it from the .NET side.

In defence of MS, how long is it possible to stretch an API without a fresh start? They must have had some minimum years to support. MS needed a
new API, to deliver the next generation OS. But some degree of backward
compatibility is a must. Mohn - could you clarify the degree to which the
backward compatibility will/will not be supported?


In another defense of MS, it has to be said that they bend over backwards to make Windows backwards compatible. Even with Longhorn, all your .NET, Win32, VC++, VB and even older apps will work fine. In a demo they showed VisiCalc running on an early build.

And another thing is that the "MSDN camp" are not Windows developers. Guys in the "Raymond Chen camp" are developing Windows and they will do everything to remain backwards compatible. The "MSDN camp" are writing about all the greatest bleeding edge things that sit on top on Windows. There are no API's invoved there.

And you raise another interesting point - How long can MS just keep on developing Win32? It's not like they didn't have anything better to do, so they decided to develop .NET and now Longhorn (XAML etc...). They were getting killed by Java. It was much superior to anything they had. .NET was a necessity for them to be able to compete and stop developers from jumping onto the Java bandwagon.

And yet anothing thing to mention about backwards compatibility. They have something called "Interop" in .NET where you can call all the Win32 API's without doing anything special (as in Java where you need special wrappers?). So when you are writing .NET apps, the entire Win32 library is available if necessary. Plus you can interact with your VB and VC++ apps through COM wrappers if needed.

They might lose the API war, but you can't say it was because they weren't backwards compatible.

In conclusion .NET defeated Java (as of today), but MS MAY have lost to MS.

I would say, .NET is good competition for Java, but MS will loose to the Web platform.

MS has a dilema. They want developers to use their platform (IE, ASP.NET) to develop for the web, but at the same time they want to protect Windows. So what it comes down to at the end is that MS is trying for the best of both worlds. They want the convenient development methods of the web but want developers to write Windows apps. These are contradictory strategies and I think this is what will hurt them in the end.

So I blurted a lot more!

Wednesday, January 12, 2005

Did Microsoft lose the API war ?

I'll just discuss a few things in the blog "How Microsoft Lost the API
War" by Joel Spolsky at http://www.joelonsoftware.com.



Here's a theory you hear a lot these days: "Microsoft is finished. As soon
as Linux makes some inroads on the desktop and web applications replace
desktop applications, the mighty empire will topple."

However, there is a less understood phenomenon which is going largely
unnoticed: Microsoft's crown strategic jewel, the Windows API, is lost.



Any of you used Google's Desktop search. Amazing desktop app which starts
a web server locally. I really wonder how they made the app !! Will more
apps be developed in this way? Also we discussed a bit on Rich Internet
Applications before. It is easy to develop those such apps in a manner
independent of the OS.. read flash. So that was one very valid point of
the future apps being more internet oriented. That should hurt MS a lot.


The author mentioned about Windows and Office being the main money-earners
for MS. I had heard that before. But there other apps must be profitable
too!! Any of you have an idea on the other hot-selling MS apps?


Its funny how the author mentioned Apple and Sun. Apple has just had a
great year selling iPods and hope to translate that to better sales of
other products. Sun on the other hand is going to go ahead with (what i
suppose is) the biggest risk ever!! So the entire arena is really hotting
up. I don't remember where I read about why BEA will not being able to
really sell a lot. BEA is a Java company which make application servers
and lots of very high end server stuff. They are the largest competitiors
of IBM on a lot of Java apps. The reason given was simple. Kids don't get to
play with BEA software. Seriously!! Devs were not exposed to BEA tools
till in the co. and so were a little averse to learning new stuff. Why MS
has has such a large developer community was that a lot of kid used MS.
And so obviously used that as a platform OS to develop on. With IBM the
argument is different because they are also a huge services company. Some
other arguments were also made. So that is an advantage for Java and
Linux today. Java is being taught in a lot of courses and Linux has taken
a lot of devs' mind share and "heart share".


The Raymond Chen Camp and The MSDN Magazine Camp section was amazing. Some
very valid arguments were made wrt the break in the Win API. There are a
few points in this regard.


Like all other blogs, I'll converge to Java vs .NET. As I must have
mentioned a zillion times before, parts of the Java API which are changed
to newer versions are not removed. Just marked as deprecated, but can
still be used. That a lot of devs feel is not very good. It does ensure
backward compatibilty but isn't that beautiful.


Mohn had mentioned about a break wrt .NET 1.0 and 1.1. I was of the
opinion that the .NET style of newer releases was better but the blog
changed my views on the topic (but not completely).


MS may have lost the API war wrt to Win32 but they have really taken the
fight to Java. The Java camp was stagnating before .NET came into the
scene. Java 5.0 was released very fast to fix the imbalance, but still has
a long way to go.


At this moment I think .NET is leading compared to Java. I have actually
advised guys to try out .NET rather than Java if they are not interseted
in the politics. Features like STL.NET which Mohn mentioned about should
really attract C++ devs. Dinesh is a good test case for this. Dinesh -
Will you prefer to use .NET or Java? Dinesh has been coding a lot in Java
for different reasons but it will be intersting to know what he would
personally prefer. I have heard about .NET code being written for custom
apps. How much is being used for apps for the general market I do not
know.


In defence of MS, how long is it possible to stretch an API without a
fresh start? They must have had some minimum years to support. MS needed a
new API, to deliver the next generation OS. But some degree of backward
compatibility is a must. Mohn - could you clarify the degree to which the
backward compatibility will/will not be supported?


So is the Linux API (if it exists) a valid alternative? Firstly they do
not have a large user base now and should take quite some time for a
feasible user bas to be set up. The sub components in Linux distro's are
changed too often. With rapid development cycle's I do not think backward
compatibility is given high priority. Hrishi - could you clarify/comment
on this? Wrt open-source Java, guys like me say that compatibility,
platform independence may be broken. Open source guys say that the newer
broken Java if good, will cause automatic adoption, something that I do
not totally agree. So overall I do not think that Linux is viable for
desktop apps??


So the future seems the Web. And don't host your application on your own.
Give it to Sun.


In conclusion .NET defeated Java (as of today), but MS MAY have lost to
MS.


So blurted a lot. What d'you all think?



Sunday, January 09, 2005

Re: Advice for Computer Science College Students


I've heard about Jython and the .NET version (IronPython), but never looked at either one. Does Jython just produce Java bytecodes and thats it or can you also use the Java API? And what dyou think of these ports? Dyou think they are useful?


Jython creates Java class files and also allows usage of the entire Java API. See a simple example here.

One line from the example -
from java import awt //this allows usage of java.awt.*

Actually I am not sure we can call Jython a port of Java or vice-versa. Jython seems more like a simpler front-end for Java. As compilation is necessary, that advantage of the scripting lang is removed.

I do not think Jython is that useful. Newer Java IDE's can make life very simple. Especially VB style drag and drop GUI building. Python by itself seems to have some advantages.

Actually there is another scripting language based on Java called Groovy. I have heard quite a bit if groovy recently. But been to lazy to actually read anything on the topic. Groovy is also currently undergoing standardization through the Java Community Process.


What is Tcl/Tk? How is the Python GUI library using it?


I had mentioned Tcl a few posts back in this thead. Tcl stands for Tool Command Language and it is a scripting language. Tk adds GUI functionality to Tcl. I suppose that rather than creating a totally new GUI, python may have used some of Tk.

Saturday, January 08, 2005

Re: Advice for Computer Science College Students

I did read up a bit on Python. What I got was a lot on the libraries. Could Mohn post a small example of creating a simple Class.

Here are two simple programs which we had as projects. They are reasonably documented so you shouldn't have a problem figuring them out.

This first one is quite simple. It sends a request to a domain name and outputs what server (IIS, Apache, Unix etc...) the site is hosted on. The Java version is almost exactly the same.

from sys import argv
from httplib import HTTPConnection
from httplib import InvalidURL

# -------------------
# printHTTPServerInfo
# -------------------

# Prints the name of the web server the specified URL is hosted on
# url - url of website
def printHTTPServerInfo( url ):
    try:
        connection = HTTPConnection( url )

        try:
            connection.request( "GET", "/" )

            response = connection.getresponse()

            server = response.getheader( "Server" )

            if server == None:
                print "Could not detect what server \"%s\" is hosted on" % url
            else:
                print "\"%s\" is hosted on %s" % (url, server)
        finally:
            connection.close()
        except InvalidURL, ex:
            print "\t--> Not a valid url. Expected format: 'www.hostname.com'"
            print "\t--> %s" % ex
    except Exception, ex:
        print "\t--> An error occured"
        print "\t--> %s" % ex


# Application entry point
if len( argv ) != 2:
    print "Usage: GetHTTPServerInfo "
    print " where is in the format 'www.hostname.com'"
else:
    printHTTPServerInfo( argv[ 1 ] )


The next one is a bit to do with AOP concepts. I had posted something a while back and gave an example using Java. This is more or less something similar. But in this case, you can optionally inject your own functions before and after the method call. One thing to notice is that Python makes it very easy (much more so than Java etc...) to add "dynamic" functions to a class - ie. functions that you don't define when writing the class. If you're interested I can post an explanation for what's happening.

# -----
# Proxy
# -----

class Proxy:
    """
    Intercepts all the method calls to some other class instance, delegating to the same method of the "proxied" class.
    In addition, it allows the user to specify functions that should be invoked before/after the delegation call.
    """

    # --------
    # __init__
    # --------

    def __init__( self, delegate_instance, before = None, after_ok = None, after_exception = None ):
        """
        Initializes a new Proxy object
        params:
        delegate_instance - the object to delegate method calls to
        before - the method to run before calling the called method
        after_ok - the method to run after calling the called method if it is a success
        after_exception - the method to run after calling the called method if it is a failure
        """

        self.delegate = delegate_instance
        self.beforeMethod = before
        self.afterMethodSuccess = after_ok
        self.afterMethodFailure = after_exception

    # -----------
    # __getattr__
    # -----------

    def __getattr__( self, name ):
        """
        Intercepts the specified method call
        params:
        name - the name of the method called
        returns:
        the invocation handler
        """

        self.methodName = name

        return self.InvocationHandler

    # -----------------
    # InvocationHandler
    # -----------------

    def InvocationHandler( self, *args, **kwargs ):
        """
        Invokes called method and any specified methods before and after method call
        params:
        *args - the positional arguments to pass to called method
        **kwargs - the named arguments to pass to called method
        """

        method = getattr( self.delegate, self.methodName )

        if self.beforeMethod != None:
            self.beforeMethod( method, *args, **kwargs )

        try:
            result = method( *args, **kwargs )

            if self.afterMethodSuccess != None:
                self.afterMethodSuccess( method, result, *args, **kwargs )

            return result
        except Exception, ex:
            if self.afterMethodFailure != None:
                self.afterMethodFailure( method, *args, **kwargs )

            raise ex


About size of projects, an application server Zope has been created in Python. So that kind of sets a very high limit for the size of Python projects.

Python is definitely being used for many large and diverse projects. BBC has a project where they plan to put their entire TV and radio archives online. They are using Python to develop some new networking protocols because apparently the current ones won't be able to handle the load.

Python has also got a Java port called Jython. So any code written in Python is converted to Java .class files. The author of the book also mentioned that a .NET python version may be released some day.

Ya I've heard about Jython and the .NET version (IronPython), but never looked at either one. Does Jython just produce Java bytecodes and thats it or can you also use the Java API? I would think that the whole point would be to enable using the libraries since Python already has a lot of features that the JVM/CLR provides - garbage collection, exception management etc... And what dyou think of these ports? Dyou think they are useful?

The python GUI library also uses Tcl/Tk in some way.

What is Tcl/Tk? How is the Python GUI library using it?

The next module is on Databases, queries and internals. What stuff do you guys know on the topic. So far the most complicated queries I have ever tried are "SELECT * FROM MYTABLE"!!

Not a lot. Just the basic SELECT, INSERT, UPDATE, DELETE stuff and a bit on Stored Procs (not writing them, just using them). So good topic to post stuff on!

We should have a discussion on the How MS lost the API war blog which Mohn linked to. What did you guys think of it?

I read it when he posted it, so its been a while. I'll go over it again and post my thoughts. Why don't you start? And Hrishi, Dinesh and Nikhil - we'd love to read your 2 cents too.

Re: Advice for Computer Science College Students


What is the size of a python project after which it becomes unfeasable?

Generally, these scripting languages are not suited for large apps because they quickly become unmanagable. But people don't seem to have a problem with Python for huge apps. It has a huge library framework a la Java/.NET.

Python is an OO language. It's not strict like Java... more like C++ in that you can have functions and data NOT associated with a class. Plus, apparently it has a close relation with C/C++. So if there is some functionality that is not available you can create it with C/C++ and "expose" it in Python.


I did read up a bit on Python. What I got was a lot on the libraries. Could Mohn post a small example of creating a simple Class.

About size of projects, an application server Zope has been created in Python. So that kind of sets a very high limit for the size of Python projects.

Python has also got a Java port called Jython. So any code written in Python is converted to Java .class files. The author of the book also mentioned that a .NET python version may be released some day.

The python GUI library also uses Tcl/Tk in some way.

I wonder how easy it is to use MVC patterns or any others in Python code!!

Some other stuff...

My Networking module just got over. The next module is on Databases, queries and internals. What stuff do you guys know on the topic. So far the most complicated queries I have ever tried are "SELECT * FROM MYTABLE"!!

We should have a discussion on the How MS lost the API war blog which Mohn linked to. What did you guys think of it?

Friday, January 07, 2005

Re: Advice for Computer Science College Students

Lots of blogs queued up in my head!!

Great! They're much needed. This place is becoming pretty lonely again.

What is the size of a python project after which it becomes unfeasable? And will co's adopt it? The advantage of faster development will sort of
be reduced by a need for better testing.


That's the thing. Generally, these scripting languages are not suited for large apps because they quickly become unmanagable. But people don't seem to have a problem with Python for huge apps. It has a huge library framework a la Java/.NET. It doesn't seem as well organized or documented, but it's there. Plus Python is Open Source so there is a huge community behind it with a lot of external libraries.

Tcl can be accompanied by other tools - OTcl and Tclcl. OTcl provides Object-Oriented functionality to Tcl. Tclcl helps in linkage between OTcl
code and C++ code. Does Python support OOPs, and/or C++ linkage?


Python is an OO language. It's not strict like Java... more like C++ in that you can have functions and data NOT associated with a class. Plus, apparently it has a close relation with C/C++. So if there is some functionality that is not available you can create it with C/C++ and "expose" it in Python. As you can imagine this is a pretty advanced topic - I just scanned through the page. Anyway, this is a pretty huge feature considering they have the OS community to keep adding features.

Another possibility is that co's develop in Python but convert the code to compiled before being deployed. (I have made dumber suggetions before!!)

Nope not dumb at all. You're talking about prototyping. At one time VB used to be popular for that. It was so easy to cook something up (RAD) and do some initial testing. Once it was accepted, convert it to a C++ app and ship it. But it seems a lot guys just stick with Python all the way through.

Wednesday, January 05, 2005

Re: Advice for Computer Science College Students


Sriram Krishnan posted a reply to the "Advice for Computer Science College Students"


Definitely read the reply when I get connected to the net!!


I'll just comment on one thing. He's mentioned Python and given it a glowing reference

Python is a dynamic language. It is strongly typed, but all the checking is done at
runtime. Nothing is done at compile time. When declaring variables you don't give them a type. A type is automatically inferred when it is assigned something. So if you've made a mistake, like use a variable is a way it wasn't supposed to be used, you will only become aware of it at runtime, if at all. I say if at all because only if your execution path leads to that piece of code will it throw an exception.

What Python has going for it is rapid development. Since there is no compile step, development is faster. But is this a valid tradeoff?


Very recently I used another scripting language Tcl. Actually used it as
part of a larger project to study a tool - Network Simulator (NS2).
Basically I am no authority on scripting languages either. I'll probably
post on that some time later. Lots of blogs queued up in my head!!

What is the size of a python project after which it becomes unfeasable?
And will co's adopt it? The advantage of faster development will sort of
be reduced by a need for better testing.

Tcl can be accompanied by other tools - OTcl and Tclcl. OTcl provides
Object-Oriented functionality to Tcl. Tclcl helps in linkage between OTcl
code and C++ code. Does Python support OOPs, and/or C++ linkage?

NS2 is a Network Simulator (I know its obvious!!). The project is used to
create virtual Networks on which tests can be run. C++ is used to create
compiled entities used within simulations, like Nodes, Links, etc. Users
generally use OTcl to create the simulations for which rapid development
is necessary.

Another possibility is that co's develop in Python but convert the code to
compiled before being deployed. (I have made dumber suggetions before!!)

In the end maybe its just a question of mindset. Probably I too will "see
the light" someday.

Rahul

Re: Advice for Computer Science College Students

Sriram Krishnan posted a reply to the "Advice for Computer Science College Students" article - Why Joel is wrong (or) Advice for *Indian* Computer Science Students. His reply is interesting for two reasons - 1) He's a 21 yr old dude doing CS. 2) He's studying in India.

I'll just comment on one thing. He's mentioned Python and given it a glowing reference (sarcastic or not). I've noticed Python getting a great reputation of late and picking up steam on the web. A lot of smart guys are recommending it (Bruce Eckel being one of them). I have to say, I don't get it. I did a bit of Python last semester. Very little, so I can't say anything about it with a great deal of authority. But from what I saw, I didn't get why it was such a big deal. If anything I thought it was super super easy to make a ton of mistakes.

Python is a dynamic language. It is strongly typed, but all the checking is done at runtime. Nothing is done at compile time. My biggest beef with Python is that you don't declare variables. You just use them as and when needed. A type is automatically inferred when it is assigned something. So if you've made a mistake, like use a variable in a way it wasn't supposed to be used, you will only become aware of it at runtime, if at all. I say if at all because only if your execution path leads to that piece of code will it throw an exception. And I won't even get started on the potential for nightmarish logic errors. If you misspell a variable, it's not a compile time error. It'll work fine.

What Python has going for it is rapid development. Since there is no real compile step, development is faster. But is this a valid tradeoff? As I've mentioned, I've not had enough experience with Python so everything I've said can't be taken too seriously. But so far, I'm not convinced. In time, maybe I will "see the light" and learn to appreciate it.

Re: Post blogs by email

Can we post pics on blogspot btw?

Short answer is yes, but it's not very convenient. You have to download a client app (actually two apps) to do it. Google bought a photo organizing software company called Picasa some time back. Now they're trying to integrated all their properties. They have another app called Hello that works with picasa from which you can post to your blog.

Post blogs by email


I am testing this feature of blogger wherein I send an email to blogger
and it gets posted as a blog.

You can set it up at Setting >> Email.

Hopefully I'll start posting more often now.

Rahul

Ps. So do not get suprised if my blogs are more email-like.

Also I wonder how they'll support MIME messages with pics and all. Can we
post pics on blogspot btw?




Monday, January 03, 2005

Advice for Computer Science College Students

An essay by this dude for aspiring programmers.

Here are his points...

---
1. Learn how to write before graduating.
2. Learn C before graduating.
3. Learn microeconomics before graduating.
4. Don't blow off non-CS classes just because they're boring.
5. Take programming-intensive courses.
6. Stop worrying about all the jobs going to India.
7. No matter what you do, get a good summer internship.
---

You can skip point 6 ;-)

This guy has quite a reputed and popular blog. If you go over some of his archives you can see the quality of the topics (ex How Microsoft lost the API war). A publisher is actually putting out a book of his essays.

Anyway, regarding the essay itself, I think he makes some great points.

Points 1, 3 and 4 are basically there to encourage you to be a more "rounded" individual. Don't just know one thing... try to expand your horizons type thing. This is fine, but I don't see it being a NECESSARY quality for aspiring programmers.

Point 2, it's something we have discussed briefly before. Languages like Java, C#, Python etc... are becoming more popular and shield you from lower level stuff. Many colleges (in the US) are shifting or have already shifted to using Java as the language of choice. And since most CS curriculums hardly focus on languages, you don't get any exposure to C or even C++. This is both good and bad. Good in that the professors don't need to focus much on the language - Java is easy enough to pick up and you have less potential to blow your head off that very little time is spent teaching the language and more on actual course material. Bad in that you don't know what's actually going on under the hood. As a CS major you would be expected to know it and you aren't taught it. Like I said, this is the trend in US colleges. I think in India C/C++ is still in heavy use in colleges and even some older languages?

I can't agree enough about point 5. We have also discussed this before and he sort of reiterates our arguments - the practical vs theory stuff. However, it should be noted that he is looking at this from purely a software development perspective. Computer Science is a vast field and theory plays a large part in it. There isn't a lot of room for this theory in everyday programming, but it is important if you're looking for that kind of work. I'm sure the Google Labs guys are heavy on this stuff.

Point 7 is just about getting some real world experience before getting out of college. There's a huge difference between what you learn in college and how it's applied practically. It helps to see that and try to connect the two (if possible ;-)).

Saturday, January 01, 2005

Happy New Years

Happy New Years to all of you!!

and the look is fine.

Friday, December 31, 2004

New Look

I thought with the beginning of the new year codeWord could do with a new look. What dyou think? Suggestions are welcome.

Keep them posts coming. Happy 2005!

Wednesday, December 29, 2004

Java Operator Overloading

I saw this comment somewhere...

---
Even if it is trivial to add operator overloading to Java and to make it simple to use, are you absolutely sure its a good idea?

Operator overloading violates one of the central tenets of the Java language design; transparency. If you look at any piece of Java code (no matter who wrote it or where its from) you can easily figure out exactly what it does. There is no "hidden" information; everything is stated explicitly. This philosophy makes Java an ideal language for Open Source and business programming where there may be many different contributors over a long period of time. It is easy to dive into a class, see what's going on and make any modifications necessary.

With operator overloading (and many of the dubious "improvements" made to the Java language in Java 1.5) we lose this transparency. External declarations not referred to internally can completely alter the meaning of a section of code.

That's bad.

Of course, some people don't agree that this emphasis on transparency is useful, so they program in (or at least advocate) other languages (like for example Lisp, Nice, or C++) where the language can be modified and transformed willy nilly. This kind of thing makes an interesting intellectual exercise; it does not however make for a good social environment to program in. For these people, Java must seem limited. However, the vast majority of programmers have rejected this approach (with some relief!) and now program in Java (or its evil twin C#)

The String concatenation argument is often brought up by advocates of operator overloading in Java, and in a way they do have a point; that operator overloading can be useful. That is, it WOULD be useful if it didn't compromise code transparency so flagrantly! There is one big difference between String operator overloading and arbitrary operator overloading. When I sit down to maintain your code, I know what the String "+" operator does; it's in the Java Language Specification. On the other hand, I have no idea what your overriding of the "+" operator does on your "CustomerRecord" class. That is, if I can Without prior knowledge, I can't even tell if an operator is overridden or not!

Operator overloading is indeed not high on Java programmers list of desires (at least those that understand the design philosophy of the language). Rather, the very mention of it provokes feelings of fear and disgust. And rightly so! To those who would like to return to the days where every day was an obfuscated C contest, and where knowledge of the actual language didn't translate into ability to understand and maintain code, I say go elsewhere; to the lands of C++, Perl, Python and their ilk where you will find yourself in eerily familiar territory. Or if you hang around Java long enough you will probably see it ruined by people such as yourself screaming at Sun for more "improvements" along the same lines as Tiger.
---

I agree with his point of transparency. When you're reading someone else's code or even your own code after some gap, trying to make sense of it is difficult. That's why trying to write "clean" self documenting code is important. And it's the reason why "simple" languages like Java and C# are becoming more popular. There are limited (often only one) ways to do things. It's one of the reasons I don't like the C/C++ typedef statement. Most of the time you can't make sense of what the underlying type is.

In the case of operator overloading I disagree with him. I don't think it destroys transperency. If anything I think it makes the code more understandable. Operator overloading is just an abstraction over methods. And it's not like you can overload any operator. There are only a limited and well know operators that have a standard universal meaning that can be overloaded. Yeah, there is potential for abuse, for example, by overloading + to subtract instead of add, but there is nothing stopping anyone from subtracting in an Add() method either.

Tuesday, December 28, 2004

GLAT

This one's pretty old, but incase you hadn't seen it. It's the Google Labs Appitude Test. Check out the four pages here, here, here and here.

They could've saved a lot of trees but just saying "Anyone with an IQ below 140 need not apply".

Scott McNeally at his best

http://www.theregister.co.uk/2004/12/23/mcnealys_xmas_dream/print.html

Friday, December 24, 2004

The Concurrency Revolution

Herb Sutter, a C++ heavyweight, writes about the next evolution in programming in The Free Lunch is over: A fundamental turn toward concurrency in software. He acknowledges that Moore's law is going to (has already?) hit limitations and that old single threaded applications won't just magically gain performance as processor speeds increase. As a way to counter the limitations, processors will increasing turn to "parallelism", but apps will need to be tuned to enjoy the benefits.

One thing he mentions in the article is that it will be similar to the OOP shift during the 90s with a similar learning curve. I think that the learning curve is going to be much higher. I haven't really done multithreading programming, but I have read about multithreading in Java and .NET and was briefly introduced to it in one of my classes (I suppose OS will have a much more comprehensive coverage of it). Multi-threading is inherently extremely hard to get right. Our brains are designed to think sequentially. Programming for parallelism is really hard. Even with simple multithreaded programs there are SO many ways to mess up. And because there isn't a straight line to follow, debugging is anothing nightmare.

I think to become as wide spread as OOP, where everyone can easily adapt to the paradigm, it needs to be simplified. Java and .NET have threading built into the platform, which is a start. They have made it easier, but it's still a huge learning curve. Just like we have "Hello World" intro programs, we'll need to start having "Hello Parallel Worlds".

Tuesday, December 21, 2004

EPIC 2014

http://www.broom.org/epic/

Where dyou think the future of online news is heading?

Monday, December 20, 2004

STL.NET

I had mentioned in a previous post about C++ being adopted to .NET. I also mentioned that the .NET guys were thinking about how to include the STL functionality in the .NET framework library. Well, C++ is special in that it supports different programming paradigms. So they've come up with STL.NET.

Stan Lippman, who is one of the dev's on the project has written an article about it. Here's the summary...

For the experienced programmer, the hardest part of moving to a new development platform such as .NET is often the absence of familiar tools through which she has honed her skills and on which she depends. For the experienced C++ programmer, one such essential toolkit is the Standard Template Library (STL), and its absence under .NET until now has been a significant disappointment. With Visual C++ 2005, we fix that by providing an STL.NET library. This article, the first in a series, provides a general overview of the STL program model using STL.NET – it discusses sequential and associative containers, the generic algorithms, and the iterator abstraction that binds the two, using plenty of program examples to illustrate each point. It begins by briefly considering the alterative container models available to the .NET programmer using C++ -- the existing System::Collections library, the new System::Collections::Generic library, and, of course, STL.NET. To provide for the widest readership, this article does not require familiarity with the STL library; however, it does presume some experience with the C++ programming language.

Wednesday, December 15, 2004

Re: which is faster : C or C++?

So, if I want to write such code (if?... hell I DO have to write such code), which is a better option - C or C++? In this case, is it right to say that you could use all the good organisation and 'cleanliness' of using classes and get the same performance if you let go of virtual functions?

I guess you've answered your own question. It's clear that your most important criteria is performance. And since you're only debating on C vs C++, C is more "lightweight" and you should be able to grind out more instructions/cycles with it.

But again, you are the only one who knows enough about your project to make the decision. Generally, you'd need to consider a lot more than just performance when choosing languages. In your case, you're deciding between C and C++. C++ (as we've all agreed) has a lot more to offer over C. But at the same time, you loose certain advantages that C provides - one of them being performance (and again this can be argued forever).

Looking at your project, would OOP be helpful? Dyou think that having classes will help in organizing and designing your project in a "better" way than C with its separation of functions and data? Think about the bigger picture rather than debate about "malloc()" vs "new".

BTW, post some info about your project.

Tuesday, December 14, 2004

Re: which is faster : C or C++?

I guess I didn't pose my question very clearly... will try to do it in this post. First of all, I must clarify that I am as big a fan of C++ as anybody can be and I'd choose C++ over C almost ALL the time unless it's absolutely necessary to use C. It's that particular 'absolutely necessary' case I'm examining here. All the things you guys have written make sense and I agree completely.

While that little function overhead is insignificant in most cases and is nothing compared to the IMMENSE additional flexibility and functionality that you gain, it would be worthwhile contemplating under what circumstances this overhead could become significant. Codes that go into CFD applications can take ridiculously long time to execute. Let's say a C++ code that does the same thing as a 5 sec C code takes 7.5 sec to execute. Doesn't seem much... you don't give a damn. Stick to C++. But when you're talking about 50 and 75 DAYS, the difference is HUGE. And I'm not kidding here. There are codes which take that long to execute.

So, if I want to write such code (if?... hell I DO have to write such code), which is a better option - C or C++? In this case, is it right to say that you could use all the good organisation and 'cleanliness' of using classes and get the same performance if you let go of virtual functions?

Once again, except for this case of infinitely large execution times, C++ is a better option than C... no doubt about it. But what about this case?


Saturday, December 11, 2004

Re: which is faster : C or C++?

Primarily what I love about C++ is the STL. It has never given me more pleasure to see a library in action. Granted that the organisation of the STL reflects the fact that there were multiple design heads involved but yet it's the most beautiful piece of code I have ever seen.

I dunno if I can say it's the most beautiful piece of code (I haven't actually read the source), but I fully agree with you that it's a fantastic library. The way they have designed it, with such a wonderful separation of containers, iterators, algorithms and functions is quite brilliant.

Whats even better about C++ is it doesn't force a programming paradigm on you, it lets you design your solution in any way you wish, so if you want to have a C style program, well just go right ahead!!

Agree again. The best thing about C++ is that it gives the programmer a lot of freedom. It supports procedural, object oriented and generic programming. I don't think there's any other language that does that. Microsoft is also fully integrating it into .NET in the next version of their compiler, so it will support garbage collection and will have access to the Base Class Library. Just another way C++ can be used.

.NET and Java are supporting generics in their newest versions. Naturally they are looking at C++ for ideas. But I feel the won't be able to come up with as elegant a solution as the STL because they only support OOP. Some proposed functionality I've read about for the next version of .NET collections is quite ugly. Like including same algorithm functionality in each collection. There is no iterator abstraction, so each collection in a way is different. It's a dilema for them. How to support all the functionality in an OOP way. It'll be interesting to see what they finally come up with. Haven't seen how Java handles it.

Always remember that C++ was meant to be a better and "safer" C.

The general trend it seems is that all the guru's (i.e. Bjarne and friends) are encouraging to make use of more abstractions and use the STL in the name of convenience, maintenance and safety. For ex. Go for vectors instead of straight arrays, Use as little manual memory management as possible or if you need to play with pointers go for some of the safe versions available through STL and boost. I took a course on generic programming where we used the STL. We hardly new'd and delete'd. It's a testament to C++'s flexibility. It's able to adapt to the evolving paradigms.

virtual functions are implemented using a lookup table that gives you a function pointer for each derived class type. Thus, these kind of functions can simply not be inlined

If a compiler is smart enough, it should be able to inline some calls to virtual functions. There's a way to explicity (statically) call virtual functions...

class Base
{
     public:
          virtual void Function1()
          {
               cout >> "Base::Function1";
          }
};

class Derived : public Base
{
     public:
          virtual void Function1()
          {
               cout >> "Derived::Function1";
          }

          void Function2()
          {
               Base::Function1(); // can be inlined
          }
};


Correct me if I'm wrong about this fact. Or if this particular example is wrong.

I think the guys designing and implementing C++ were as concerned about performance as anyone. They did everything possible for limited performance hits. I don't think anyone can fault them. Dinesh had recommended a book long back called "The C++ Object Model". It gives you a good idea about how they implemented a lot of the features. Virtual functions and polymorphism in general is discussed at length. And they give a lot of examples in CFront. So you can see what C code is generated.

Friday, December 10, 2004

Re: which is faster : C or C++?

Obviously, I am interpreting this question as structured vs object oriented programming. I personally have used C++ for ages, without caring to make a class -- and i really appreciate the fact that it dosnt force a programming paradigm on us :)

Regarding optimization, one thing is clear -- especially in the GNU context: GCC does optimization on an intermediate form of code that it derives from the front-end language like C or C++. Hence, optimization must be just as good for both. In fact, I believe that taking the CFront route (C++ -> C -> ASM) instead of the GCC route (C++ -> ASM) will produce assembly that's just as good, but will take much longer to do so.

So, what the point? How is C++ optimization different? I'd say that the "optimization needs" of a C++ program are different.

Let's take an illustrative historical case of encapsulation -- encapsulation brought in a new era where the number of functions written by a programmer increased manifold! Firstly, because C++ dissuades the use of macros, and secondly, because there is a higher tendency of making constructors and destructors in C++, whereas in C, you'd type in the whole thing each and every time you needed it. Thus, older compilers who did not have good enough support for inlining functions, often failed to produce overall good C++ code.

Of course, any self-respecting compiler today has really good inlining support, so this example I have given probably no longer holds. So now, lets move on to simple polymorphism: virtual functions are implemented using a lookup table that gives you a function pointer for each derived class type. Thus, these kind of functions can simply not be inlined, and they also use "jump to address in a variable"; something like this: (*var)(). A programming style that enforces use of such control jumps is BAD. The reason is that most computer architectures today have built-in support for branch prediction and usage of such statements defeats their purpose. I do not deny that you can do this in C as well; but you would usually not! Whereas, the use of virtual functions in C++ is almost a norm!

I have no idea about multiple inheritence etc., god knows why they created such a feature! Also, I have never used STL, so I don't really know how the widespread use of STL influences the optimization needs of C++ code.

All said, I definitely agree that C++ is a wiser choice than C for any hardcore hosted developmental work, because of lesser development time. I just seriously recommend restricting polymorphism to only those places where it really really simplifies things.

BTW, G++ usually produces bloat in the form of a symbol table, that's used for debugging etc., it won't even be copied to memory... just sits on your harddisk.

Google Suggest

http://www.google.com/webhp?complete=1&hl=en

Yet another innovation from everyone's favorite company. Go through the alphabet to see what the suggestions are. Some are pretty interesting (ex. 'p').

Re: which is faster : C or C++?

I agree with Mohnish here. When comparing languages for implementing something you gotta see what suits the purpose best. The cost for virtual functions and polymorphism in C++ is a single virtual table pointer in each object and the resolution of those pointers and what exactly should be called based on the heirarchy of class implementation. But what you get for that is a whole new paradigm under your control. A whole new world view if you will. No more is programming based on thinking about what piece of information is processed when rather we are supplemented to talk in more abstract or high level terms.

A language which gives you the power to do object oriented programming at the cost of a single virtual table pointer is a piece of work in itself. Primarily what I love about C++ is the STL. It has never given me more pleasure to see a library in action. Granted that the organisation of the STL reflects the fact that there were multiple design heads involved but yet it's the most beautiful piece of code I have ever seen, if you don't agree just open up the algorithm or functional standard header and read for yourself, it's beautiful!! :) Whats even better about C++ is it doesn't force a programming paradigm on you, it lets you design your solution in any way you wish, so if you want to have a C style program, well just go right ahead!! Always remember that C++ was meant to be a better and "safer" C.

Over C, I'd choose C++ anyday, besides I hate writing the cumbersume printf() statements for everything, cout is so much better :) (ok, that was my cheesy joke for the day! sorry!!)

Put things in context and you'd see that C++ gives you a lot more than C, atleast thats what I think. One gripe I have with the g++ compiler is that it produces a lot of code, the -strip option does work well but still I have never been able to figure out what bloat code it writes! But then again with memory so cheap now it doesn't really matter.

By the way, can you factually prove that C++'s optimization is not as good as C(or were you saying something else)?? The g++ gives three levels of Optimization - O1, O2 and O3, all my programs are compiled with the -s -O3 options (releasable code that is). C++ by it's very design allows the compilers a lot of lee-way as to what it can optimize. And the GNU compilers sure do make use of it!

All in all whatever the speed comparisons, if I had a big project to work on, I'd be betting on C++ to get the job done in a good and maintainable way!

Dinesh.

Wednesday, December 08, 2004

Re: which is faster : C or C++?

which is faster : C or C++?

I think it would a good idea to first define "faster". What exactly do you mean? Faster in what context? In a one line program or in a 100,000 line program? And how do you analyse the performance?

Personally, I feel it's an exercise in futility to compare what language is "faster" than the other. The reason I feel that way is cause you'll find studies and papers claiming that each language can beat every other one.

Use of virtual functions and run-time polymorphism slows down the code a little. So if this feature of C++ is not used, C++ code would run as fast as C code.

I think this is a wrong approach with which to look at C++. C++ was created to be a "better" C. You can take that to mean whatever you want (everyone has their own opinion about why it's better (if at all)). From what I understand, as applications started getting larger, using C to develop them was getting to be a pain in the arse. They needed something that would make it easier to write maintainable code (Isn't code always easier to write than read?). Enter C++. It created another level of abstraction, just as C created an abstraction over assembly, and assembly over machine code, and machine code over gates, and gates over the 0s and 1s, and the 0s and 1s over the electrons... you get the picture (did I miss a level?).

Anyway, my point (yeah I have one!) is that if you look at C++ feature by feature and look to eliminate something so as to get it to run as "fast" as C... you might as well cut to the chase and go play with electrons.

Having said this, the difference between run times is due to the compilers and not the languages themselves. Last I heard, C++ compilers don't optimize C++ code as well as C compilers optimize C code.

Did you know that the first C++ compiler (CFront) generated C code... not machine code? So any optimization made to C compilers would apply to C++ code as well. Today, every C++ compiler most likely generates native code, but I don't see any reason why they would be any less optimizing than C compilers.

Again the abstractions bit comes in. It's all about the amount of control you (the programer) want to have. You can write programs with 0s and 1s if you want to... you got all the control in the world. I wouldn't imagine it would be very fun to do it, but you can if you want to. You sure as hell won't be very productive. Just as you lost some control when you went from C to C++ (like creating/destroying objects, does multiple things... you don't have control over the entire process), going from C++ to Java/C# you lose even more control. But what you gain is productivity.

The code that goes into CFD applications handles millions of points, so even a little function overhead (eg virtual function) is significant.

I read this on some (smart) dude's blog about performance: "Always set goals and always measure". What's good enough for you? If you code the app in C++ and it's slower than it was with C, but good enough then does it matter? Depending on how good you are with each language you might be a lot more productive with C++. So it's a tradeoff.

Bottomline - if virtual functions, run-time polymorphism isn't used, C++ code would run as fast as C code.

There are a lot more abstractions than just virtual functions in C++, so I doubt if you just avoid that if it would make a huge difference.

For starters, about me -- I have no clue to Java; I'm pretty good at C on UNIX/Linux etc and I can bear C++.

Firstly, cheers on your first post. Hope to see a lot more.

Just to give a brief intro to what we dudes are about...
Hrishi - (you probably know more) C/Linux
Rahul - Java/Linux
Dinesh - C++/AI/Game engines/Philosophy
Yours truely - C#/.NET/Bit of Java/Bit of C++

PS: Did you guys know we guys here call Hrishikesh, "Micro"? Micro?! Huh! near Mega you'd say... well... but then it all started from a Micro-elephant :D

Dyou see the archive links on the right hand side of the page? Go to November 2003 and check the very first post's title and ask Micro to explain it. Post your reaction.

Hey guys!

Ok, looks like Hrishikesh has plucked the right string there... C/C++ usually gets me started :-)

For starters, about me -- I have no clue to Java; I'm pretty good at C on UNIX/Linux etc and I can bear C++. Regarding my ignorance of Java, all I will say is that the "Hello world!" I wrote took so long to start off that I gave up :D Well, maybe though, my body and soul is written in Java. See, Mohnish added me to the blog almost a week ago. And my first post comes now. Pretty much like the Hello World I wrote... took a looong time to start, but worked fine after that. (bad joke -- you said this was the place :P)

I am looking forward to seeing your comments on C vs C++. In fact lets add Java to it! Let's see what you hard-core Java fellows have to say about the efficiency of object oriented features that Hrishikesh (in my opinion, correctly) labels as having sub-optimal implementations in C++. What about Java?

I will come up with a post detailing what I like and dislike about C++ soon...
Till then,

PS: Did you guys know we guys here call Hrishikesh, "Micro"? Micro?! Huh! near Mega you'd say... well... but then it all started from a Micro-elephant :D

which is faster : C or C++?

Let's reignite this age old debate; well maybe not all that age old but definitely something worth discussing. It is a widely regarded notion that C is faster than C++ though I havne't found any concrete reasons or literature to support this claim.

This is what I have inferred from what I have read -

Use of virtual functions and run-time polymorphism slows down the code a little. So if this feature of C++ is not used, C++ code would run as fast as C code.

Having said this, the difference between run times is due to the compilers and not the languages themselves. Last I heard, C++ compilers don't optimize C++ code as well as C compilers optimize C code.

The code that goes into CFD applications handles millions of points, so even a little function overhead (eg virtual function) is significant.

Bottomline - if virtual functions, run-time polymorphism isn't used, C++ code would run as fast as C code.

Thoughts, comments, links?

Monday, December 06, 2004

Re: Is Some Software Meant to be Secret?

if I provide source of my app, don't I have to provide it during developement phase too?

Isn't this normal practice for open source apps? Couldn't you download daily builds of Firefox?


Yes. Thats why I felt that Tim Bray mentioning that if a super feature is being included it will not give an advantage to rivals till released. Maybe their design would be different but an idea could be incorporated.


I think a major difference between closed source apps and open source counterparts is that open source doesn't really have a strong sense of versioning. It is a very iterative process. Using FireFox as an example... people have been using it way before they released 1.0. It's part of the "culture". You're expected to keep up.

I disagree here. The users of open source API's are generally more adventurous, but the feature set for each version are generally clearly defined. If more co's start using open source products, they will be more slow to update versions and even take beta releases.


How does Sun do it for Java APIs?

I am not sure about the Java API. The Java JDK has been released as a project at java.net. This is a Sun site where loads of open and not-so-open projects are hosted. So you can start off with Java 6.0 today. Sun has mentioned that they are going to provide faster releases in the future.




MS sees a subscription based model as the future.

Dyou really think this model will work?


Dunno. Any new model will take time for adoption. Sun is actually doing it now. It seems scary but it seems more correct to me. In todays world everything is connected to the net. For a co. (who buy software) subscription seems better as they get new releases. Can switch after a year with lower costs. Lots of co's pay loads for new software. That leaves them with old versions very soon. And a lesser functionality version can be passed to the kids to play with. Everyone it seems, would be much more happier. Subscription is like your cable or cell. Its just that we are not used to it now. And with web-services this model seems even more easier to implement.



I just do not see the need to please anyone else

I was joking. You know... going public as in getting listed on an index like Nasdaq and so pleasing our shareholders. Maybe I should make more use of ';-)' in the future ;-)


Dude. That would not compile. Here's why..
1. class shareholderJoke extends nasdaqPatheticJoke {} --- missing
2. And the ;-) Annotation was missing too. (Yup.. I still do not know how to write Annotations!!)


And BTW, we do have a new member but he's been quiet. Hrishi's pal from IIT, Nikhil, is the latest codeWordian (too cheesy?). Let's have some posts dude.

Welcome aboard. This (as you might have realised) is the place for really bad jokes. Might get a bit of knowledge once a while.

Sunday, December 05, 2004

Re: Is Some Software Meant to be Secret?

if I provide source of my app, don't I have to provide it during developement phase too?

Isn't this normal practice for open source apps? Couldn't you download daily builds of Firefox?

I think a major difference between closed source apps and open source counterparts is that open source doesn't really have a strong sense of versioning. It is a very iterative process. Using FireFox as an example... people have been using it way before they released 1.0. It's part of the "culture". You're expected to keep up. So the release/development phase is sort of blurred. It's not really the case for closed source apps. There's a clear separation. So even if these closed source guys open their code, it would most likely be with the final release. How does Sun do it for Java APIs?

MS sees a subscription based model as the future. I think Web-services will play a big role in this. Sun has a subscription model for JDS and plans something similar for Solaris 10. They even want to offer grid computing wherein the customer simply pays for CPU cycles. So the revenue model is changing.

Dyou really think this model will work? Somehow I can't imagine it will ever be successful. This idea of pay per use will be too hard for many people to swallow. People are used to the idea of owning their software and using it however they want. Moving to the subscription model won't be easy because you're not in control. At anytime, anyone can cut off your access. I think MS did some trials in a few countries and it bombed. Maybe it would work in large companies where there might be a possibility of cutting costs. But for personal use - I highly doubt it.

There should be no pressure on us. We continue what we do. If someone else is interested, they join. Simple. I just do not see the need to please anyone else

I was joking. You know... going public as in getting listed on an index like Nasdaq and so pleasing our shareholders. Maybe I should make more use of ';-)' in the future ;-)

And BTW, we do have a new member but he's been quiet. Hrishi's pal from IIT, Nikhil, is the latest codeWordian (too cheesy?). Let's have some posts dude.

Re: Is Some Software Meant to be Secret?

Tim Bray and Microsoft's Joe Marini

To open source or not. Tis is a very big question.

Wrt the articles, if I provide source of my app, don't I have to provide it during developement phase too? In that case any new feature can be picked up by a rival before its out in the market and then any major benefits may be lost.

If the source is not provided early, then it can be argued that the project is not really open-source.

It depends a lot on what is the source of revenue for the company. If you have a large user-base then money can be made through subscription too. Disruptive technology was pointed out in some previous blog. Lots of open-source are basically destroying closed-proprietary apps. Users can get similar or better features for free and no one wants to pay - like firefox. Unless you have a major app for which there is no competition only then can you afford being closed. But eventually some open-source app will catch up and then you'll not have much of a choice. Basically it depends on the project and the team. For newer applications I think it makes more sense to be open. But then again a proper source of revenue has to be thought of.

MS sees a subscription based model as the future. I think Web-services will play a big role in this. Sun has a subscription model for JDS and plans something similar for Solaris 10. They even want to offer grid computing wherein the customer simply pays for CPU cycles. So the revenue model is changing.


Ok that's two for going public. I guess we'll do it. But remember, that puts pressure on us to please the shareholders.

There should be no pressure on us. We continue what we do. If someone else is interested, they join. Simple. I just do not see the need to please anyone else


Saturday, December 04, 2004

New India Glimpses

From this dude's blog. Subscribe to it!

New India Glimpses

India is witnessing amazing change. While life on a day-to-day basis
still has its challenges (poor road infrastructure, erratic power,
limited bandwidth, growing urban-rural divide, quality and
availability of education, a population that is still growing more
rapidly than available resources), there is a lot that is happening to
augur well for the future.

Cellphones: Recently, the number of cellphones in India passed the
number of landlines. This is not just a statistical milestone. It
signifies the choice that Indians are making. By leapfrogging to a
wirefree world, communications in India is being transformed, and so
is life. Hoardings in Mumbai announce the availability of TV via EDGE
networks and railway reservations via the handset. About 2 million new
users a month are being added to the current base of about 45 million
cellphone users. India has one of the lowest tariffs in the world for
mobile telephony. Text messaging has become a way of interaction for
many. Value-added services like ringtones and gaming are growing.
State-of-the-art networks and feature-rich handsets across India are
beckoning the next set of users. Cellphone companies are profitable at
average monthly revenues of Rs 400 ($9) per user.

Cable TV: A hundred channels for all of Rs 250 ($5.50) – that's what
about 55 million households pay to enjoy their television. And there
is no dearth of new channels launching every month. I still remember
the launch of Zee TV, India's first private channel – it happened just
over a decade ago. A mélange of cable companies are now tying up with
Internet Service Providers to offer "broadband" (more like, always-on
narrowband) Internet to homes.

Wireless Data: Reliance Infocomm's CDMA-based wireless data networks
covers more than a thousand towns and cities across India. Lottery
terminals, ATMs and even credit card authorization terminals are using
it to connect to centralised servers. Providing speeds of 30-60 Kbps
(versus a theoretical maximum of 115 Kbps), these data networks are
also providing laptop users the ability to connect to the Internet in
under five seconds for 40 paise a minute (less than a penny) from
almost anywhere in urban and semi-urban India.

Cybercafes: Even as the cost of ownership of a computer remains high,
thousands of cybercafes function as "Tech 7-11s" in neighbourhoods.
Sify's 2,000 iWays offer not just Internet access, but also Internet
telephony and video conferencing.

Internet Telephony: I still remember the time a few years ago when
phone calls to the US cost nearly Rs 100 a minute. The other day, one
of the VoIP company sales representatives came calling offering calls
for less than Rs 2 a minute. Smart Indians are also buying by Vonage
boxes in the US and getting them to India to make calls to the US for
a flat rate of $30 (Rs 1,350) a month. Geography indeed has no
barriers!

eCommerce: For all who think we have been left behind in the b2c
revolution, think again. Indian Railways and Deccan Airways have
proven that Indians will pay for transactions over the Internet. The
Indian Railways website address one of the major pain points in the
life of many – booking train tickets and checking the reservation
status of waitlisted tickets. Deccan Airways, one of the new low-cost
carriers, does bookings of Rs 1.5 crore ($330,000) daily over the
Internet.

Matrimonials and Jobs: The way people find lifemates and new employers
is changing. Sites like Shaadi.com and BharatMatrimony.com offer to
connect prospective brides and grooms. Job portals like
MonsterIndia.com (which also owns JobsAhead) and Naukri.com have
increased liquidity and fluidity for people seeking new career
opportunities.

Retailing: India is witnessing an unprecedented retail revolution as
malls and chains proliferate. Investments in IT are helping them not
only manage their supply-chain effectively but also build and maintain
customer relationships. The malls and multiplexes are becoming new
hangout places. With the boom in outsourced services, a growing
youthful population has more to spend. Easier access to credit is also
fueling an appliances and automobiles boom.

The Rs 500-a-month PC: Recently, HCL launched a computer on
installment payments – Rs 500 per month. This is a good start, even as
computing by itself faces challenges of affordability, desirability,
accessibility and manageability. The computing industry is not
learning two important lessons from the telecom industry – that of
zero-management user devices and subscription plans (as opposed to
installments).

Rural India: For a variety of reasons, rural India still remains
frozen in time. As governments start believing that free electricity
to farmers can be a passport for electoral success, investments in
other areas are likely to get compromised. There are a few signs of
hope – ITC's eChoupals and n-Logue's kiosks are providing a platform
for trade and services. But rural India still has a long way to go.

India is arriving as a market for global companies. Virgin is
considering investments in telecom and low-cost airlines. Cisco closed
a $100 million deal with VSNL for metro Ethernet. Most luxury brands
are already available or will be. India is a melting pot for many
simultaneous revolutions across multiple industries. As urban incomes
grow, a generation seeks to race ahead. With one of the most youthful
populations in the world, aspirations are on the rise. The next few
years are critical. If we can do things right, we can unlock the
potential of millions. If not…it will be yet another case of so near,
yet so far. The race is not with China, it is against our own
mindsets. Tomorrow's world is happening. Our actions can hasten it or
delay it. Hopefully, this time around, we can cross the chasm. For
that, India needs to build its digital infrastructure right.

As HP's Carly Fiorina wrote in The World in 2005: "Getting there is
going to require the right blend of realism and optimism. We need to
be realistic that none of this is going to be easy. But we also need
to be optimistic, because if we get this right, digital technology
will make more things more possible for more people in more places
than at any time in history. That alone is worth the journey." The
next Google will come out of the opportunities that technology is
creating in the context of the next users. What can we do to build out
tomorrow's world first in India and then across other emerging
markets?

Friday, December 03, 2004

Is Some Software Meant to be Secret?

Straight off of slashdot...

"Tim Bray and Microsoft's Joe Marini are doing a back-and forth on Open Source. Tim serves (open everything), Joe returns (secret-source is good business) and Tim volleys (the closed-source niche is shrinking)."

Any opinions?

Wednesday, December 01, 2004

The Daily WTF

Check it out at http://thedailywtf.com/forums.aspx. RSS feed at http://thedailywtf.com/rss.aspx?ForumID=12&Mode=0

Describes itself as "Curious Perversions in Information Technology". Everyday they post a new coding horror. These (most) are taken from real world code which people have come across. Covers a whole range of languages.

As a sampler, check out today's post...

------------------------------------------------------------------------------------
The .NET developers out there have likely heard that using a StringBuilder is a much better practice than string concatenation. Something about strings being immutable and creating new strings in memory for every concatenation. But, I'm not sure that this (as found by Andrey Shchekin) is what they had in mind ...


public override string getClassVersion() {
return
new StringBuffer().append(
new StringBuffer().append(
new StringBuffer().append(
new StringBuffer().append(
new StringBuffer().append(
new StringBuffer().append(
new StringBuffer().append(
new StringBuffer().append(
new StringBuffer().append("V0.01")
.append(", native: ibfs32.dll(").ToString())
.append(DotNetAdapter.getToken(this.mainVersionBuffer.ToString(), 2)).ToString())
.append(") [type").ToString())
.append(this.portType).ToString())
.append(":").ToString())
.append(DotNetAdapter.getToken(this.typeVersionBuffer.ToString(), 0xff)).ToString())
.append("](").ToString())
.append(DotNetAdapter.getToken(this.typeVersionBuffer.ToString(), 2)).ToString())
.append(")").ToString();
}

Note, that it is J#, StringBuffer and StringBuilder are the same thing.