Annotations are hardcoded string literals.

Well,
I do not have much to say apart from the what the title of this post says.

I do not like annotations as a way of weaving code for an application at all.
XML’s are bearable, but looking at an annotated code, is like looking at hardcoded values as if they are all string literals.

The reason I prefer XML over annotations is atleast they keep the configuration part staked away seperately or is it just me who does not like overloaded contexts?

Here’s the real motivation:
The OO paradigm was there to do the abstraction right, by punctuating them with annotations, we miss the broader general rule of why the object maping was done initally.

Let’s Keep the principle Simple!

Stable Dev Environment?

Once upon a time there was a Q&A that happened as follows…

Q:So when can you say that your local dev environment is ready?
A:When you have run a comprehensive unit test, pre-existing or drafted yourself.

Q:What is a comprehensive unit test?
A:One that covers all major components of the architecture you are working on.

Q:What can be the major components of an architecture, one may be working on?
A:Layer Code, deployment, DB, Jndi context, orm context, 3rd party API context.

Q:What’s your point?
A:You environment ain’t ready until all your environments are not accessible from your box. The best way to ensure this is with a unit test and know thy environment!

Some Maven gyaan

Maven is a project management and comprehension tool and as such provides a way to help with managing:
• Builds
• Documentation
• Reporting
• Dependencies
• SCMs
• Releases
• Distribution
Buzzwords
1) POM (Project Object Model) – The POM is the basic unit of work in Maven. POM essentials:
• project This is the top-level element in all Maven pom.xml files.
• modelVersion This element indicates what version of the object model this POM is using. The version of the model itself changes very infrequently but it is mandatory in order to ensure stability of use if and when the Maven developers deem it necessary to change the model. By default, the model version is set to 4.0.0.
• groupId This element indicates the unique identifier of the organization or group that created the project. The groupId is one of the key identifiers of a project and is typically based on the fully qualified domain name of your organization. For example org.apache.maven.plugins is the designated groupId for all Maven plug-ins.
• artifactId This element indicates the unique base name of the primary artifact being generated by this project. The primary artifact for a project is typically a JAR file. Secondary artifacts like source bundles also use the artifactId as part of their final name. A typical artifact produced by Maven would have the form . (for example, myapp-1.0.jar).
• packaging This element indicates the package type to be used by this artifact (e.g. JAR, WAR, EAR, etc.). This not only means if the artifact produced is JAR, WAR, or EAR but can also indicate a specific lifecycle to use as part of the build process. The default value for the packaging element is JAR so you do not have to specify this for most projects.
• version This element indicates the version of the artifact generated by the project. Maven goes a long way to help you with version management and you will often see the SNAPSHOT designator in a version, which indicates that a project is in a state of development. We will discuss the use of snapshots and how they work further on in this guide.
• name This element indicates the display name used for the project. This is often used in Maven’s generated documentation.
• url This element indicates where the project’s site can be found. This is often used in Maven’s generated documentation.
• description This element provides a basic description of your project. This is often used in Maven’s generated documentation.
More information about POM files can be found in POM reference and POM Introduction.
2) Archetype – Archetype is a Maven project templating toolkit. It provides a standard way to enable creation of sample projects which can be used as a starting point.

• To create a maven project based on archetype, you need to give the following command:
mvn archetype:generate

• Following archetypes are provided by maven:

Archetype ArtifactIds Description
maven-archetype-archetype An archetype which contains a sample archetype.
maven-archetype-j2ee-simple An archetype which contains a simplifed sample J2EE application.
maven-archetype-mojo An archetype which contains a sample a sample Maven plugin.
maven-archetype-plugin An archetype which contains a sample Maven plugin.
maven-archetype-plugin-site An archetype which contains a sample Maven plugin site.
maven-archetype-portlet An archetype which contains a sample JSR-268 Portlet.
maven-archetype-quickstart An archetype which contains a sample Maven project.
maven-archetype-simple An archetype which contains a simple Maven project.
maven-archetype-site An archetype which contains a sample Maven site which demonstrates some of the supported document types like APT, XDoc, and FML and demonstrates how to i18n your site.
maven-archetype-site-simple An archetype which contains a sample Maven site.
maven-archetype-webapp An archetype which contains a sample Maven Webapp project.

• Archetypes are packaged up in a JAR and they consist of the archetype metadata which describes the contents of archetype and a set of velocity templates which make up the prototype project. Archetype contents are as follows:
a) an archetype descriptor (archetype.xml in directory: src/main/resources/META-INF/maven/). It lists all the files that will be contained in the archetype and categorizes them so they can be processed correctly by the archetype generation mechanism.
b) the prototype files that are copied by the archetype plugin (directory: src/main/resources/archetype-resources/)
c) the prototype pom (pom.xml in: src/main/resources/archetype-resources)
d) a pom for the archetype (pom.xml in the archetype’s root directory).
See guide for creating archetype descriptors here for more information.
3) Build Lifecycle & Build Phases – Maven is based on concept of build lifecycle. This allows one to have a clearly defined process for building and distributing a particular artifact.

• There are three build lifecycles- default, clean and site. Default lifecycle is for handling project deployment, clean handles project cleanup and site handles the creation of project’s site documentation.
• Each of these lifecycles is made up of build phases. The build phase represents a stage in the lifecycle. eg. the default lifecycle is made up of following phases:

a) validate – validate the project is correct and all necessary information is available
b) compile – compile the source code of the project
c) test – test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
d) package – take the compiled code and package it in its distributable format, such as a JAR.
e) integration-test – process and deploy the package if necessary into an environment where integration tests can be run
f) verify – run any checks to verify the package is valid and meets quality criteria
g) install – install the package into the local repository, for use as a dependency in other projects locally
h) deploy – done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
These phases (and other phases in clean and site phases) would be run sequentially. For example, if the following maven command is issued:
mvn compile
maven would do every build phase prior to compile before compile it (namely validate).
• A build phase is further made up of goals. Even though it may be responsible for a specific step in the build lifecycle, the manner in which it carries those responsibilities varies. This is achieved by declaring the goals bound to these build phases. A goal represents a specific task (finer than a build phase) which contributes to the building and managing of a project. It may be bound to zero or more build phases. A goal not bound to any build phase could be executed outside of the build lifecycle by direct invocation.

Introductory AOP (Aspect Oriented Programming)

I wrote this piece as part of my work….

Aspect Oriented Programming is one of the programming paradigms where secondary or supporting functions are separated from the main business logic. The major objective is to increase the modularity by separating the secondary functionalities as crosscutting concerns. The main driving force behind the AOP was Gregor Kiczales, who worked on AOP at Xerox Palo Alto Research Center (PARC) and developed AspectJ which is one of the most popular AOP packages available today.
Basic Concepts
The basic concepts involved in Aspect Oriented Programming are:
1) Cross Cutting Concern: This refers to the secondary functionality which needs to be separated from the main business logic. For example, logging needs to be performed by classes in our data access layer and also by classes within our UI layer. Even though the major functionality of classes in UI and data access layer is separate but the secondary concern (i.e. logging) is common to both. So, in this case logging functionality forms a cross-cutting concern (term cross-cutting is used as the functionality needs to be implemented in such a way that it cuts across the main functionality).
2) Advice: The additional code that needs to be implemented whenever a cross cutting concern is involved. For example, this can be the logging code which needs to be implemented.
3) Pointcut: The point of execution in the application where cross cutting concern needs to be applied. For example, pointcut is reached when we need to log information before entering a method and we need to log information after exiting out of method.
4) Aspect: Aspect is simply a combination of the pointcut and advice. So, if we continue with our logging example, then logging aspect involves the advice (logging code to be implemented) and pointcut (point where we need to execute our advice).
Support for AOP
AOP is supported by variety of frameworks, platforms and languages. As of now, nearly every major J2EE platform (JBOSS, Spring, Weblogic, Websphere) is supporting AOP. AspectJ and AspectWerkz are two most popular packages available for AOP for use with Java. Moving apart from Java/J2EE world, AOP is also supported by .NET framework (both C# and VB.NET), C, C++, Perl, Python etc.
Implementation
AOP can be implemented via a process called weaving, which involves the use of an aspect weaver reading the aspect oriented code and weaving it (or simply put as generating) appropriate object-oriented code with all the aspects integrated. The weaving methodology is language independent and the only factors which govern the choice of weaving are 1) implementation and 2) ease of deployment. Weaving process can be done in two ways:
1) Source-level weaving: Source level weaving can be implemented using preprocessors having access to modify source code files. For example, in case of Java programming language, source level weaving can be performed via bytecode weavers which can work directly on compiled .class files. Bytecode weavers can work during codebuild, or during class loading. However, this approach causes problems as some of the third party decompilers or debuggers are unable to process the woven code as they understand the code generated by Java compiler rather than the one generated by the aspect weaver. AspectJ uses source-level weaving to generated aspect oriented code.
2) Deploy-time weaving: In order to avoid the problem associated with source-level weaving, deploy-time weaving use post processing whereby instead of modifying the existing code, we subclass existing classes and any modification is carried out via method overriding. The existing code thus remains untouched. This approach is commonly implemented in Java EE application servers, such as Websphere by IBM.
Problems with AOP
The use of AOP involves proper understanding of crosscutting concerns which sometimes can be a difficult task involving clear knowledge of static as well as dynamic flow of a program. If a developer commits any logical error while implementing crosscutting, the effect may be widespread. Also, if joinpoints are modified again it might lead to breakdown across the application.

Spring Integration: Basic Fundamentals

Looking into spring integration for quite a while now.

Spring Integration is a project of SpringSource(duh). The major aim of Spring Integration is to apply the Spring’s core programming model (IoC et.al) into the messaging domain.

The main components of Spring Integration are:

1) Message: It is a generic wrapper for any Java object combined with the metadata to be used by the framework to handle that object. The message is further consisting of header and payload. Payload can be of any type(basically a Java object) and header is for holding the information required for the message to be processed.

2) Message Channel: Message Channel forms the mode of communication between the message producer and consumer. It decouples the message production logic from the message consuming logic. The key point to be noted is that the message channel supports both Point-to-Point and Publish-Subscribe models (for the uninitiated, Point-to-Point model basically means a message has only one consumer processing it even though other consumers might also exist for the same message and Publish-subscribe model basically means a message has multiple consumers processing it simultaneously. To summarize, Point-to-point is unicasting the message whereas Publish-subscribe is broadcasting it). Another important point to be noted here is that while these two models describe how many consumers would ultimately process the message, Spring Integration also allows you whether to have message channel to buffer messages or not. This is important in the scenarios where it might be prudent not to overload the consumer with the messages.

3) Message Endpoint: Message endpoint connects the message and the application code in a non invasive manner. In other words, application code and message need not know the implementation details of each other.

Instant Noodle aka Instant Google!

As most of us have come to peace with the latest ripple(sorry wave ain’t news anymore) on the world wide web caused by no other than google, it is time to analyse the new offering!

What is it?
An approach that takes away the mice and directly displays search results as alphabets are typed.

Any similar things exists before?
Absolutely Yes. Any regular KDE user knows what happens when Alt-F2 is pressed.

Is it any worth?
Yup! It was fun using it for two days. But don’t know how long it lasts.The good thing is that the mice has been pushed away one step more.

Any Gotcha’s?
As with any ajax application, browser button behaviour is unpredictable.You might not see actually things on the screen, but your request has everything.
Also earlier, for a search text only a single hit was required to the google servers, now every alphabet invokes a new hit.Get ready to leak unnecessary bandwith data.
Google really has some strong servers to take the toll of every search query to around 5-7 times!

The official post is here.

Cut Rubies With Ease.. Through RVM!

I have been out of touch with Ruby for quite a long time now, all thanks to my pathetic job!

In the meanwhile a lot of things have happened, like Ruby1.9.2 is finally out, and along came the even more awaited Rails 3.0

So, last weekend I made up my mind to take the plunge and set off to setup everything up and running. But as soon as I learned that my distro still doesn’t have the pkgs of the latest ruby and rubygems, I almost stopped dead in my tracks..

But then I found about RVM and everything changed. Yes.. RVM as you might have guessed is a Ruby Version Manager. RVM doesn’t work like any other pkg, its tightly integrated with the shell you use.

RVM empowers you to install and use multiple versions of ruby at the same time.
$rvm install [ruby version]

You can switch to different ruby versions, just like that..
$rvm [ruby version]

You can set a default ruby version to use whenever you open a shell
$rvm –default [ruby version]

RVM also enables you to easily manage all your gems specific to different versions of ruby.

RVM saved the day for me, and it can do it for you. For more info on RVM, checkout this link – http://rvm.beginrescueend.com/

Maven and Proxy scripts

This friday at work, I was configuring a new system for project use.
The transition to a newer LAN was fun but what was more challenging and a little less-fun the configuration of maven for some spikes.

I was supposed to get working on spring-webflow and for that I had to get a maven controlled project up and running.

In this I faced the challenge of getting maven past the proxy settings and it being able to download all/any dependencies as required.
I had earlier, on a previous LAN setup, known the proxy server and port number and configuring the settings.xml for the same was not at all tough.
This time, our LAN is configured via some asp scripts residing at a server, so I did the following to get maven talking to the internet.

1/Go the script hosting the proxy script.
2/Download and study the proxy script, find the final else-if case for identifying the actual proxy server and port.
3/Put my user name alongwith *domain* and put it in the settings.xml[this was the part that took longest amount of time to find]

And maven got to see the light of the internet!

It is important to note that maven does not support NTLM authentication(I assume this was the problem) although there are tools(cntlm), which I tried working for 5-10 minutes but did not get through.

The missing software oath!

We as software creators, affect lives of everyone.
Be it a lawyer/doctor/government/police/reporters and what not.
All of them have an oath they take acknowledging with their conscious the work they are supposed to do would be done with best spirits and with best intentions.
Although at the ground, it might not be true but atleast as a ceremony they have something to swear by!

Coming to the profession(an occupation requiring special knowledge) of software development and related works, we do have no such promises to make or oaths(commitment to tell the truth!) to take!

Maybe all related software professionals are assumed to lie or are assumed to be true.
If we all are liars, then we might not have his wonderful profession, as good things rest on good souls and get bad name from a few unfortunate few.

What place do you belong?

Book Read : The Practice of Programming

Phew!
I read a book. Complete. End to End.
It is in my morning travel time, thanks to the 17 kilometers I need to travel everyday one side, increasing my carbon footprint(or is it natural gas?), that I have started to devote time to reading.

Motivation:
I have access to a library that boasts of some timeless titles.

I can quote just one part from the book that I really liked.It refers to the ways of Debugging-Explain your code to someone else.
It states:
“One university computer center kept a teddy bear near the help desk. Students with mysterious bugs were required to explain them to the bear before they could speak to a human counselor.”

These precious gems are already jotted down by someone who likes this book here.

What I would want to put across here is the quote which the authors have chosen to convey the essence of each chapters:

Chapter 1 : Style

It is an old observation that the best writers sometimes disregard the rules of the rhetoric. When they do so, however, the reader will usually find in the sentence some compensating merit, attained at the cof violation. Unless he is certain of doing as well, he will probably do best to follow the rules.

-William Strunk and E. B. White, The Elements of Style.

Chapter 2: Algorithms and Data Structures

In the end, only familiarity with the tools and techniques of the field will provide the right solution for a particular problem, and only a certain amount of experience will provide consistently professional results.

-Raymond Fielding, The Technique of Special Effects Cinematography.

Chapter 3: Design and Implementation


Show me your flowcharts and conceal your tables, and I shall continue to be mystified.
Show me your tables, and I won’t usually need your flowcharts; they’ll be obvious

-Frederick P. Brooks, Jr., The Mythical Man Month.

Chapter 4: Interface

Before I built a wall I’d ask to know
What I was walling in or walling out,
And to whom I was like to give offense.
Something there is that doesn’t love a wall,
That wants it down.

-Robert Frost, Mending Wall.

Chapter 5: Debugging

bug.
b. A defect or fault in a machine, plan, or the like. orig. U.S.
1889 Pall Mall Gaz. 11 Mar. 1/1 Mr. Edison, I was informed, had been up for the two previous nights discovering ‘a bug’ i his photograph–an expression for solving a difficulty, and implying that some imaginary insect has secreted itself inside and is causing all the trouble.

Oxford English Dictionary, 2nd Edition.

Chapter 6: Testing

In ordinary computational practice by hand or by desk machines, it is the custom to check every step of the computation and, when as error s found, to localize it by backward process starting from the first point where the error is noted.

-Norbert Wiener, Cybernetics.

Chapter 7: Performance

His promises were, as he then as, mighty;
But his performance, as he is now, nothing.

Shakespeare, King Henry VIII.

Chapter 8: Portability

Finally standardization, like convention, can be another manifestation of the strong order. But unlike convention it has been accepted in Modern architecture as an enriching product of our technology, yet dreaded for its potential domination and brutality.

-Robert Venturi, Complexity and Contradiction in Architecture.

Chapter 9: Notation.

Perhaps of all the creations of man language is the most astonishing.

-Giles Lytton Strachey, Words and Poetry.

No doubt, the book needs to be read again atleast twice to imbibe by its sayings.
A similar java specific list can be found from Effective Java.

This is something to get used to and keep with oneself always.
~rohit.

ReverseLogic ~ Making Ends Meet!