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


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 javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorldServlet extends HttpServlet {

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

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

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Ž,

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

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:

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