Tuesday, June 16, 2009

C++ Questions

Questions:

  1. What is extensibility? How can OOPs dynamic binding enable (virtual functions) old code calling new code?
  2. Do inline functions improve performance?

Answers:

  1. Something...Something... dekhenge!
  2. http://www.parashift.com/c++-faq-lite/inline-functions.html#faq-9.3

Thursday, July 13, 2006

Spring Experiences - 3 (Setup)

Assuming you have used eclipse as your IDE, lets now have a set-up which would help us launch our application and test it without any hassle.
Lets say, our project root folder is: SpringTraining and we aim to build MVC based webapp.
Then using eclipse->New->Folder, we may have our application structure as:
  1. SpringTraining/src [All source code and packages].
  2. SpringTraining/src/edu.springtraining.services [All services pakcage i.e. service interfaces (model) would go in here]
  3. SpringTraining/src/edu.springtraining.db.orm [All hibernate package - reverse engineering code generated *.hbm.xml + *.java]
  4. SpringTraining/src/edu.springtraining.db.dao [All DAO, which would contain access code and business logic would go in here].
  5. SpringTraining/src/edu.springtraining.mvc.controller [All controller code package]
  6. SpringTraining/webapps [Actual deployment directory].
  7. SpringTraining/webapps/training/ [deployment root]
  8. SpringTraining/webapps/training/WEB-INF [deployment contents container]
  9. SpringTraining/webapps/training/WEB-INF/web.xml [web.xml for our webapp container i.e. Jetty in this case].
  10. SpringTraining/webapps/training/WEB-INF/training-servlet.xml [Spring MVC wiring xml file].
  11. SpringTraining/webapps/training/WEB-INF/training-services.xml [Spring services xml, i.e. actual application xml]
  12. SpringTraining/webapps/training/WEB-INF/training-data.xml [Spring data access layer wiring].
  13. SpringTraining/webapps/training/WEB-INF/classes [the compiled byte-code]
  14. SpringTraining/webapps/training/WEB-INF/lib [all needed jars]
  15. SpringTraining/webapps/training/WEB-INF/jsp [all jsp files would go in here]
Note, for all WEB-INF/*.xml, you may also make them go under a directory like WEB-INF/conf/*.xml

To have jetty deploy or launch your application you need to do simply change in jetty's folder:
etc/jetty.xml
root



/projects/SpringTraining/webapps/
/etc/webdefault.xml
true
true


Note: The "projects" is a new folder under jetty-root folder and SpringTraining is a symlink (*nix) or short-cut folder (windows) to our actual SpringTraining folder.

With above structure in place, we can see, how MVC based development can start. You might make further changes to the packages, as you wish like, edu.springtraining.services might as well go under edu.springtraining.mvc.model.services ........ but as long as you get the big-picture and the whole idea, it suffices, rest is personal choice or maybe application requirements based.

Now you have spring-framework webapp MVC set-up ready!

Friday, June 09, 2006

Spring Experiences - 2 (Power of Hibernate)

It's time to generate java mapping classes to our DB. Hibernate is really a very powerful ORM framework. On top of that, it offers plethora of tools, IDE integration plugins, especially if you are developing on Eclipse.

So here's excellent description of hibernate tools installation:
http://www.hibernate.org/hib_docs/tools/reference/en/html_single/
Please refer it. For our project, we need not install anything related to jboss. Our project will be quite simple, light-weight. We will have Spring to wire all our objects and Jetty can be configured as web-application server, our object container.

At this point I assume, referring above link, you all have installed hibernate tools. It further explains how-to 'reverse engineer code'. It's quite simple. If you are using MySql, you might need to download mysql-jdbc-connector and include it your classpath (simply import it in lib directory - A directory under your project-root containing all jars). When you would opt for reverse engineer, you can specify what all you would like to be reverse engineered or exported (these options are under the Export tab). I prefer only .java domain files, hbm.xml and html documentation. We would code our own DAOs as per needed functionality. In later post you would see, how Spring wonderfully harnesses hibernate's functionality and helps building extensive, scalable and rapid application development.

Once you have the reverse-engineered code generated, there's 1 catch for MySql (atleast till date, the current version of of hibernate tools) . All .hbm.xml files you might find this string being added:
catalog="databaseName"
this is a BUG! It happens for MySql, not sure for other DBs. But thats the only bug, rest everything works like a charm. And fix to this problem is simple, remove the string from all your .hbm.xml files. Further more if you are on *unix based platform (I am on FreeBsd), I can help you better ...
simply use script to eliminate the string. On command line you can check it real quick as:
cat table.hbm.xml sed 's/ catalog = "databaseName"//' > table_1.hbm.xml

Hmmmm.... all right, now we have all java classes, next what? Isn't this article about Spring? Ofcourse, it definitely is about Spring. Spring does support + enhances use of various other technologies in a amazing fashion. As per our early decision, application being data-centric, we started from database. Now we are well established with the back-end DB layer. It's time to further build access logic and actual business logic. In my next post, we would start building code and wiring it with Spring.

Monday, May 08, 2006

Spring Experiences - I

Best way to develop is to develop by developing small, simple testable modules. Every programmer knows that. It's a saving in the long run. No wonder "Hello World" is like the developers "Shree Ganesh" (Indian auspicious words spoken at the onset of any work).

Anyways, once fundamentals are clear, there are too many things yet to be explored. What if you have to develop some advanced application but you just know the basics? Can you do it? Usually, tutorials, step-by-step approach are most helpful in such cases. You save your research time, follow tutorial, step-by-step, with customizations as and wherever, whenever needed, with comfortable understanding and confidence.

I am going to try to enlist my successful / unsuccessful experiences of development of a medium-to-large scale application on spring framework.

Goal: To develop a multi-tier extensible, scalable, flexible enterprise application.
Framework and others: Spring as overall application glue. Spring will be used to loosely couple various components. Jetty will be our servlet [webserver]. MySql will be our database and Hibernate will be ORM / DAO layer.

So lets start!

We can start in 2 ways - 1. first design classes and then, further develop 2. first design database tables and further proceed. Usually first step is most difficult, especially if there are too many unknowns to be researched. In my case, I started with design of DB tables, as the overall application was more data-centric.
Design of MySql Relational Tables Pointers:
1. MyIsam is default table and most optimized for DB operations. But it does not support relational linking. For any type of relational linking, MySql's InnoDB tables must be used. In general, we should try to split tables, certain tables hold information that can be linked with other more functional tables. It's usually these functional tables, that may have heavy DB operations and they can be made MyIsam. When we have such case where there exists a relational logic, but it is not supported by database, the responsbility gets obviously pushed on the back-end access layer (or maybe business layer) to maintain synchronization.
2. Most of the tables can be InnoDB, to have well defined and organized relational linking.

Now, after we have created the database or coded the db.sql, we have the database with tables. We will consider each each table as a business object and try to achieve this, by defining class for each table. Thus we are trying to map the classes over data now. It's here, where hibernate comes in very very handy! Hibernate manages all data flow using XML mapped files.
In the next part, we will try explore the power of Hibernate to automate the process of code-generation for the all the classes that map tables in our database.

Tuesday, November 08, 2005

Linux Vs FreeBsd

What is the difference between Linux and FreeBsd ?? Pros and Cons?

[meanwhile, research for mobile project still continues...]

Tuesday, October 25, 2005

Project1 - SMS Service Web2Mobile and the Challenge

In the sidebar I have provided the link for SMS Service. This is a small module I wrote. It works perfect, I have only tested it for T-mobile yet. But please if you a chance try it and let me know the results.
There are many limitations to this though:
1. It needs carrier information. If you have a friend who knows nothing about your carrier, then she/he cannot conveniently send you SMS without knowing your carrier. Is there any way that this can be resolved? I know they call it reverse lookup, but how do i do it programmatically? I don't want to run curl and parse html of certain existing sites that do this for free. There should be some interesting and elegant solution to this.
2. Currently only ascii based text messages upto 160 characters can be sent. It would be genius if this limit can be surpassed and html-based sms messages with unlimited length could be sent using the same Email Gateway system! I don't think this has been ever done before by anyone succesfully.

Both the above limitations can be overcome using pricey solution, where a wireless modem is used to actually send the messages. But you know, the network is in place [Email Gateways], infrastructure is in place, why then opt for pricey solutions? We are techies and lets see if we can nail this down! It's an open challenge.

Mutator - getter functions answered

Let me be very brief. For getters() if they return objects, i mean large objects, it makes sense to return be reference. But most of the times these objects are aggregated prviate members hence best solution that complies with OO semantics as well as provides optimization:

const ClassType& getClassType() const { .....}

All comments are most welcome.

Monday, October 24, 2005

Mutator - getter() functions

How should the getter() be declared?
what is best option to declare getter() such that it holds with OO semantics and also gives maximum optimization .... ?