Thursday, June 11, 2009

Java methods and declared return type

Guess the output:

May seem straight forward to Java Geeks.



I thought this would give compile time error. Later on realized the output is

This is funny

Moral: It is possible for a method to have a declared return type and yet contain no return statements.

Saturday, March 28, 2009

Being a Green Programmer

I know:

  • You are busy coding.
  • You are working on p1.
  • Your Manager wants to meet you in 10 minutes and already 1 min is gone reading till here.

For those whose vocation is Programming and you always have the above excuses or hand-cuffs and even then you want to be Eco-Friendly, glance at the titles and pictures. The pictures are dedicated to you.



For all others, I promise it is worth reading and I recommend to follow at least one.

Who is a Green Programmer?

All those people whose job is Ctrl+c, Ctrl+v (I know there is a lot more) and who have already realized that the Beautiful Earth is in danger and are desperate to contribute and follow a set of Eco-friendly rules, are already Green Programmers. The level is based on the number of rules you follow and the number of people you educate. The other synonym is Eco-Friendly Programmers.



Why should I become a Green Programmer?



Global warming, Acid Rain, Pollution, Hazardous waste, Ozone Depletion, etc. These terms are now more practical and live. By becoming a Green programmer, you are first aware of the cause and consequences; and then aware and follow the ways to reduce them.

How to become a Green Programmer?

Apart from following the best practices for programming, there is a simple set of Eco-Friendly practices, which needs a little extra effort. There are a few easy and basic rules defined in this blog and the rest is common sense.

If you have understood till now, you are already a Green Programmer.

Being the Green Programmer:

I asked a question in stackoverflow, "How to be an Eco-friendly programmer?" and I am going to use few of the answers here. For those answers that I got from stackoverflow, Notation is Answer:.

  1. Efficient Programming:



    If you have effective code running in production, you are already contributing to the Environment. Answer: "If your software is widely used, write decent code. Shaving 30 seconds off that image stabilization code saves 30 secs of computer time, every time it is executed (30 secs * 10000 execs/day * 30 days = 104 days of saved computing time). That's far more energy than you'll ever save personally."
    Try to complete all the tasks ahead of the schedule so that you don't have to do over time thus reducing the power consumption.

  2. Turn your stuff off:



    In a day, actual work, code, checking mails takes 6-8 hours and most of the systems remain switched on even after that because of
    a short break: coffee break, lunch break, Meeting, long phone calls. In such spans, Just switch off the monitors.
    or a long break: EOD, weekend. In such cases do shut down the machine and switch off the monitor. And for programmers, the desktop is in Schrodinger's cat state most of the time, it is better to hibernate.



    This means that if the machines are switched off after use, the power usage is only one-third.
    Apart from these,
    - Turn-off the mp3 players, i-pods, etc when not in use and switch off the lights, AC, fans while leaving.
    - Activate the Eco-functions of your computer, make it turn off the screen after a few minutes and go in stand by after a few more.
    - Use an empty screen saver.

  3. Remember Paper Comes from Tree:



    - Try using e-books, online materials, white boards.
    - Use a ceramic cup instead of paper cups.
    - Hand dryers and kerchiefs are better than paper towels.
    - Don't burn waste papers. Recycle.

    For those who work on report generation, Answer:
    "If you write software that generates reports try to:
    - minimize the unused space on a page (use two columns, etc.)
    - remove superfluous information or graphics (fancy headings ...)
    - allow the user to select the wanted information (print only what you need)

    This will reduce paper and toner (or ink) usage on the client side. If your client prints a lot of your software's reports, this will save much more paper than you can by cutting down your printer usage."

  4. Reuse, Reduce, Recycle:



    The advantages of reusable code for programmers is obvious.
    - Share the book that you have, let someone reuse it.
    - Share the common print outs.
    - Answer: "Buy an Aeron Chair. Not only because it's 94% recyclable; odds are you'll use it for a time span within which others would go through twenty (all destined for a local land fill). Extra Bonus: they are nice and comfy."
    - Don't upgrade your computer until you really need to. When you finally do, recycle your old computer, sell it, donate, or give it to an organization that disposes of computers responsibly.

  5. Telecommute, Cycle and Public Transport:



    Live close to work, the advantages are obvious. The only disadvantage may be, higher rents. If you are very far away from work place, try using Public Transport. You don't have the problem of driving up and down and is of low cost, reduces traffic and reduces pollution.

    - Telecommute whenever possible, Answer: "If you commute by car, work from home a couple of days a week if possible. You'll reduce your carbon output, and save a bit of money, too. I save ~£24 (~$34) a week (£1,248!) on diesel by working from home two days a week; that doesn't include car maintenance costs either. It's not insignificant. Plus, less traffic on the roads means less congestion which means free flowing traffic and thus much more efficient motoring for those who are on the roads."
    - Cycling has one more advantage of Good Health.


Activities:

  • Once a week, try using public transport or cycle.
  • Discuss on a tea break on the points that you follow and those you are planning to follow.
  • Try doing one activity a week and then it becomes a habit.

This is not over. There are a lot more that our common sense tells us everyday. Now what are you waiting for? Join hands with the other Green Programmers, follow and spread the word.





References:




Green Programmer

Tuesday, December 30, 2008

Limitations of the Present Search Engines

"Organize the World's Information and make it Universally accessible and useful" - Google.

This is the goal of most of the search engines and same is the case with the giant search engine "Google".



Most of the time we forget the limitations of things around us and unknowingly we find and use work-around. The same is true with the search engines that we use.

The problem:

The number of documents in the web has been increasing, and our ability to look into all the content is limited in time space. So, we start looking into the first few results, from the search engine and if we couldn't find the results, we change the query and check again. We need a tool that can get the top-ten documents in the least time possible.

Solution:

The tool is called search engine. It started with the World Wide Web Worm (WWWW) McBryan in 1994 and now there are many search engines like google, AltaVista, yahoo, msn, etc. The Limitations among these are common.

Limitations:

Let us start with an example. Suppose if we want to download jdk 1.4.2 from Sun Microsystems. We may give "download jdk 1.4.2 from sun" as the search String. We get a page full of results and we can click next, next .. till we don't know when it ends.

  1. The result is humongous and the precision is low. Not all the times we get what we want. For e.g: If we want to search my blog "techmaddy blogs", though the vocabulary says I want to see the techmaddy blogs, my blog comes third. The reason may be that my page ranking is bit higher. A few search engines couldn't even find it.
  2. Irrelevant results: Sometimes the results are irrelevant. Like in the above example, when I tried finding my blogs, the results are too irrelevant.
  3. Manual integration of data required. Most of the results are not processed. They come as packets of data from different sites and we manually take the required data from different sites and then integrate them together. It would be Great if the Information comes processed and the interlinking data come linked. For e.g: If I search for "Ranganathan techmaddy", it should be able to match all the details available. Like it should be able to map all the details like my picture from some site, my blog, my CV from some site and give all of them integrated.
  4. Invalid results: Suppose a new blog or site is written and published. Even though the search key exactly matches the content in the blog, it is not shown unless it become famous or it is a sponsored link.
  5. Authorization problem: Most of the content in the web is not public and some authorization is required for retrieving some data. Now, if I am logged in orkut and now I have authorization for the search. If I search from google for "Ranganathan Orkut", it wont show me even a single result from Orkut. Not even the link to Orkut.
  6. Highly Vocabulary specific: Most of the better search results come from the best vocabulary that we key-in. There are few better things like spell correction and auto-suggest. Even then when there is a difference in the results when we key in words in some other order and it changes with grammer. For e.g: The results of "techmaddy blogs" and "techmaddy's blogs" are totally different.
  7. Incorrect image results: When we type "apple" and search for it. The intention may be different. But, I could see some other pics other than apple. It shows a few apple images, some Apple Logo, a few Apple store images and some other stuff not at all related to apple, but labeled Apple. It would be better if we could see only apples. And if there are some images like a person holding an Apple. Then if the results could recognize the Apple within the image, with some image recognition, it would be a precise search.
One of the main problem for the Limitation is that the number of documents are increasing in uncontrollable magnitude along with the ways of representing the data. Html, xml, pdf, video files, images, etc. Apart from this there are misleading meta data. The newly released sites are not added to the indexing. A few sites manipulate the search engines for profit. Sponsored links cannot be avoided.

Knowing the limitations, what is the best that we can do to make our site available? Add a customized search for the site. Add the site to the indexing. Properly add meta data. Naming the images precisely. Use Semantic web.

When the web is organized, it is like a organized desk. Searching for a file in the desk will be pretty easy. Having said that a well organized web does not require a search engine. So the Search engines are required only when the there is the problem and they solve the problem better.