Tuesday, September 28, 2004

Re: C# ?

The DS module in Cdac is over and I just flunked in the Mgpt. The next module is C and C++ programming and so I should have lots of questions coming up soon.

Sorry if you've told me this before already but what's Mgpt? So are they going to teach you C/C++ in this next module or just use it for your programming?

Just for a change I got a book from the library which I plan to go through very fast just for an overview - C# Progamming (with the public beta) by Wrox. So got another bunch of questions...

I have a super huge grin on me face. You don't know how happy this made me. Change is good :-)

Enums in c# are value types. So firstly are data types stored on the stack? And even class instances can be stored on the stack.. so what's the syntax for that?

In .NET there are two sets of objects... Reference and Value types. Reference types are Classes, Interfaces, Delegates, Arrays. Value types are Structs and Enums. Basically, all objects in the system have System.Object as the root object. But value types, also derive from System.ValueType. So you CANNOT create class instances on the stack. You can only create struct instances on the stack, which implicitly derive from System.ValueType. And btw, all primitive types in C# like int, double etc... are structs in the BCL (Base Class Library).

On enums i wanted to compare them with java enums. In java 5.0, enums were added which are actually classes. So when you say enum {something} you are actually extending a class. So enums in java are pretty advanced. I'll have to read more to give more info. What about c#? You can get more info on Enums from this Oreilly sample chapter

I guess again the motivation for making enums classes was for backward/forward compatibility. I scanned the article link you sent briefly and you're right... java enums have much more ability since they are full blown classes. Personally, I don't see the point of this. Enums play a very specific role in C++ and C#. They are just defining type-safe constants as a group. Why complicate matters by allowing it to do everything a class can do? Why would you want to define methods on an enum? Dyou see a benefit?

Another thing was the huge number of keywords. I read on const and readonly. Are they really required over final?

I dunno the exact number, but I guess C# must have maybe +20 keywords over java.

Regarding const and readonly - they serve two different purposes. const is evaluated at compile time and is implicitly static. So every instance of the class gets only one copy. readonly is evaluated at runtime and are not static. So every instance gets its own copy.

If you make any fields const in your app, when you compile it, the compiler will replace all the fields with the actual value. For ex.

class Math
{
    public const double PI = 3.14;
}

class Circle
{
    private double circumference( double radius )
    {
        return 2 * Math.PI * radius;
    }
}

Here, it will turn into 2 * 3.14 * radius. The compiler can make this optimization. You can't do it for readonly fields since they are evaluated at runtime.

But readonly fields have a different benefit. What if you shipped this code and then later on realized that PI is wrong or you want to make it more accurate. If you had made it a readonly field, you can just make the change and ship the updated Math class. Your Circle class's Circumference method will automatically use the new updated PI value without re-compiling. Since PI is evaluated at runtime it will automatically use the updated value. But since it's const here, you will have to recompile.

Does final do both?

The main question that propmted this blog was inheritance.virtual override new sealed and abstract... wow so many keywords and complex relationshipsDo you make use of all these keywords?? Isn't the Java style much more simple? Trying to appease c++ programmers, but added awhole extra bunch of words!!

Again, all those keywords serve a purpose just as const vs readonly. They didn't just get keyword happy. I had written a blog regarding polymorphism in C++, Java and C# long back - http://codeword.blogspot.com/2003/12/polymorphism-c-vs-java-vs-c.html. It talks about virtual, override and new. So check it out and see if you think they serve some meaningful purpose.

Java uses one keyword which can be used on classes, methods and fields. They have the same essential meaning for all - preventing things from being changed. C# has taken a different route. They make all methods non-changeable by default and then make you explicitly say if you want to change something. They requires more keywords.

On boxing and unboxing, why the need for a different object class from the default Object class? In Java the wrapper classes for primitives like Integer for int can be cast to Object. Wrt Java 5.0 I think the compiler will be generating casting code which was generally written by hand.

One thing you should understand is that all the types are defined in the .NET BCL. The language itself does NOT define any types. The languages only provide an alias for primitive, string and object types. So in C#, int == System.Int32, long == System.Int64, double == System.Double, string == System.String, object == System.Object etc... Same way VB and Managed C++ provide something similar. So there is no different object class from the default Object class.

So hope that cleared some stuff up. What are your impressions of .NET from the book. I've been blogging a lot about this stuff so you should be familiar with some of it already - atleast I hope.

Btw, check this link out - C# from a Java Developers Perspective. It's a bit old but quite comprehensive and an easy read. He'll have to update it for Tiger. And before you expect some .NET bashing... he's a Microsoft employee.

Re: A9 ??

If I would get a good net connection I think I would. It has a better UI with more features.

The site looks good. They are providing a more "dynamic" user interface and some potentially useful additional features like keeping a history and bookmarking your searches. No doubt about this.

The point I was trying to make is, it is not a huge leap from what google is offering. Essentially, when I search, I want results - that's it. I don't even go to google's website anymore... just use it from the toolbar on Opera, Firefox and IE. So the UI that a9 is offering makes no difference to me since they are just returning google results. If it was using a different technology entirely, then yeah, maybe I'd use it to see how it compares to google (which has set the standard for everybody).

What's your opinion? Dyou agree on the point about functionality?

Do you use rich-UI sites? I know you don't like sites with flash overkill but does this qualify as the same?

Yup, generally I don't like Flash sites. The keyword is "generally". My experience has been that they go totally overboard and are too flashy (pun intended). But that's not to say I don't like rich-UI sites. The best example is GMail. It qualifies as a rich-UI site. And it's superbly designed... extremely simple, but functional and useable.

I know you have an opposite view regarding flash sites.

C# ?

The DS module in Cdac is over and I just flunked in the Mgpt. The next module is C and C++ programming and so I should have lots of questions coming up soon.

Just for a change I got a book from the library which I plan to go through very fast just for an overview - C# Progamming (with the public beta) by Wrox. So got another bunch of questions...

Enums in c# are value types. So firstly are data types stored on the stack? And even class instances can be stored on the stack.. so what's the syntax for that? On enums i wanted to compare them with java enums. In java 5.0, enums were added which are actually classes. So when you say enum {something} you are actually extending a class. So enums in java are pretty advanced. I'll have to read more to give more info. What about c#? You can get more info on Enums from this Oreilly sample chapter

Another thing was the huge number of keywords. I read on const and readonly. Are they really required over final?

The main question that propmted this blog was inheritance.virtual override new sealed and abstract... wow so many keywords and complex relationshipsDo you make use of all these keywords?? Isn't the Java style much more simple? Trying to appease c++ programmers, but added awhole extra bunch of words!!

On boxing and unboxing, why the need for a different object class from the default Object class? In Java the wrapper classes for primitives like Integer for int can be cast to Object. Wrt Java 5.0 I think the compiler will be generating casting code which was generally written by hand.

Re: A9 ??

Haven't used it much, but don't see it as being anything great. One major thing is the site info and history. Other than that, a bit advanced user interface.

This is my view. How dyou find it? Would you use it over google?


If I would get a good net connection I think I would. It has a better UI with more features. Do you use rich-UI sites? I know you don't like sites with flash overkill but does this qualify as the same?

Saturday, September 25, 2004

Re: Generics and different interpretations of backwards compatibility

When backward compatibility is mentioned about Java releases, it means that the bytecode is similar to old releases. So new compilers will not generate bytecode which is new. Just the conversion of code like generics to bytecode will be done by the compiler. Other features also need the compiler to generate code. So the VM as such does not need to recognise any new keywords. So the JVM's do not need to change the core.

So what you're saying is that the bytecode that was designed back when Java first came out is set and won't be changed for stuff like generics? And the class file that is generated won't have anything that can't be recognized by previous VMs?

In .NET on the other hand newer bytecode keywords might have been added. So running that code will require different changes in the VM.

This is what I understand. I guess there will have to be changes to the IL and assembly metadata when compiling new features like generics. So you can't load it on previous CLR versions.

Which do you think is better??

I've always understood "backwards compatibility" to mean "be able to run older code on newer platforms without making any changes". This gives you the freedom to make any improvements you want to new stuff as long as older stuff works. And this is what .NET is doing.

Somehow Java is trying to do both things... backwards and forwards. Run old code on newer JVM without problem, and also run newer code on older JVM. But this second part has a catch - you can only use the old APIs. If you want to use new features like API improvements and generics, you will need the newer VM and APIs. I don't see the point. One argument is, there will be a larger installed base, but I mean, you can't use new features so just work with previous APIs and VM.

I'm still confused about something... can you clarify. Is VM and Java API completely separate? So can you use VM 1.5 with API 1.4? I believe this can be done with .NET. If you have the newest version of the CLR, you can use all previous API versions. They plan to have only one CLR in Longhorn.

Re: SUN in the news again!!

Somehow I always get the feeling Sun has a bit of an identity crisis. For ex. with IBM, you know they've put their full force behind Open Source. But with Sun, they support it, don't support it, now Open Sourcing Solaris, attacking Linux. It's hard to see where they will go.

I guess pretty much all closed sourced companies are under pressure now to open their source code to the world because of Linux. Microsoft already opened up Windows to major governments and recently did the same for Office. Sun felt the heat too and so decided to open source Solaris. Dyou see a great benefit from doing this? I guess they are mostly doing this to appease people than get anything out of it. I doubt there will be much community involvment in it as it will always be seen as controlled by Sun. Somehow it seems like a fad right now - Open Source everything... whether it will be of any use or not.

Sun has already open-sourced a lot of stuff and are very open with Java. Personally I do not think that Java should be open-sourced. They have to get the community on their side. Thats a very hard task.

I agree with you. It's a bad idea to open source Java. What they keep saying is Open Standards rather than Open source and that seems a good way to go. Actually, all the source for the Java API's are available. And Java is already quite open in that a lot of companies are involved in improving it.

Re: Generics and different interpretations of backwards compatibility

I'm actually a bit confused about this. If your new Java 1.5 code can run on previous VM's then you will only be able to use the Java API from previous versions right? You can't use any new functionality added to the library. So you will need to get the new API's anyway?

I am not sure if my explanation is totally correct.

What Mohn said about needing the Java 5.0 VM to run 5.0 API enhancements is correct. When backward compatibility is mentioned about Java releases, it means that the bytecode is similar to old releases. So new compilers will not generate bytecode which is new. Just the conversion of code like generics to bytecode will be done by the compiler. Other features also need the compiler to generate code. So the VM as such does not need to recognise any new keywords. So the JVM's do not need to change the core. Just add the newer libraries (rt.jar). Only one keyword enum has been added in 5.0. Enums are also classes in Java.

In .NET on the other hand newer bytecode keywords might have been added. So running that code will require different changes in the VM.

Which do you think is better??

(I think I made this blog a bit confusing)

SUN in the news again!!

Well Sun is in the news again as they might open source Solaris and are also changing their strategy by attacking Red Hat.

So got a few interesting links..

Sun's plans...and how they could go wrong

Reflections on OS addiction

I really suggest reading some follow-up blogs from the second link. Really cool.

Sun has already open-sourced a lot of stuff and are very open with Java. Personally I do not think that Java should be open-sourced. They have to get the community on their side. Thats a very hard task.

Is this bad or good for Linux/SUN/MS..?

Friday, September 24, 2004

Generics and different interpretations of backwards compatibility

From Bruce Eckel's blog - http://mindview.net/WebLog/log-0058

Going back to his disappointment at Java generics and erasure. Erasure erases the type info at runtime, so casting is done under the hood w/o programmer's knowledge. .NET retains type info as metadata and is accessible at runtime.

Interesting to see what he writes about backward compatibility. Whereas Java wants to be able to write code using Java 1.5 and be able to run it on previous VM's, .NET wants to be able to run previously developed code in the new CLR w/o recompilation. You can't run newly developed .NET code (v2) on previous versions of CLR.

I'm actually a bit confused about this. If your new Java 1.5 code can run on previous VM's then you will only be able to use the Java API from previous versions right? You can't use any new functionality added to the library. So you will need to get the new API's anyway?

Tuesday, September 21, 2004

Re: A9 ??

Haven't used it much, but don't see it as being anything great. One major thing is the site info and history. Other than that, a bit advanced user interface. I'd still use google. I mean they are essentially just doing a google search and presenting it in a different way. I don't think this is meant as a competitor. I guess, amazon just wanted to get into the search game and maybe make some money with sponsored links?

This is my view. How dyou find it? Would you use it over google?

gbrowser

There's been some roumors about google working on a browser. Apparently they've even registered gbrowser.com.

I've read on some blogs about google planning on an instant messenger and also a grand plan of a super OS. This is all speculation... nothing official, but it seems they are dipping their bud in a lot of areas.

Google is an exciting young company with a lot of bright ideas. They've been hiring the greatest brains from companies like Microsoft and Sun. Also doing some radical new stuff. Just as an example, on my bus ride to the Uni, there is a huge billboard for a google ad. The ad doesn't say that it's from google. Instead, it asks to solve a problem, which gives you a URL to a website, which asks another problem. If you get through it, they ask you to send your resume. Just some simple stuff like that which I don't think has ever been done before.

Having said all this great stuff about them, I'm a bit skeptical about the google browser, if it is true. I don't see what they could possibly come out with that will be a radical departure from Opera or Firefox, who are setting the standards for browser innovation. Sure, google has great services - search, mail, groups, but I don't see the rational in coming out with a browser just to "connect" all those properties, as some people have been speculating. Do you? And if they do come out with one, what dyou think the reaction of the open source community will be? They are behind Firefox/Mozilla full force.

Monday, September 20, 2004

Re: Longhorn Features?

Firstly thanks for all the amazing info you provided.

Last year at their Professional Developer's Conference (PDC), Microsoft announced that Longhorn would include three technology pillars - "Avalon", "Indigo" and "WinFS".

For sometime they had been talking about releasing the "Indigo" set of API's as an add-on to the .NET framework.

There are pro's and con's to this...

blah blah ( :) )

What do you feel about the announcement? You think it's a major advantage for the Linux dudes?


I see the entire Longhorn issue in a different way. Its more of Win vs Win. What I mean to say is that considering all the MAJOR changes in the OS, will the industry accept. I rather think they'll take a wait and watch approach. Especially on the server-side. Btw is Longhorn going to be for the desktop or server? So adoption of a very new technology will be slightly slow. How fast did industry accept the Win NT platform? Is .NET being readily accepted? as a stable platform? I am asking questions here and not being cynical. Thats a reason why I believe an incremental update to the OS is a much better approach.

Will Linux gain in what I feel might be a sluggish initial period? I am not sure. Linux vs Windows will continue to be decided on different factors. Servers do not need the Longhorn features. Same for most co's running word processing apps. So who knows.

The same argument applies to the new Java 5.0 version. There are many new features so when will the industry adopt? We as dev's get excited with new tech. What is the status of Web Services? How many co's use them? (Again a question). I do not think Web Services have been adopted widely enough.

Whats Yukon and the other future stuff?? I read some article somwhere which basically confused all the relationship between the file-system, the database etc!! Whats supposed to do what? And like Mohn (assuming Mohn and I are not the only ones reading codeword anymore!!) mentioned the base FS is something else. So any idea about all the layers?

Other points Mohn raised was the size of the .NET framework and version problems.

The Java runtime Environment is 10Mb+ and the SDK is 30Mb+. Both platforms are mini-OS'es in a way. After Longhorn, .NET might become super huge!! Un-Downloadable !! Java also has so many extensions now (javax) which are pretty huge in size. So thats going to be a bigger problem for Java as MS will bundle .NET in the OS.

On incompatibility between versions there are differences again. In Java, all versions are backward compatible. Even though a section maybe deprecated (say 1.1), even the never versions have to support it. In other words what is marked as deprecated is never removed. This was one promise by SUN to their customers, that Java will always be backward compatible. This is not what the dev's like too much. Obviously this bloats the API and its not "clean" anymore. Having said hat the .NET scene seems more worse? What versioning system is followed in .NET? Any minor/major system? I always get the feeling that .NET is in a sort of a test phase. Maybe after Longhorn, the API will be fixed to atleast some scheme.

A9 ??

A9 from Amazon is a new search engine.

They have a pretty neat interface and cool options. Similar to the gmail site in a way. Are these the next generation of web-sites? They seem like semi - Rich Internet Applications. (D'yu know what I mean!). You guys seen any similar stuff? With higher bandwidth becoming more common, RIA and better UI's seem to be the way to go. Just like 3-D desktops. Or will they just be more eye-candy??

Also in the A9 FAQ, it is mentioned that they internally use the google service for searching web pages. So how does A9 become a competitor to google? And wouldn't A9 have had to make an agreement with google to use them as a backend(sort of)!!.

P.s: The coolest thing i noticed so far is the site-info after performing a search. And EconomicTimes,IndiaTimes comes in a whopping 12+ seconds. Try finding something slower!!

Tuesday, September 14, 2004

Quake II .net

mms://wm.microsoft.com/ms/msnse/0408/23360/Scott_currie/Quake_Demo_56K_110K_300K.wmv

Video is a MS dev showing Quake II running under .NET

This is a pretty old story... I think summer of last year (told Rahul about this when I was in India). The guys who made Quake, ported their C code to C++ and then compiled it under the .NET CLR. They then added new functionality using managed code. The entire process is quite nicely detailed in this whitepaper, incase you're interested.

They were able to take legacy code and just compile it under .NET without making significant changes. OK, they had to first get it to C++. But after that it was just a recompile. The C++.NET compiler takes your native code and generates MSIL. This means that your app is a ".NET friendly" citizen. You can now come in and create new features using C# or VB.NET or whatever, getting all the benefits of managed code and using the .NET framework, and easily integrate it into this legacy app. Understand that the old code is NOT being GC'd. It still needs manual memory management. But it's able to play nice with managed components with little effort.

I still don't understand the exact process of what happens under the hood, but I think it's pretty damn amazing.

Monday, September 13, 2004

Re: Longhorn Features?

What do you think will be the implications of this. Ms guys are happy that there is a release date and non Ms guys are happy as they take it as a Ms defeat. Also is the Win API going to be completely ported to .NET in Longhorn?

Last year at their Professional Developer's Conference (PDC), Microsoft announced that Longhorn would include three technology "pillars" - a new presentation system, "Avalon", a new communications framework (I think it has to do with making web services super easy), "Indigo" and a new file system, "WinFS". And all these would be made accessible through a superset of the .NET framework, "WinFX". Essentially WinFX would replace the current Win32 API and further improve the current .NET framework to include (more or less) the entire Windows API as managed code.

This seemed quite ambitious. It would be the most complex OS ever created. I think they went a bit overboard with their goals, but it's fine - you need to aim high. But the problem for them was that they couldn't give an exact release date. People kept speculating 2006, then 2007 and some even said 2008! If you take the best case of 06, that would still be 5 years since the release of XP... worst case would be 7 years. They would be pulling the trigger on themselves if such a scenario ever came. That's just an insane amount of time between OS releases.

For sometime they had been talking about releasing the "Indigo" set of API's as an add-on to the .NET framework, which would work on previous OS's like Server 03 and XP. Now they have said that even some part of the presentation system, "Avalon", will be made available for downlevel OS's. They didn't give a specific date for all this to be available, but I guess the general timeline will be 06. They also said WinFS won't be released with Longhorn (which is also to be released around 06-07), but will be available as an add-on later on.

There are pro's and con's to this...

One pro is that there are millions of XP systems out there. Having these new capabilities on this installed base will be beneficial to developers. I'm assuming they will release an interim .NET version which will include these technologies and that can be easily deployed/downloaded just as today's Java or .NET frameworks. In this sense, I don't see any benefit to non-MS guys. If anything, it hurts them, since they were hoping that they would get a fresh start when Longhorn comes out - Longhorn install base will start with 0. Now that won't exactly be the case.

The one main con I see (I'm sure there are many others) is that there won't be a common base platform. Devs will need to keep checking to see if this version of Windows has Indigo or Avalon, what version they are running. If they don't have it, to download it or distribute it with their own apps. This is the same problem with .NET today. Not everyone has the framework today. And version 1.1 is 23 mb. Adding Indigo and Avalon will drastically increase that size.

Many people are also saying that if these are going to be available in XP, why would one upgrade to Longhorn when it comes out. They have a point. But I feel that Longhorn capabilities will be superior to what will be released for XP. They talked about three tiers for the presentation systems... based on graphical capabilities. I guess for Longhorn they can just default to the most advanced as it will be released with new machines, which at that time will include the latest graphics cards.

Finally, a lot of them are saying since WinFS won't be released with Longhorn that all the new search capabilities won't be available in Longhorn. I think that WinFS itself is not the file system. It's something that sits on top of the file system (like NTFS) and enables relational database like capabilities which interacts with the underlying file system. I feel they will improve the underlying file system itself for Longhorn which will enable better searching. WinFS will come later to better interact with it.

Having said that, I think it's a bad idea for MS to release Longhorn without WinFS. This is one of the main things people have been waiting for. And it's not going to be released for previous OS's. This is what will differentiate the Longhorn release. MS has been talking about this "unified file system" for a long time and it's dumb for them to delay it further. It should be in Longhorn even if it pushes back the release date.

What do you feel about the announcement? You think it's a major advantage for the Linux dudes?

Saturday, September 11, 2004

Longhorn Features?

Recently Microsoft announced that Longhorn will have a reduced set of features. The highly publicized WinFs feature will be scraped for the early version.

What do you think will be the implications of this. Ms guys are happy that there is a release date and non Ms guys are happy as they take it as a Ms defeat. Also is the Win API going to be completely ported to .NET in Longhorn?

P.s: I am fully aware that I am too small an entity to comment on such a huge topic, but hey that's why we have blogspot!!

Friday, September 03, 2004

Re: Java's pass "by reference" demystified

An interesting thing to note is that in Java there is no way to create a "swap" method for primitives. A swap method is where you send in two arguments and have their values interchanged. Now, there are wrapper objects for all primitives - like Integer, Doublt etc... It's possible with that. With plain primitives, it's impossible.

Of course, I got to throw in how C# differs. There is a "ref" keyword which does pass by (true) reference as in C++. So you can infact create a swap in C#...

private void swap( ref int x, ref int y )
{
    int temp = x;
    x = y;
    y = temp;
}

Btw, I'm also doing a course on OOP using Java. We got some introductory material on Java fundamentals.

http://www.cs.utexas.edu/users/rockhold/cs371p/handouts/Java-1.pdf
http://www.cs.utexas.edu/users/rockhold/cs371p/handouts/Java-2.pdf
http://www.cs.utexas.edu/users/rockhold/cs371p/handouts/Java-3.pdf

Java's pass "by reference" demystified (by Rahul)

So finally posting a blog after ages. The course in NCST has been great and I have learnt a lot. Clearing my fundamentals. Or really learning programming for the first time to put it correctly. The first module has been in Java programming and I read a few parts of "The Java Programming Language" by Ken Arnold and James Gosling.

Got an intersting part on passing parameters via methods. Personally I always thought that primitives were passed by value and instances by reference. But the second part is wrong. I'll simply write an excerpt from the book in full knowledge of the copyright violation!!

"..
You should note that when the parameter is an object reference, the object reference - not the object reference - not the object itself - is what is passed "by value". Thus, you can change which object a parameter refers to inside the method without affecting the reference that was passed. But if you change any fields of the object or invoke methods that change the object's state, the object is changed for every part of the program that holds a reference to it. Here is an example to show this distinction:

class PassRef {
public static void main(String[] args){
Body sirius = new Body("Sirius",null);

System.out.println("before:" + sirius);
commonName(sirius);
System.out.println("after: " + sirius);
}

public static void commonName(Body bodyRef){
bodyRef.name = "Dog Star";
bodyRef = null;
}
}

This program produces the following output:

before: 0 (Sirius)
after: 0 (Dog Star)

Notice that the contents of the object have been modified with a name change, while the reference bodyRef still refers to the Body object even though the method commonName changed the value of its bodyRef parameter to null.
.."

"..
Some people will say incorrectly that objects in Java are "pass by refernce". The term pass by reference properly means that when an argument is passed to a function, the invoked function gets a refernce to the original value, not a copy of its value. If the function modifies its parameter, the value in the calling code will be changed because the argument and parameter use the same slot in memory. If Java had pass-by-reference parameters, there would be a way to declare halveIt so that the preceding code would modify the value of one, or so that commonName could change the variable sirius to null. This is not possible. Java does not pass objects by reference; it passes object refernces by value. Because two copies of the same reference refer to the same actual object, changes made through one reference are visible through the other. There is exactly one parameter passing mode in Java - pass by value - and that keeps things simple.
.."

Did you guys know this?? Any more tips/hacks?