Saturday, April 09, 2005

Re: More on Mono


One of the questions in the interview was about the development process behind Mono. He gives a really good answer about not being a great fan of UML and strict development processes. They are all great hackers and just want to do it because they are having fun... enjoying it. Strict dev practices etc... limit creativity and the "art" of programming.

What dyou think of his answer? I want to learn good practices about developing software because right now we all lack any substantial experience with it. But at the same time, I read about UML, design patterns, agile development, "some new hyped up buzzword" etc... and it all just seems so "messy" or tends to complicate matters. Same feeling I have with some Java developments. I've mentioned them before. It feels a lot of over engineering.


UML is a diagrammic notation to express Software design at various stages of development. You should learn UML because it is the de-facto method for communication between dev's. So if I show you a UML Class diagram you immediately know what inherits what and methods etc.. blah blah. As I mentioned various stages of developement exist for a particular piece of software. In the initial stage a Use Case diagram is made, then Analysis diagrams, then Design diags. All these help in development.

Now there are many methodologies for developing software. The various stages I mentioned were wrt the Waterfall process (or the Unified Dev Process), which I must admit is very boring. Too much documentation and managerial in nature. But understandably in a large organisation these things become important. Other methodologies include the Agile process. Agile process includes XP development practices which seem more Developer friendly. Many methodologies or processes use UML diagrams to express artifacts (or products) at various stages of development.

So firstly you should learn UML diagrams. Reading about various Development processes is also good. You will get an idea as to how many co's work. Dinesh could probably tell us a bit about his company. Which process you apply is a different matter.

And Design Patterns is a separate issue altogether. Which book for patterns or articles have you read?? Design Patterns was the first book to talk about patterns and is simply put a Bible. I have had the book since a while and even suggested to you guys to read the book. But to be frank I have not been able to understand too many patterns. We did try to apply a few in the Object Oriented Analysis and Design Module here at Ncb. Recently I read a sample from this book from Oreilly Head First Design Patterns. Read the sample chapter. The style of the book is very different, and I really loved it. Only after you read a few design patterns do you realise how beautiful solutions to generic problems can be !!

And complications in Java is another issue. I'll talk about Java some other time. I think you have mixed too many questions in one paragraph. Read about stuff to get an idea of things. UML and Design Pattens should be high on the priority list.


Also, any opinions about Mono? From his blog sometime back - "7 out of the 20 top-rated apps on gnomefiles.org are mono apps".


Even since coming here to Ncb I have harldy booted into Gentoo, and am not aware of whats going on in the Linux world. Probably Hrishi could shed more light on the popularity of Mono apps. Personally I am very skeptical of Mono being used widely.

Friday, April 08, 2005

More on Mono

Kinda obvious, but one of the great things about the programming world is that you interact, learn from, help and work with people from all over the world. Here's a video from Turkey interviewing Miguel De Icaza - the Mono dude (also GNOME founder). Can't understand half the things the interviewers are saying. I thought they were talking Turkish... turns out it was English.

Anyway, I really got a lot of respsect for Miguel. His blog gives you a good insight into his views - and not just programming related. He's like a really experienced open source hacker. Just feel like if you worked under him you would learn a lot. One of the questions in the interview was about the development process behind Mono. He gives a really good answer about not being a great fan of UML and strict development processes. They are all great hackers and just want to do it because they are having fun... enjoying it. Strict dev practices etc... limit creativity and the "art" of programming.

What dyou think of his answer? I want to learn good practices about developing software because right now we all lack any substantial experience with it. But at the same time, I read about UML, design patterns, agile development, "some new hyped up buzzword" etc... and it all just seems so "messy" or tends to complicate matters. Same feeling I have with some Java developments. I've mentioned them before. It feels a lot of over engineering. Granted this is coming from someone with little experience, but haven't you read an article which goes on about something and at the end of the 20th page you think, what the hell was that? Just seems so complicated for something which could have been done more simply.

Also, any opinions about Mono? From his blog sometime back - "7 out of the 20 top-rated apps on gnomefiles.org are mono apps". I was quite surprised/impressed. It looks like it's use has picked up.

Sunday, April 03, 2005

Google: Behind the scenes

Streaming vid (~1 hr): Behind the scenes at Google

One (more) thing which is impressive is they've built their services on top of commodity hardware... no super expensive machines. Just regular stuff with a lot of redundancy. Also, they have a ton of in built stuff - from a Google File System to some map/reduce algorithm which is infrastructure code to be fault tolerant and distribute the load among different machines (mentioned in the talk). They've recently started to share some of this.

Re: Databases Part 1

Waiting on part deux.

You'll have to wait for some more time... Very busy with the current module at Ncb as reaching the submission deadline.


A table can have a primary key.

When you say "can" dyou mean a primary key is NOT necessary? I thought it would be.


Right. A primary key is NOT necessary. But searching for a particular row will be more complicated as duplicates can be added to the table.


One thing that needs to be considered is where the error checking happen? Does it happen in the "business logic" layer or directly in the data layer? I would think a lot of times the database should ONLY be conserned with storing information.

I guess the question comes down to what responsibilities the database should take on. It seems the trend is to make more and more things happen in the data layer.


Basically databases are becoming more intelligent. So more Business logic is being pushed into the databases. It seems like mixing of responsibilities, but only specific business logic could be put into the db. Like you need to retrieve some data occasionally which spans across many tables and this is done very often. Rather than have loads of SQL in your business logic, just call a stored proc.

Another trend is distributed databases, which still have to mature well.

Error handling is possible in Stored procs. But I am not very sure how errors are sent to the host language. I think a simple SQLError could be returned by the db. We returned C-style status codes from the Stored procs.


Each trigger is associated with a TABLE on some event.

This is quite cool. I didn't know this was possible. You can basically keep a log/trace of everything that's going on in your database this way.


Care has to be taken that triggers are not written on 'events' of heavily used tables. Events could be insert, delete. Now if I have 500 inserts per sec on a table and I write a trigger on that event, its going to really load the server.


I'm interested in Stored Procedures just because I've read that they are beneficial to app performance. Is that really true?


Yes its true.

Now for some explanation.

When a simple query is submitted to a database, a few steps are carried out after which the result is returned. These include checking if the query is valid and tries to reference valid tables and columns. Then optimization of the query is done. Most queries in SQL are commutative and associative, so the order of the operations in the query can be changed without changing the meaning of the query as a whole. So the db does this based on the information it has about its tables and some heuristics as well. After this, the new SQL query tree is compiled and finally executed to return a result. Now as you have noticed, this is a very complicated and lengthy process. (and trust me, db's are really smart already wrt optimization!!)

Back to Java. There are three ways to execute a query in Java SQL - A Statement, a PreparedStatement and a Callable statement.

Now in a simple statement, the query is sent from the host language, then goes through all the steps of checking and optimization mentioned above.

A prepared statement is cached into the db for some time. So it does not have to go through all the optimizations steps each time. Probably only the new arguments have to be checked which should be faster.

A Callable statement is used to run a Stored Procedure. Now a stored procedure query resides IN the db. Only arguments are passed similar to a Prepared statement. So all optimization, compilation is already done.

I guess that should explain performance effects of various methods.

Also Stored procedures have other advantages like Mohn mentioned in his Hacking Websites blog.

< Excerpt Begin >
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
< Excerpt End >


What db are you working with? I've had basic experience with Access and SQL Server.


I used to work on Access before leaning what a 'real' db is supposed to do. We worked on SQL Server here at Ncb. Access does not do most of the things I blogged about. Just has tables with Primary and Foreign keys. Probably something more!!

I guess this blog introduced Stored procedures well enough. An example later..

Sunday, March 27, 2005

Dynamic Languages

Over at DevSource they have a piece on The State of the Scripting Universe. Boy, this scripting engine really is going full throtle. Everyone and his dad seems to have seen the light and gone over to scripting land. Somehow I'm still sitting in "static" darkness. We have discussed this a bit before. I guess it's the fact that I've only had very limited exposure to it... not having developed something "significant". Once you have that kind of experience under your belt it's better to compare it with C#/Java/C++.

I believe scripting in quite big in game development. A friend of mine works at a gaming company and all he does is scripting (some custom developed one) and he's in the design department! From what I understand, all games start out with the engine and you just customize that. The engine is sort of like the platform? And the scripting languages use that as an API? Maybe Dinesh can shed some light.

While on topic, Bruce Eckel had a post last month about productivity between static/dynamic languages. Productivity is one of the apparent key advantages of dynamic languages. In it he links to some dude who writes about Tests vs Type. Read his post to understand what that means.

Personally, I think the "Edit Types" block under "Explicit Typing" is way too big. To me it seems like spending time "editing types" is a way of testing. You bypass this step in "implicit typing". So I think the "editing types" part should come under tests. What dyou think?

Btw, searching for anything on the blog really sucks. I had to find the previous post link manually. Google isn't spidering/indexing the posts properly.

Saturday, March 26, 2005

Don't throw from finally

I found this very interesting. It's a .NET piece, but these things tend to cross over one-to-one into Java fairly often. This is a CLR feature, so dunno in this case if the JVM behavs the same way.

Btw, both in C++ and C# you have the option of setting an event handler for an unexpected exception.

In C++,
set_unexpected( my_event_handler );

In C#,
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( MyEventHandler );

Is there something similar in Java?

JSP/Servlets compared to ASP.NET

I read up a little on JSP/Servlets + Rahul's post. They seem more similar to ASP.NET than plain ASP.

ASP was quite a mess really, because everything was on one page. You had a lot of "spagetti" code, no separtion of UI from code and it was interpreted, not compiled. It was recommended practice to create code, package it into COM components and then use these components from your ASP page. COM code was compiled so you got some performance inprovements. But it was a hassle and not very popular. The whole COM technology was messy - not dynamic with needing to reboot machines, registering/unregistering components etc...

Compared to Servlets, ASP tech was a joke. ASP.NET completely changed this, brought it on par and even surpassed it. With ASP.NET you get complete separation of UI and code. Basically, you get the MVC pattern for free (no need for external frameworks like Struts). You can integrate code within the same page as UI if you want, but it was kept for compatibility with ASP. To be able to "upgrade" old ASP pages to .NET. It is not recommended. VS.NET only supports "CodeBehind" wherein you have one page with UI and another code behind that page that is your logic. When you access an ASP.NET page it automatically combines these two pages into one "Page" class... similar to when you access a JSP page, it gets compiled into a Servlet.

I see that there is something new coming up called Java Server Faces. This is in direct reaction to ASP.NET server controls. Again their main motivation is to clearly separate code from presentation. Think about when you want to spit out a table with info from a database. You have to connect to the database, get a recordset, start a table, create a row, add first row of data, repeat, end table and then send it to the browser. Your presentation (the table) is intertwined with your code (connect to database, loop through records etc...). Server Controls in ASP.NET changed this. You just drop a DataGrid control in your page. In your "CodeBehind" page, connect to the database and bring back a DataSet. Then just bind this DataSet to the DataGrid. The DataGrid control will take care of outputting the table. Basically, you just pass it a collection of data and it takes care of handling the presentation. You can later set properties on it to change appearance etc... Everything about the DataGrid can be programatically accessed on the server side including a whole bunch of events. This is the essence of OOP. JSF seems to be doing something similar.

What I notice on the Java side is a plethora of different intimidating acronyms. JSP, Servlets, [Enterprise] Java Beans, Struts, Web Containers, Application Servers and now JSF. Obviously, Microsoft is known for integrating everything and Java is more community related with diff frameworks being "plugged" in (which is good in a way). I posted about this difference sometime back. But regardless, it seems like maybe the Java side tends to complicate matters a bit much? Maybe you don't need to use all these all the time? Maybe it's just for the super high end stuff - enterprise level? What dyou think?

Wednesday, March 16, 2005

GoogleX

Something for the OS X fans - GoogleX

Re: Eclipse Tutorials

Is Netbeans free? Or is there a free (community/personal) version? What about IntelliJ - It regularly gets voted top Java IDE.

Netbeans is free with source available. Netbeans is sponsored by Sun and is available under the Sun Public License a variant of the Mozilla Public License. Eclipse is available under the Commons Public License but according to their site, its going to be converted to the Eclipse Public License.

IntelliJ is not free either in source or usage. They do have a trial version!! IntelliJ actually uses a lot of open source libs. I haven't really used it to comment on its features.


Eclipse has been built up, not only as a (superb) IDE, but also as a platform for plug-ins.

Same is true for Netbeans. Both IDE's also have a platform concept over which the IDE is built. So I can create applications over their Platforms which contain generic libraries which are used within the IDE's. This can ease lots of stuff. Netbeans also has good Plug-In capabilities. But I do not know which IDE has a better platform and plug-in design.


What's impressed me most about Eclipse is that it is written entirely in Java. I haven't had any unreasonable performance problems at all. I've used it both on Windows and Linux and the experience is absolutely seamless.

Eclipse is not as pure Java as Netbeans. This may sound a bit funny at first. In Eclipse, the Standard Widget Toolkit is used for GUI. Now SWT is not standard Java. It is possible to embed C code within Java code. So what the Eclipse group did is created a new GUI framework called SWT in which direct calls are made to the underlying OS. This bypasses the JVM. This apparently has performance benefits. But now the user needs to install the SWT libraries which contain OS dependent library files like dll's. Netbeans on the other hand uses Swing. And to run swing, just the JVM is needed. This article should make things clearer.

Also both Ant and Junit are also seamlessly integreated into the Netbeans IDE.

Personally I am not sure why Eclipse seems more popular compared to Netbeans.

Servlets and JSP : An Introduction

I am going to give a short introduction to Servlets and Java Server Pages(JSP) which are used to create dynamic web pages using Java technology and are part of J2EE.

Both Servlets and JSP have to be run within a web-container. The web-server will start on a particular port on which pages are served. I recommend using Jakarta Tomcat as your web-server. Web-Containers are also embedded within application servers. Installation of Tomcat is very easy.

Both Servlets and JSP are basically simple Java class files. This is a simple servlet -

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorldServlet extends HttpServlet {

public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

res.setContentType("text/html");
ServletOutputStream out = res.getOutputStream();
out.println(" < html >");
out.println(" < head > < title > Hello World < /title
> < / head >");
out.println(" < body >");
out.println(" < h1 > Hello World < /h1 > ");
out.println("Server time is " + System.currentTimeMillis());
out.println(" < /body > < /html > ");
}

public String getServletInfo() {
return "Create a page that says Hello World";
}
}

The code should be mostly self explanatory.

The HttpServlet contains two important methods, doGet and doPost. doGet is used to handle HTTP GET requests and doPost is used to handle HTTP POST requests. The path to invoke this Servlet will depend on the web-server used and settings made. When the url for this Servlet is requested, the doGet method is invoked.

Within the doGet method, the HttpRequest and HttpResponse are passed as params. So both can be checked. An output stream to the HttpResponse instance is opened and any html to be displayed to the user, is simply thrown to the output stream. As simple as that.

The second method getServletInfo is analogous to toString and will never be used that much.

As you'll notice the HelloWorldServlet is a simple java class file. So you can easily make your web-page dynamic. Like in this example, I simply print the Server time. If/Else loops can be added, Database connections opened, anything you can do within a normal class can be done here too. But this obviously leads to a mess, with UI, logic and everything else getting mixed up.

Basically the first time the url is requested, the Servlet class file is compiled. The next request onwards, the compiled class file is simply executed.

Also Servlets are a bit cumbersome to code. So JSP was introduced. This is a sample JSP page -

< html >
< head > < title > Hello World < /title > < / head >
< body >
< h1 > Hello World < /h1 >
Server time is < %= System.currentTimeMillis() >
< /body > < /html >

As in the servlet example, whenever this url is requested, the time of the server is shown within the response web-page. This code is written within a .jsp file and placed within the web-server. The web-container will automatically generate a Servlet for this JSP page and then serve requests. Lots of the boring stuff in Servlets is taken care of. But in essence, the Servlet generated for this Jsp page will be very similar to the above page.

The < %= "Java code here" > is used to embed java code within a Jsp page. There are additional tags, directives and methods for scripting. Both Servlets and Jsp also have advanced features for filters, custom tags, session management etc.

The best way to get the basics is to practice and read more examples. Download and install Tomcat. There are sample examples which explain a lot. Also you should get a whole bunch of tutorials at developerworks-java. This is one tutorial.

Wednesday, March 09, 2005

Attributes/Annotation usage

.NET introduced the concept of "Attributes". Java 1.5 came out with a similar concept called "Annotations". They take a while to fully understand. Examples always help and here's one that does a good job of explaining WHAT they accomplish.

It's interesting to see the evolution of languages and how newer features are just formalized notions of what you could do before that feature came to be. More often than not, it was just "hacking" a feature for something it was'nt really meant for. Classes (from Structs), Interfaces (from Abstract Base Classes with no implementation), Enums (from grouping named constants), Properties (from Getters/Setters), Events (from function pointers) and now Attributes/Annotations (from Marker Interfaces?) all fall into this category.

Sunday, March 06, 2005

Re: Databases Part 1

Finally responding on this great post. Waiting on part deux.

A table can have a primary key.

When you say "can" dyou mean a primary key is NOT necessary? I thought it would be.

Things get a bit messier in real life scenarios. Consider Age was one of the fields in the Employee table. Now Age could be modelled as an Integer data-type. An Integer can be negative, but Age can definitely not be. So such simple rules are enforced by using a CHECK's. The definition of the Table is called a Schema. This Schema is mentioned using the CREATE statement. PK's and FK's are mentioned along with the Field names and this is where CHECK's can be applied too. I'll not get into the syntax here. A simple line like CHECK ([AGE>0]) will enforce the integrity of the Age field.

One thing that needs to be considered is where the error checking happen? Does it happen in the "business logic" layer or directly in the data layer? I would think a lot of times the database should ONLY be conserned with storing information. All the validation should happen elsewhere. Wouldn't it be more convenient that way?

Why more convenient? Because your business logic layer interacts with both presentation and data layers. If something doesn't get validated it's easy to present the error to the user. I'm not sure how this would be handled with the database. What happens when the CHECK([AGE] > 0) fails?

I guess the question comes down to what responsibilities the database should take on. It seems the trend is to make more and more things happen in the data layer. The next version of SQL Server is being integrated with .NET. So you can apparently write stored procedures in the .NET languages rather than SQL. I believe Oracle has had this capability with Java for a while. Also, another big trend is SOA - Service Oriented Architecture. The idea is to make each layer completely separate with each providing services. You call those services instead of directly making SQL calls. I suppose these will be Web Services, so you can invite others to call them - not just your app.

Each trigger is associated with a TABLE on some event.

This is quite cool. I didn't know this was possible. You can basically keep a log/trace of everything that's going on in your database this way.

I'll post later on Stored Procedures, Prepared Statments and simple Queries. If you guys want some other info, I'll try. Was this blog too complex/easy?

I'm interested in Stored Procedures just because I've read that they are beneficial to app performance. Is that really true?

What db are you working with? I've had basic experience with Access and SQL Server.

Saturday, March 05, 2005

Eclipse On The Rise

By Charles Babcock of InformationWeek

IBM has had to walk a tightrope between open-source and
proprietary forces to make the Eclipse programmer's workbench a
success, Lee Nackman, chief technology officer in IBM's
Rational Software unit, told attendees at the EclipseCon
conference Thursday. By most measures, the high-wire act has
succeeded "beyond our wildest imaginings," Nackman said.

Eclipse, a Java workbench that can host many unrelated
development tools, has emerged as the prime alternative to
Microsoft's popular Visual Studio .Net set of integrated
programming tools. Nackman insisted the name Eclipse was aimed
at Microsoft, not Sun Microsystems, originator of the Java
programming language.

The name was selected in a January 2000 meeting at IBM's
Raleigh, N.C., facility, Nackman said. "E-business was hot. We
tried a lot of E-sounding names," but the Eclipse name stuck,
he said. IBM realized at the time that Microsoft was on its way
to establishing a dominant set of development tools with Visual
Studio. To challenge them, IBM and other Java vendors, such as
Symantec Corp. with Visual Cafe and Borland Software Corp. with
JBuilder, were going to have to stop "reinventing the same
things over and over again. We were not moving fast enough to
keep up with Microsoft," he said.

IBM turned the idea of a tools platform over to a subsidiary,
Object Technology International, in Ottawa, which used small
teams to develop new tools. IBM's own Visual Age toolset was
based on the Smalltalk language and "was getting increasingly
brittle." The new development environment would have to remain
flexible and allow dissimilar tools to plug into it and share
files.

In November 2001 IBM decided to let Eclipse go public as a
freely available open-source-code project.

Nackman said he and members of IBM's Visual Age and WebSphere
groups thought top management would resist such a move, but
they had seen earlier successes working with the Apache HTTP
server group, now the Apache Foundation, and Linux open-source
developers. "It turned out to be not much of a struggle,"
Nackman said.

Even so, for many months, many Java tool competitors refused to
sign up as Eclipse users or joined the project as "voyeurs,"
watching from the sidelines but not committing to its ongoing
development. The open-source project was launched with nine
vendor backers, including Borland, Rational Software,
TogetherSoft, and the new owner of the Java tool Visual CafŽ,
WebGain.

IBM remained the largest code and financial contributor to
Eclipse and collected feedback from market researcher Gartner
that indicated the outside world still thought of Eclipse as an
IBM-controlled project.

IBM knew Eclipse needed "conceptual integrity" or technical
leadership that kept it focused on its primary role as a
plug-in platform for diverse tools. At the same time, major
rivals were reluctant to invest in it when it was still under
apparent IBM control. And potential users were confused: "What
is Eclipse? An IBM thing or a weird open-source thing
controlled by radical hippies?" Nackman said.

IBM "wanted to get into a put-up-or-shut-up mode" with
Eclipse's titular supporters. The expansion of the Eclipse
board of directors March 1 at the "strategic developer" level
has brought in competing tool vendors BEA Systems, Scapa
Technologies, and Sybase. Borland, already a member, increased
its commitment to the strategic developer level, which carries
a $250,000 annual fee.

With competing Java vendors offering Eclipse-based versions of
their tools, "Eclipse has dramatically reduced fragmentation.
The tools have come together. The ecosystem is thriving,"
Nackman said. Eclipse.org, a URL that four years ago had to be
purchased from a girls' soccer team in Illinois, has become an
open-source project that's rapidly branching out into
data-management tools, Web tools, business-intelligence and
reporting software, and test-and-performance projects.

To expand on its success, Eclipse will have to maintain a
discipline of only permitting published programming interfaces
into the workbench system and not letting the multiplying
projects overlap too much. At EclipseCon, Nackman said he had
seen the "good-faith discussions" that were resolving those
issues. "People are coming in to this discussion asking what's
good for Eclipse."

Proprietary technology vendors such as BEA Systems, Borland,
and IBM can support Eclipse and still make products for sale,
he said, because they "will constantly be lifting the line,
constantly innovating above what Eclipse does."

Wednesday, March 02, 2005

The Emperor Penguin

Interview with the Emperor.

Re: More on C# and C++

The one time I picked up a C# book and read some fundamentals,.. I was really quite lost. I kept wondering where is all this in Java and is it really needed. The features did have merit but life was simpler without them.

Can you give some examples? I somehow feel C# maybe simpler because it has better abstractions - things like delegates, events, properties and attributes. Also, Java 1.5 has included many features from C#.

Is NUnit widely used? I think its similar to the JUnit library.

NUnit was a direct port of JUnit. Recent versions have made better use of .NET features like attributes, which have made it better. For example, in JUnit, you have some restrictions like you your test class has to extend "TestCase" and you HAVE to start your method names with "test". In NUnit, you just apply an attribute, ["TestCase"] to your class - no need to extend it, and similarly just apply an attribute ["Test"] to your method - no need to start it with "test".

NUnit is quite popular. But I fear Microsoft is going to have a negative affect on their growth. With Visual Studio 2005, they are introducing Visual Team System, which includes it own testing framework. I'm actually not sure if the Team System features are only for the high end version of Visual Studio or if they will be included in all. This is just another example of the difference in cultures between the Java and Microsoft camps.

JUnit was started by the community and has been accepted as an unofficial standard. Microsoft on the other hand, instead of embracing NUnit has gone and done their own thing. I'm sure their features will be great and it will integrate really well with Visual Studio providing for a great experience. But it just shows that they haven't really opened up to the .NET community.

Java is also a pretty huge framework. It is divided into Standard and Enterprise Editions, but are still very huge in themselves. Are .NET api's divided similarly? And the Java api's are bloating too. So there doesn't seem to be much of a diff there.

.NET has two versions - .NET framework (clients and servers) and .NET compact (mobile - similar to J2ME). I guess it's not going to matter a whole lot that .NET will keep getting bigger because Microsoft will just integrate it into the OS - That's what WinFX is all about. So no headache of downloading it. I found the idea of a linker for .NET quite interesting. Why wouldn't this work?

I just read something similar in a book recently - Class invariants. Never thought of this stuff before. Could Mohn post an example.

I had posted something on class invariants long back. This was during the period where we obsessed with assertions.

Re: Eclipse Tutorials

I use Netbeans by Sun. Lets see if I find something really attractive in Eclipse to switch. Btw one of my favorite features in Netbeans is Refractoring.

Is Netbeans free? Or is there a free (community/personal) version? What about IntelliJ - It regularly gets voted top Java IDE.

Eclipse has refactoring features. Microsoft has been quite late to the game on this one. Visual Studio 2005 will finally include it.

Eclipse has been built up, not only as a (superb) IDE, but also as a platform for plug-ins. I love how JUnit so easily plugs into the environment. It just makes it so much more convenient to write tests... It makes you want to. I haven't had a chance to explore other plug-ins, but I've seen a ton of them, including articles on building them.

What's impressed me most about Eclipse is that it is written entirely in Java. I haven't had any unreasonable performance problems at all. I've used it both on Windows and Linux and the experience is absolutely seamless.

What is software design?

Exerpt: "The following essays by Jack W. Reeves offer three perspectives on a single theme, namely that programming is fundamentally a design activity and that the only final and true representation of "the design" is the source code itself. This simple assertion gives rise to a rich discussion—one which Reeves explores fully in these three essays."

Good set of articles - all three. The first one was published over a decade ago when the hot new language was C++. The second one was published last month.

I can see where the author is coming from. For the most part I agree with his point that you can't have a clear separation between designing software and actually implementing it. It has to be an iterative process. Yes you do need to think about the design of the product. But there are SO many things that just don't come into play until you actually start implementing it. This is true even in the "proper" engineering disciplines. So many unforseen events can occur.

From what little experience I have had with the small projects I've worked on, I've experienced it. During the design phase, you're generally supposed to think of everything. But it doesn't work out that way. You need the implementation to back you up and to weed out potentialities you hadn't thought of. As he says, even builders create prototypes and test them out before starting on the real thing. With software, since it's so easy to replicate, you don't *really* need the prototype. You can start on the real thing, little by little.

His other point is that code is documentation. There has to be something said for self-documenting code. The intent of code is precise. The same can't be said of languages like English. There can be so many ways to interpret it. With code, there is only one meaning. Don't get me wrong, I think proper documentation is essential. And things like javadoc where your documentation is so close to the code has been pretty revolutionary. But there are still times where javadoc doesn't tell you what's going on *exactly*. Take one look at the implementation and it makes sense.

Tuesday, March 01, 2005

Eclipse Tutorials

Got a link to a whole bunch of tutorials on various Eclipse technologies. Btw Eclipse is an open-source IDE by IBM.

http://www.eclipsecon.org/tutorials.php

I use Netbeans by Sun. Lets see if I find something really attractive in Eclipse to switch. Btw one of my favorite features in Netbeans is Refractoring. Basically a change in some code is reflected in all dependent areas. From the netbeans site:

Refactoring
* Renaming of classes, methods, and fields
* Moving of classes
* Field encapsulation
* Changing of method parameters
* Finding usages of classes, methods, and fields

Saturday, February 26, 2005

Re: More on C# and C++


The basic focus in creating C# was simplicity (not to the levels of Java, but close).


This is a very important point you made. The one time I picked up a C# book and read some fundamentals,.. I was really quite lost. I kept wondering where is all this in Java and is it really needed. The features did have merit but life was simpler without them.


Regarding Coherent Libraries... MS keeps saying how they want to get the community involved with their technology. But it pales compared to the Java community. utting everything in one gigantic framework just keeps bloating it up and you have to pay the size penalty regardless of whether you will use them APIs or not.


Is NUnit widely used? I think its similar to the JUnit library.

Java is also a pretty huge framework. It is divided into Standard and Enterprise Editions, but are still very huge in themselves. Are .NET api's divided similarly? And the Java api's are bloating too. So there doesn't seem to be much of a diff there.

There area however many widely used 3rd party Java libraries and apps. Some even competing with the Standard api's. What do you think is the reason for this state in .NET?


As as aside, have you guys read anything on Eiffel? I've heard that it's heavily contract oriented. As in, even pre and post conditions can be specified in code.


I just read something similar in a book recently - Class invariants. Never thought of this stuff before. Could Mohn post an example.

Sunday, February 20, 2005

New Scientist

The magazine "New Scientist" has a special issue focusing on India.

Wednesday, February 16, 2005

Movie recommendations

Had a great valentine's day!!

Saw two hindi movies.. one good and the other just simply amazing.

The good one is "Page 3". Based on high society life in Aamchi Mumbai.

The great movie is "Black". If you haven't seen the movie yet, get up and go. There is a reason why a lot of Indians think this movie deserves somthing at the Oscars. Definitely one of my all time favs and highly recommended.

Thank God Bollywood is moving away from the standard masala movies. Getting some variety of late. The degree of sleaze is also increasing alarmingly. Its funny how we Indians are hypocrites in a way. Aware of sexuality but yet conservative. The generalization I made was what I think is the general thought.

Friday, February 11, 2005

Google Maps

Few days back the Do No Evil company released another amazing web app... http://maps.google.com. Only works with IE and Firefox. And it subscribes to the map of the world after George Bush's second term (joke from slashdot).

Anyway, the blog world being what it is, responded super fast. There's already a post demystifying how it works. As expected a lot of DHTML, XML and XMLHttpRequest.

Databases Part I


Mohn mentioned Stored Procedures which I have been working on as part of the current DBMS module. You guys interested in the topic?

Of Course, don't even have to ask. Post it.


I was just trying to buy some time.. keep the blog rolling. The Database Module (DBMS) is almost over. And like always learnt a LOT. I'll try and cover a few topics I learnt in brief. Before the module I was a DBMS dumb-ass. Now I am a novice..

There are different models for DBMS. The one all of us use and see generally are Relational DB's. These are based on Relational Algebra and Relational Calculus. In Relational DB's information is stored in tables and various realationships exist between different tables. A table consists of rows and columns. The SQL language is based on Relational math, with some additions and ommissions. Most SQL queries are easy to understand. Then you can combine, nest etc to get info from the DB.

The thing I want to focus on is Integrity and Constraints. There are different constraints which can be set up which maintain the integrity of the database. These contraints are used to make sure that data in the DB satisfies some rules.

A table can have a primary key. A primary key is used to uniquely identify a single instance within a table (ie a row). So no two rows can have the same primary key. Also no row can have a NULL in the primary key. This is known as Entity Integrity Constraint.

Like mentioned before, tables are generally related to each other. In a DB, a table has a Foreign Key to show a relationship. Consider an example with two tables Employee and Department with cols as shown below.

Table Employee { (PK) Emp_ID, Emp_Name, (FK) Dept_ID }
Table Department { (PK) Dept_ID, Dept_Name }

In this case Employee belongs to a particular Department. So the FK in the Employee Table is a Primary Key in the Department Table. This brings us to Referential Integrity. Referential Integrity means that if a FK exists in a table then the corresponding PK has to exist in the referenced table. In simpler terms suppose there is an Employee { E101, Scott, D505 } then there has to be an entry in the Department table with D505 as a PK like { D505, Management Board }. If D505 does not exist, then the DB will no allow you to enter the E101 row.

The above two contraints were simple.

Things get a bit messier in real life scenarios. Consider Age was one of the fields in the Employee table. Now Age could be modelled as an Integer data-type. An Integer can be negative, but Age can definitely not be. So such simple rules are enforced by using a CHECK's. The definition of the Table is called a Schema. This Schema is mentioned using the CREATE statement. PK's and FK's are mentioned along with the Field names and this is where CHECK's can be applied too. I'll not get into the syntax here. A simple line like CHECK ([AGE>0]) will enforce the integrity of the Age field.

And obviously things can get even more complex (read nastier) in real life scenarios. Suppose I can insert a particular entry only on the basis of checking some other tables or the table itself. This can be thought of as having a sub-query along with every INSERT. This is where TRIGGER's come into play. Consider this example.

CREATE TRIGGER reminder
ON titles
FOR INSERT, UPDATE, DELETE
AS
EXEC master..xp_sendmail 'Blah', 'Blah'
GO
Each trigger is associated with a TABLE on some event. In the example above, the TRIGGER reminder, is called whenever there is an INSERT, UPDATE or DELETE on the TABLE titles and a stored procedure is called with the EXEC statement. So based on some event some action can be taken. Wrt to business rule integrity, I could ROLLBACK if some condition was not satisfied.

In conclusion, Entity Integrity and Referential Integrity are more pertinent to the integrity of the data in the DB. Simple CHECK's and TRIGGER's are for validity of data wrt a particular business rule.

I'll post later on Stored Procedures, Prepared Statments and simple Queries. If you guys want some other info, I'll try. Was this blog too complex/easy?

Tuesday, February 08, 2005

Managed Code Verifiability

Recently James Gosling (of Java fame) made some comments about .NET being unsafe.

Expectedly, there were rebuttals from the Microsoft camp. Here are two which I found particularly nice, in that they not only responded to his claims, but also explained the basic idea of managed code verifiabilty. The first one is particularly good.

Testing James Gosling's Thoughts on C++ in .NET

Huge Security Hole in Solaris and JVM

Re: Hacking Websites

The You suck message did feel nice for a couple of days.

I was surprised it showed up. I thought I took the precautions I mentioned in the article. I guess the blogger server is manipulating even that. Anyway, I finally settled on putting spaces between the tags, to display them.

Mohn mentioned Stored Procedures which I have been working on as part of the current DBMS module. You guys interested in the topic?

Of Course, don't even have to ask. Post it.

Sunday, February 06, 2005

Pure C++

Sorry if I'm beating this drumb a little bit too often lately, but another nice intro article to C++/CLI on MSDN mag.

One of the main concerns about moving from native manual memory managed to an automatic GC'd environment is one of deterministic destruction i.e. the lack of it. He mentions some stuff at the end about how they are trying to achieve similar functionality in .NET with C++. It's pretty interesting how they achieve it.

Re: Did Microsoft lose the API war ?


I googled "Google Desktop search" and the first few articles mention that it does indeed have a local web server. Dyou think a web server is needed just because they are trying to present the results in the Google Web Search like interface i.e within the browser, using html?


Simply to provide one app both for Google-Desktop and Google-Web. The user does not need to shift between apps.


Do any of you know how Gmail works internally?
They have a LOT of data redundancy to counter failure.
Regarding the client. Yup, it's a lot of dhtml. Have you viewed the source?


The major reason why google has huge amounts of redundancy is because they expect their hardware to fail. Seriously. Google do not use the most top-end hardware in the market. They use off-the-shelf x86 hardware. This helps in keeping costs down. So they can upgrade systems more regularly at a cheaper cost. Their software is built aroud the assumption that some node will fail. Amazing stuff. Everyday the Java and I think .NET API's are getting more and more complex. Layers of patterns over patterns are being built. You just need the most advanced hardware to run stuff for say 10,000 simultaneous connections. This stuff feels a bit awkward. I'll explain more later..

I haven't tried looking at the source. Dunno DHTML etc.


So, all old java code will work on the newer 1.5 jvm. New java code, developed with generics and newer types won't work on pre 1.5 jvms. This is exactly the case with .NET. I don't see any reason why you can't add NEW bytecodes. Don't change any existing bytecodes. How would there be a break in compatibility?


The only valid answer I have is wrt to the compatibility of all JVM's supporting a fixed set of bytecodes. The JVM's do not need to be re-written to work with Java 5.0. I too am not totally convinced with the rationale behind this.


Basically, you can do everything in ASP that you can with ASP.NET, but it was a mess to code, debugging was a nightmare and it was based on COM which was torture. ASP.NET has made the development experience much better. I don't know anything about the web tech in Java, but from what I've read, it seems similar to ASP i.e. complicated. Can Rahul provide some details about what's required to develop a dynamic site using Java tech? Is JSP enough or dyou need other thing like JSF, Struts, Servlets, EJBs etc...?


I made a statement that ASP was lame compared to JSP. One reason was that JSP pages are compiled only once. For ASP it happens more often. Is it for every request?

Using JSP by itself is easy, but you'll manage to mix UI and business logic etc. It is possible to create MVC apps by making some Servlets, but rather use Struts. Struts is an API which helps you develop MVC based Web Apps. Servlets and JSP are technically the same thing. A JSP page is easier to code and is converted to a Servlet by the Web Container.

I read quite a bit on Struts lately. What I learnt is Struts is HARD, and JSP by itself is messy. In most apps you need to connect to some back-end database. You can use JDBC for connecting to a database. EJB and other stuff are used for advanced persistence of objects and advanced stuff like transactions etc. This area of persistence is where Java sucks at the moment compared to .NET.

Struts also internally uses Servlets. Basically Struts helps structuring the Web App really well. Obviously there is an overhead of performance. But that is not what concerns any one. I brushed through two books by Wrox on JSP and Struts. In addition to Struts, they advised using two additional layers of "design". One to manage Persistence and another to store the Business rules. Both these layers are to be included at the Model layer within the Struts MVC.

I have to admit that in the end the Web App was beautiful. I mean the design felt so damn right. But at the same time, it also felt too damn bloated. Too many things happening on a simple request. Its like screw performance. So it was a funny feeling.

Now the usual questions!! How does stuff happen in the .NET world? How are ASP.NET pages structured? How easy to develop, and can it be done without an IDE easily? Also if you really want good design, how bloated does it get? How much can as ASP.NET dev get to know about inner workings, under the hood?

Thats when you see something like google apps. Which really are efficient and are great at the same time. Doesn't it feel like Java and .NET are making like easier but making you pay somewhere else.

Re: 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.

Blah blah...


Yes ... I am responding to the super blog by Mohn after so long that I need to provide a link to codeword itself!! That was one of the best blogs we've had.

The You suck message did feel nice for a couple of days.

Haven't come across more cracking methods though. You guys tried anything? Leart anything new?

Mohn mentioned Stored Procedures which I have been working on as part of the current DBMS module. You guys interested in the topic?

Wednesday, February 02, 2005

Re: More on C# and C++

For the most part I agree with his points. The basic focus in creating C# was simplicity (not to the levels of Java, but close). So they tried to remove everything that would get in the way of that goal. Long back, in one of his posts he mentioned how when the began the design, they started off giving each (potential) feature a -10 and then tried to make arguments for it to be included in the language. This meant it need a really strong case to get in.

A couple of points where I feel I disagree with him.

Regarding Coherent Libraries... Yeah, the .NET framework includes everything but the kitchen sink. And yeah, it's very nice and convenient. But at the same time it seems to be shutting out other people from coming up with libraries of their own. MS keeps saying how they want to get the community involved with their technology. Towards that end, they have opened up quite a bit with their dev blogs. But it pales compared to the Java community. In the Java circle, a number of APIs have come out and risen to prominence (Rahul can mention them). They are not part of the standard Java API, but everyone knows about and uses them. I don't think I can even name one third party popular .NET library. Putting everything in one gigantic framework just keeps bloating it up and you have to pay the size penalty regardless of whether you will use them APIs or not.

I think I actually read it on some Sun dev's blog that this was a big difference in view points of Java and .NET. Although, Sun seems to have this overarching hold on Java, it really is quite an open thriving community. MS needs to change their attitude and let others join in.

Regarding const... In this one I completely disagree with him. There is this "Principle of Least Privilage" where you only allow the absolute lowest possible acess to get the job done. const enables you to make use this principle in C++. You can make the contract clear that you won't mess with someone else's object. Why not do the same for C#? Yeah, C# is a more "safer" language than C++ with less potential for abuse, but anything that makes the programer's intentions clear in code can't be bad. In C# most arguments are passed by reference (except for value types and even they could (unkowingly) be passed by reference through boxing). So the callee could modify it any way they want. I really think that const should have been part of the language.

As as aside, have you guys read anything on Eiffel? I've heard that it's heavily contract oriented. As in, even pre and post conditions can be specified in code.

More on C# and C++

Part deux from Eric G. And check the comments for more discussions on why things missing in C# from C++ is good/bad.

Cross-Platform

When I wrote the last post, I was thinking of cases where you have a choice between languages, so I didn't think of cross-platformk, since if you need to run on a platform where a language isn't present, that pretty much eliminates the language from consideration.

It's true that C++ is available on far more platforms, and if that's important in your case, C# probably isn't an option for you.

Templates, template metaprogramming, STL, Boost

I missed templates as an advantage that C++ currently has, as I forgot that Whidbey isn't there yet for C# programmers. When Whidbey is widespread, C# will have the majority of the features that I'd want related to generic types, though it won't be able to do as much as C++ does.

In my mind, that's (mostly) a good thing. While there are things that aren't in C# generics that I'd like, I think that, because of the indirection involved, generic types are something that are best enjoyed in moderation, as they're near the limit of what most programmers can easily understand. Which brings us to template metaprogramming. The discussions I've read on this topic list "power" and "optimization" as the big advantages of this technique, and I'd have to agree with that evaluation. But the code that I've looked at makes normal template code look simple and straightforward. So, I'm not sorry that you can't do this with C# generics.

Something I do miss is the ability to do Mixins, which would be a nice complement for a language without multiple inheritance. They would be helpful to add in system functionality without burning the base class.

STL isn't the kind of library that I like to use, as I think it's too baroque. Sure, you can do a *ton* of things with it and easily switch things around, but I've never found that I need to switch things around that often, so it's complexity that I don't use, but still have to deal with. So, for me, no thanks - I'd rather have foreach, which covers about 90% of my loops. Oh, and before I leave this topic, I should mention that the richness of data structures in STL is a lot greater than that in C#, though you should keep your eye out for C5 and PowerCollections when Whidbey shows up.

In the current C#, foreach only supports one way of iterating. About 3 years ago I wrote an article on some collection wrappers you could use to support other ways of iterating, though at some cost to performance. Unfortunately, I chose to call the "iterators", which, of course, is also the name of a C# 2.0 feature that allows you to make objects iterable more easily, and support multiple ways of iterating a collection.

Boost seems like an obvious C++ advantage, if you're working in an environment where you can use outside libraries.

Object Lifetime

There were a lot of comments around deterministic destruction, and there is certainly a big difference between the "programmer owns the allocations" and the "the GC owns the allocations" approaches.

I will admit that when I first started using C#, I missed that feeling that I had full control over what was going on in the system. But over time I found that while I did need to be concerned with scarce resources (db connections, file handles, and other system resources), I didn't really need to be spend a lot of attention on memory resources. For scarce resources, "using" works well for me, and I prefer the scoping that "using" gives me over the scope-based lifetime that you get with smart pointer approaches in C++, and I also like that it's more explicit.

This does not mean that you can totally ignore the issues around object allocation in C#, as Rico's has said, repeatedly.

Oh, one other point on object lifetime. Having an environment where there is no automatic scope-based lifetime makes supporting exceptions much cheaper in C#, as there isn't the overhead of tracking what objects are live at any point that is required by C++ exceptions.

const

Which brings us to const. My experience with const is as follows:

When I used const in my projects, I always ran into situations where I needed a routine that was const to become non-const. That meant either changing that routine - and then updating all of the callers so that they were non-const - or creating non-const versions of existing routines where applicable. Neither of those is a particularly nice and/or fun thing to do, and after trying it for a while, my conclusion was that having const didn't give me enough benefits to make it worth the disadvantages.

I do agree that const can give some protection against the programmer doing the wrong thing (which, interestingly, is not really in keeping with the general C++ philosophy that programmers should be able to do whatever they want, even if it's wrong (yes, I'm being a bit extreme there)), but since it's merely a convention and not a guarantee (as I can cast const away whenever I want, or just use "mutable"), I don't see a lot of value.

I've talked to enough people to know that my opinion is not shared by all.

C# things I missed

There were a couple of notable things I missed from my C# list.

Events

Events are much much more useful than I had originally thought. While you can do a lot of similar things with interfaces, events are great for the sort of loosely-coupled components that I like to create. For me, events are a feature that work exactly the way I want them to.

Data types

This is a big one that I missed.

In C#, there is one string type.

In C++, I'm currently dealing with code that uses:

CString (the ATL/WTL type)
LPCTSTR
LPTSTR
WCHAR*
TCHAR*
BSTR
_T("constant")
and needs to transform strings from one type to another fairly regularly. I also spend time making sure I have the right distinction between byte count and character count when dealing with such types.

Re: Demo Perils

I doubt any of us have actually given demos considering we haven't really created something interesting enough for others to use (ie. something like DTrace)! The closest thing I've come to a "demo peril", is when running my project for grading. It works fine on my box, but when I run it for the grader, it bombs.

Monday, January 31, 2005

Demo Perils

I am copying an excerpt from this blog by a Sun employee.

It was about a Dtrace demo which went a bit out of hand.

-----------------------------------------------------------
Last week, I had the opportunity to give a DTrace demonstration for a
highly technical -- and highly influential -- audience at a Fortune 100
company. When I demonstrate DTrace, I typically do a couple of invocations
on the command line before things become sufficiently complicated to merit
writing a DTrace script. And it was when I went to run the first such
script (a script that explored the activity of xclock) that it happened:


# dtrace -s ./xclock.d
Segmentation Fault (core dumped)
#

If you've never had it, there's no feeling quite like having a demo blow
up on you: it's as if you peed your pants, failed an exam and were punched
in the gut -- all at the same horrifying instant. It's a feeling that
every software developer should have exactly once in their lives: that
unique rush of shock, and then humiliation and then despair, followed by
the adrenal surge of a fight-or-flight reaction. In the time it takes a
single process to dump core, you go from an (over)confident technologist
to a frightened woodland creature, transfixed by the light of an oncoming
freight train. For the woodland creature, at least it all ends mercifully
quickly; the creature is spared the suffering of trying to explain away
its foolishness. The hapless technologist, on the other hand, is left with
several options:

1. Pretend that you didn't write the software: "Boy, will you get a load
of those fancy-pants software engineers? Overpriced underworked morons,
every last one!"

2. Explain that this is demo software and isn't expected to work: "Well,
that's why we haven't shipped it yet! I mean, what fool would run this
stuff anyway? Other than me, that is."

3. Make light of it: "Hey, knock knock! Who's there? Not my software,
that's for sure! Wocka wocka wocka!"

4. Suck it up: "That's a serious problem. If you can excuse me for a
second, let me get a handle on what we've got here that we can demo."

I always aim for this last option, but on the rare occasion that this has
happened to me (and this is -- honest -- probably the worst that a
customer-facing demo has gone for me) I usually end up with some
combination of the last three, often with plenty of stuttering, some mild
swearing ("Damn! Damn!") and profuse sweating.

-------------------------------------------------------------

You guys ever given demos? Ever goofed up??

Rahul


Re: Nerd Level

80 -> "High-Level Nerd. You are definitely MIT material, apply now!!!."

I'm actually quite surprised I scored this high. I consider myself just "slightly nerdy". I would think that being a "Windows man" would count big against being nerdy.

Btw I am proud to be a nerd.. are you?

I'm neither proud nor ashamed. But I don't think I'd advertise it.

Nerd Level

Found this link somewhere

http://www.wxplotter.com/ft_nq.php?im

Fill in the form to gauge your nerd level...

Btw I am proud to be a nerd.. are you?

I got a "High-Level Nerd. You are definitely MIT material, apply now!!!" though it seemed a bit high considering it is easy to guess the -less nerdy- answers and there were quite a few. So don't cheat incase you are tying it!!

Sunday, January 30, 2005

Re: Solaris vs Linux

The only reason I want to try out Solaris 10 is dtrace. I have already worked on UltraSPARC machines running solaris, and I believe the x86 version should be no different.

What experience have you had with Solaris? Any different from Linux? Ever worked on some BSD version. Hrishi had mentioned that you guys had some really old Sparc boxes at IIT.

Dtrace has been the most widely publiscised of the S10 features. Loads of devs must have downloaded it. And a Linux port have surely been started!!

Btw some other features are a new file system ZFS and some predictive healing capability which should be really interesting.

What is your level of expertise in Linux? From Kernel dev to Novice User(thats me). So expect loads of questions!!

The install is intuitive; it co-exists with Linux (so I hear) -- you need 12GB of free space. Except maybe the grub part. In any case, a simple installation guide is very much there on their site. If you need it, I can mail you a copy of the pdf, or I could put it on Hrishi's site.

I got the pdf from Hrishi's site. Thnx. The instructions seemed a bit too simple. And that was scary.

I'm not sure if I'll be able to dload S10 and should take quite some time. Any of you guys installed it? Especially asking as I need to use grub.

Saturday, January 29, 2005

Re: Solaris vs Linux

The only reason I want to try out Solaris 10 is dtrace. I have already worked on UltraSPARC machines running solaris, and I believe the x86 version should be no different. (Like Linux, most of the Solaris operating system has been designed to be portable; luckily for the engineers at Sun, only very necessary sections are architecture-specific.)

The install is intuitive; it co-exists with Linux (so I hear) -- you need 12GB of free space. Except maybe the grub part. In any case, a simple installation guide is very much there on their site, but it won't deal with the coexistence I guess. If you need it, I can mail you a copy of the pdf, or I could put it on Hrishi's site.

Regarding the Solaris/Linux comparison pdf, I personally think it is an excellent discussion. However, I have one thing to say -- security is more in the hands of the system administrator, and less in those of the OS developer. And Solaris is extremely difficult to manage well! So, despite the fact that Solaris offers more security than Linux, I would currently recommend Linux to most lesser-than-FBI applications. A much more relevant white paper would have some sort of a metrics to compare ease of administration.

Anyway, fingers crossed till Linux gets its own dtrace :-)

Re: Solaris vs Linux

A while back Rahul and Hrishi had a discussion/argument about Solaris and Linux. Looks like some guys took their lead and released a whitepaper (pdf) comparing the two.

What were you debating about anyway?


The PDF did make some good points. All factors other than hardware support were clearly for Solaris. But somehow the conclusion did not suggest Solaris as it should have. That was a bit wierd. On the link providied by Mohn, right-click and Save Target As.. The PDF downloads from www.sun.com . So maybe this PDF is not totally unbiased!! So that makes the document loose a bit of credibility.

Btw the search for codeword doesn't seem to work. Any ideas?? Will have to look back to see what questions I had asked then.

Do any of you know any major advantages of Solaris over Linux or vice-versa?

I will definitely like to install solaris on my desktop, but have not gotten installation steps. Hrishi, have any docs from IIT? Would any of you try?

Gentoo is the Linux distribution I prefer. This is their recent newsletter. One of the top items is Gentoo/OpenSolaris stuff. So it seems like some open source guys are noticing OpenSolaris after all!! The news letter also has a pic of Gentoo running on the latest mini-Mac.

Coding competition??

There is "AN ALGORITHM INTENSIVE TIME CONSTRAINED ONLINE PROGRAMMING CONTEST" at IIT Kharagpur.

Visit http://www.bitwise.iitkgp.ernet.in/index.php for more info.

Dinesh and I have teamed up and registered for the competition.

Coding is in C/C++ so that should please Hrishi too. Talking about Time Constrained its 12 hrs long!!

Lets see how we perform!!

PS- Do you thing they not consider Java for perf reasons?? AARGH!!

Friday, January 28, 2005

Linus hired by Microsoft

Don't have a heartattack. Hypothetical memo sent by Microsoft-hired-Linus to Bill Gates in 2008.

Solaris vs Linux

A while back Rahul and Hrishi had a discussion/argument about Solaris and Linux. Looks like some guys took their lead and released a whitepaper (pdf) comparing the two.

What were you debating about anyway?

Wednesday, January 26, 2005

C# vs C++

Via Eric Gunnerson - one of the designers of C#. It's obviously biased, but he makes some points for C++ as well.

---
At the class a took a while back, the instructor asked me to talk a little bit about the benefits of C++ vs the benefits of C#, since I had worked in C++, then in C#, and now in C++ again.

I talked for about 5 minutes on why C# was better, in the following themes. Note that I'm speaking about the whole programming environment, not just the language.

Automatic memory management

There are several facets of this. When I read or write C++ code, I keep part of my attention on the algorithmic aspects of the code, and another part on the memory aspects of the code. In C#, I usually don't have to worry about the memory aspects. Further, in C++ I need to figure out who owns objects and who cleans them up, and also figure out how to clean up in the presence of error checking.

Exceptions

Without a lot of dedication, using return codes is a bug farm waiting to happen. In the C++ world, some functions return HRESULT, some return a bool, some return another set of status code, and some return a number and use an out-of-range value as an error indicator. Oh, and some are void. You not only have to write the correct code there, you have to successfully convert back and forth between the various kinds of error handling.

You also lose the opportunity to write more functional code. I end up writing something like:

CString name;
RTN_ERROR_IF_FAILED(employee.FetchName(name));

instead of writing:

string name = employee.FetchName();

And, of course, exceptions are fail-safe in that you get error reporting without doing anything, rather than having to do everything right to get error reporting.

Coherent libraries

The C++ code I'm writing uses at least 6 different libraries, all of which were written by different groups and have different philosophies in how you use them, how they're organized, how you handle errors, etc. Some are C libraries, some are C++ libraries that are pretty simple, some are C++ libraries that make heavy use of templates and/or other C++ features. They have various levels of docs, all the way from MSDN docs through "read the source" docs to "a single somewhat-outdated word doc".

I've said in the past that the biggest improvement in productivity with .NET comes from the coherent library structure. Sure, it doesn't cover everything in Win32, but for the stuff it does cover, it's often much much easier to use than the C++ alternative.

Compilation Model

C++ inherited the C compilation model, which was designed in a day when machine constraints were a whole lot tighter, and in those days, it made sense.

For today, however, separate compilation of files, separate header and source files, and linking slow things down quite a bit. The project that I'm working on now takes somewhere on the order of a minute to do a full build and link (that's to build both the output and my unit tests, which requires a redundant link). An analogous amount of C# code would take less than 5 seconds. Now, I can do an incremental make, but the dependency tracking on the build system I use isn't perfect, and this will sometimes get you into a bad state.

Tools

Reflection is a great feature, and enables doing a ton of things that are pretty hard to do in the C++ world. I've been using Source Insight recently, and while it's a pretty good IDE, it isn't able to fully parse templates, which means you don't get full autocompletion in that case.

Code == Component

In C#, you get a component automatically. In C++, you may have extra work to do - either with .IDL files or with setting up exports.

Language Complexity

C++ templates are really powerful. They can also be really, really obtuse, and I've seen a lot of those obtuse usages over the years. Additionally, things like full operator overloading are great if you want a smart pointer, but are often abused.

And don't get me started on #define.

The alternate view

So, if what I say above is true, the conclusion looks pretty clear - use C#. Not really much surprise considering who came up with the list.

But there are things that C++ has going for it, and it really depends on the kind of code you're writing which language is a better choice. In broad strokes (and in my opinion, of course), if you're doing user applications (either rich client or web), choosing C# is a no-brainer. When you start getting towards lower-level things like services or apps with lots of interop, the decision is less clear.

So, what do I think you get in C++? A few things spring to mind.

Absolute control over your memory

I think you actually need this level of control much less than you may think you need it, but there are times when you do need it.

Quick boot time

Spinning up the CLR takes extra time, and it's likely to alway take extra time (unless it's already spun up in some other manner). You don't pay this penalty in the C++ world.

Smaller memory footprint

Since you aren't paying for the CLR infrastructure, you don't pay for memory footprint.

Fewer install dependencies

You can just install and go, and your users don't have to install the proper version of the CLR.


So, that's pretty much what I said in the class. What did I miss?
---

What dyou think? In a lot of cases, C# could just as easily be Java.

Monday, January 24, 2005

Revenge of the <T>

Jarwars - Episode III

via this Bruce Eckel post. Check out the comments for potential causes of Auto-Boxing leading to Null Pointer Exception.

Saturday, January 15, 2005

Re: Did Microsoft lose the API war ?

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?

You're right. I googled "Google Desktop search" and the first few articles mention that it does indeed have a local web server. Dyou think a web server is needed just because they are trying to present the results in the Google Web Search like interface i.e within the browser, using html? As in, since everything is being done locally on your machine, it would seem like they don't HAVE to take that approach.

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).

All these (DHTML, CSS, (X)DOM, XML, XSL) are W3C standards. As far as I know, IE was the first to support XML, XSL and (X)DOM within the browser. Also Netscape 4's DHTML, CSS and DOM support was pathetic compared to IE4. Only with Mozilla and now Firefox, have they caught up and surpassed support for these standards.

Of the others I mentioned (Iframes, DHTML behaviors, XML data islands and XMLHttpRequest), I only know for sure that Iframes has become a standard. The others I haven't checked, but XML data islands and XMLHttpRequest functionality is there in Firefox (and soon to be in Opera, I believe).

A thing that needs to be said is that the W3C puts out standards and expects the browsers to support them. But the browsers themselves come out with innovative features. Slowly, the other browser will see that it is a great feature and support it. Eventually it becomes a standard. This was the case with Iframes. IE3 (maybe 4) came up with it, the others added it and eventually it became a standard. DHTML behaviors is an amazing concept. It enables you to create componentized scripts and apply them to elements on a page similar to a CSS class. IE5 introduced it. Unfortunately, it hasn't been standardized and I don't think Opera/Firefox support it.

Anyway, the point was that, IE4 completely overshadowed Netscape4. Then Netscape was open sourced. During that time MS came out with IE5 and 5.5 with even newer/better features for "rich" functionality. Yeah, they weren't standards, but they were useful. So a lot of people started developing higher end features for IE and more basic features to handle Netscape.

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?

They have a LOT of data redundancy to counter failure. Not only for gmail but also for their search. I mean they index ~8 billion pages. For that they need a LOT of servers (I read somewhere it might be something like 100K+ servers). Check out The magic that makes Google tick. He's talking about search specifically, but I would think that everything he says would apply to gmail as well.

Regarding the client. Yup, it's a lot of dhtml. Have you viewed the source? They've gone out of their way to hide it. Anyway, check out "About the Gmail engine and protocol" on this page at the very bottom. It explains some basic stuff.

Any idea on the gaming front? MS is releasing a new XNA platform or something that unifies dev.

Haven't heard about XNA. On the gaming front, MS is losing money on every XBOX they sell. They sell the hardware at a loss. They make money through games. So the more developers you get to publish on your console the better. That's why PS2 is the leader. Sony gets everyone to make games for them. MS, for a new guy, has done a decent job. Nintendo seems to be losing out the most.

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.

Yeah, I checked their site. They support MP3 in addition to AAC. But iTunes only sells in AAC format. The point is that they still prefer their own format and a lot of people aren't happy about it. And I still think iPod is way overpriced. $400 for 40 gig hddrive, small cpu, sound chip and some control features? It will be hard for others to topple them, but the price will definitely come down.

Apple released some cool products recently. The mini Mac and iPod shuffle. Sure would want to own some apple product some day.

Around this time every year at MacWorld they come out with all the cool products. But after the hype, nothing much changes in the big(ger) picture. As in, they still cater to a niche community. Don't get me wrong, their products look fantastic, but they are generally very expensive and don't seem to "play well" with others.

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.

So, all old java code will work on the newer 1.5 jvm. New java code, developed with generics and newer types won't work on pre 1.5 jvms. This is exactly the case with .NET. I don't see any reason why you can't add NEW bytecodes. Don't change any existing bytecodes. How would there be a break in compatibility?

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.

Basically, you can do everything in ASP that you can with ASP.NET, but it was a mess to code, debugging was a nightmare and it was based on COM which was torture. ASP.NET has made the development experience much better. I don't know anything about the web tech in Java, but from what I've read, it seems similar to ASP i.e. complicated. Can Rahul provide some details about what's required to develop a dynamic site using Java tech? Is JSP enough or dyou need other thing like JSF, Struts, Servlets, EJBs etc...?

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.

Web Services is a standard that comprisis of UDDI (Directory), WSDL (spec) and SOAP (protocol). Any platform that supports web services will definitely be compatible because they will agree on these three things. That's the whole point. If you expose a web service using Java, I will be able to invoke it using .NET and vice versa. I posted a link to an article (Objects, Components and Web Services) recently. The objects and components will be platform dependent. The web services are environment neutral.

One of the "pillars" they have mentioned for Longhorn is "Indigo" which is the communications area. This seems to focus on web services and making it easy to use them. Dunno much details about it though.

Friday, January 14, 2005

Objects, Components and Web Services

Fuzzy Boundaries: Objects, Components and Web Services

Images could have been bigger, but a well written article nonetheless.

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?