Tuesday, April 12, 2011

ASSEMBLED: Why don't we get custom cars?

With so many innovations happening around us, especially in the field of computer sciences, why is it that we still have no clear and complete knowledge of the things we use everyday. Take for example, the Car. How many of us actually know what composes a car and what to do when something goes wrong?!

Despite the fact that we have so many things around us about which we do not have a complete understanding, I am going to concentrate on the cars. We use our cars and bikes everyday! At least, back here in India, one in 2 houses has a car or a bike. Yet only 1 in 1000 people know about what a car is made of. Fewer still, only 1 in 100000 really know what each internal part of a car does. When it comes to fixing a car, the ratio is much much smaller. I am not providing an exact ratio or even an approximate ratio but you would understand yourself that the ratio that I have chosen is not too absurd either.

What is the reason for so much disparity?! Well, I believe that this is because there are still many domains about which we do not share information! Look at the Internet, look at the domain of computer sciences! Do you ever feel the need to buy books on programming languages or database systems?!

No.

Why!?

Cos most of the information and tutorial that you need is available on the Internet. The literature on Computer Sciences has been made available anywhere and everywhere. So much so that assembled desktops are now the most sought after product and most desktop owners can now assemble their own desktops. Not just assemble, but also customize; both in looks and performance.

Its not just the Computer Sciences domain that has easily accessible information. There are many such domains. A few that I know of are

The Polymath Project: a massively collaborative environment for the study and research of sciences, especially that of mathematics.
(http://polymathprojects.org/)

The Human Genome project: a project with completely open data access and with legal backing which states that if you have to work on the human genome, you have to agree to abide by certain principles. Principles that state that whatever find you make, must be available in the public domain. And so, GenBank was born.

When such domains can exist, can a domain exist for the study and research of the automotive technology? We do have a forum where discussions of many sorts happen on cars and other automobiles: TeamBHP. But why is there an absence of a portal to learn about your beautiful car or your not-so-beautiful car. A Wikipedia kind of domain completely dedicated to the technology of automobiles so that you will be equipped to learn and control and custom your ride. Do throw in your opinion.

Monday, January 24, 2011

Public or Private or Protected: The trouble with access specifiers!

The object-oriented paradigm introduces a new concept towards accessing variables using, what are called, access specifiers. All of you who had been introduced to the OOP (Object Oriented Programming) paradigm, would definitely have heard and used these access specifiers. There are, in general, 3 levels of access specifiers in OO languages: public, protected and private.

Many new learners of the object-oriented paradigm often get confused by the purpose of these access specifiers, especially when it comes to assigning access specifiers to variables. Most literature on this explain the existence of these access specifiers as providing secure access to these variables. But what kind of security are they talking about?!! They simply use the abstract term security without ever mentioning why this security is required or how this security is helpful.

Here I try to explain one of those cases where the use of these access specifiers is very handy and definitely provides, what is called, security. Please leave a comment if you know of any other scenarios where access specifiers are helpful.

Say I have a class called Person, which has a variable that stores a value for the age of a person
class Person {
    .........................
    unsigned int age;
    .........................
    .........................
};
Now there are 2 ways to access this variable, age. One is using the dot(.) notation and the other is via some functions (called the getter/setter functions).

Case 1: If I happen to declare this variable with public scope, then I can access this variable directly using the dot(.) notation. Let assume that in my application I create an object of this class and I name it obj. Then I can read the age of a person into another vairable var by a simple statement:
var = obj.age;
and I can set the age to a new value using the statement:
obj.age = 20;

Case 2: If I happen to declare this variable with private or protected scope, then I cannot access this variable in the fashion show above. I would have to use member functions of the Person class to read or write values to this age variable. These functions are called getter/setter functions in the OOP paradigm.
Lets say, I have declared 2 such functions:
/* The setter function for the age member variable */
public void setAge(unsigned int age) {
    this.age = age;
}
/* The getter function for the age member variable */
public unsigned int getAge() {
    return (this.age);
}
Then I can read the age of a person into another vairable var by using the statement:
var = obj.getAge();
and I can set the age to a new value using the statement:
obj.setAge(20);

Now that these 2 cases have been established, its time to decide when to use either of these cases. This is often a confusion among beginners, who generally always stick to one of the access specifiers without giving a thought to the logic and the different scenarios that their logic would have to deal with.

Here I am going to discuss one of the scenarios, in short.

Consider a system which maintains a record of everything you have done so far since the minute of your birth (Scary isn't it!? :) and in such a system, while entering some information, lets say that the age has to be specified and the form does not have validation code programmed into it. Then, if I accidentally enter 1000 (which is unthinkable right now except if you are HanCOCK), this method would set the age to 1000 without any fuss in both the cases (described above). But this is wrong! We need to validate the value for age before it is saved but there is also a restriction that this validation cannot be written in the form code. So what do you do!?

This is where the implementation of Case 2 comes into play. Here you can program the validations in the setAge(unsigned int age) function just before saving the value in the variable. So now our setAge(unsigned int age) function would look more or less like:
public void setAge(unsigned int age) {
    if (age <= 100) {
    // Considering the biological maximum age of humans
        this.age = age;
    }
}
This is just a simple validation. More complex validations can be added depending on the logic that is to be implemented. The advantage of programming the validation within the setter function is that we can club together the validations and the operation (in this case its an assignment) together without having to touch each and every piece of code where ever this assignment is made.

But this explanation should not serve as a support for tagging all variables under the private or protected access. Always remember that an assignment via a function call is always slower than a direct assignment. Use the dot(.) notation access (otherwise called public scope access) when the variable does not control any critical logic. For example, a system where a variable is required to store the latest warning or error message, among a series of messages just before the exception is thrown, can very well have the variable, that stores this error message, with public access and used with the dot notation.

And a very important thing is that these access specifiers are applicable only to variables within a class!!!

Monday, March 2, 2009

VLC player stuttering on Fedora 10

My God! What an annoying day this was... I happily installed my favorite player (VLC) on fedora 10 after just having completed my Fedora 10 installation and before I could relax on some glorious music from Rock On!!!, VLC started choking on fur-balls like a cat. It totally screwed me out but after about 10 minutes, I found Silpheed2k on fedoraforum.org (well not actually found him, just his post) and here is what he had posted...

These 3 simple steps:
  1. open a terminal and run the following command: gedit /etc/pulse/default.pa
    add tsched=0 to the line: load-module module-hal-detect
    so this line would look like: load-module module-hal-detect tsched=0
    (don't forget to save your changes)



  2. now install the following packages:
    pavucontrol pavumeter paman padevchooser paprefs alsa-plugins-pulseaudio gstreamer-plugins-pulse pulseaudio pulseaudio-core-libs pulseaudio-esound-compat pulseaudio-libs pulseaudio-libs-glib2 pulseaudio-libs-zeroconf pulseaudio-module-gconf pulseaudio-module-x11 pulseaudio-module-zeroconf pulseaudio-utils xine-lib-pulseaudio xmms-pulse

    (for the absolutely naive user to install the above packages run the command:
    yum install pavucontrol pavumeter paman padevchooser paprefs alsa-plugins-pulseaudio gstreamer-plugins-pulse pulseaudio pulseaudio-core-libs pulseaudio-esound-compat pulseaudio-libs pulseaudio-libs-glib2 pulseaudio-libs-zeroconf pulseaudio-module-gconf pulseaudio-module-x11 pulseaudio-module-zeroconf pulseaudio-utils xine-lib-pulseaudio xmms-pulse)


  3. and finally run the following command (make sure that you do not have root privileges when you run this command): pulseaudio -k



Done! Now your VLC would run perfectly. At least, it did so for me! In case you do find better solutions, please feel free to comment...

Thursday, December 25, 2008

Can my waiter truly calculate my age? Here is the trick behind it

I got this *magic for the year 2008* in my mailboxes so I thought I would share the secrets behind this magic trick flying around people's mailboxes.

Here is the original puzzle moving around on the internet that promises to calculate your age from the number of times you like to eat out at some place.

//////////////////////////////////////////////////////////////////////////////
YOUR AGE BY EATING OUT

Don't tell me your age; you probably would lie-but your waiter may know!

YOUR AGE BY DINER & RESTAURANT MATH……….
---------------------------------------

This is pretty neat

DON'T CHEAT BY SCROLLING DOWN FIRST!

It takes less than a minute. Take a paper & pen and Work this out as you read .

Be sure you don't read the bottom until you've worked it out!

This is not one of those waste of time things, it's fun.

1. First of all, pick the number of times a week that you would like to go out to eat. (more than once but less than 10)

2. Multiply this number by 2 (just to be bold)

3. Add 5

4. Multiply it by 50

5. If you have already had your birthday this year add 1758... If you haven't, add 1757.

6. Now subtract the four digit year that you were born.

You should have a three digit number. The first digit of this was your original number. (I.e., How many times you want to go out to restaurants in a week.)

The next two numbers are YOUR AGE ! ------ (Oh YES, it is!)

THIS IS THE ONLY YEAR (2008) IT WILL EVER WORK,

SO SPREAD IT AROUND WHILE IT LASTS……….
////////////////////////////////////////////////////////////////

Amazed by the results? Well to be true this trick can be tried any year by just increasing the number to be subtracted at step 5 as a year goes by...

Here is how I worked out the solution...

I chose the number of times that I would like to eat outside as 3 and my birth year is 1987. Here I go

1. 3
2. 3 * 2
3. (3 * 2) + 5
4. ((3 * 2) + 5) * 50
--------> (3 * 2) * 50 + 250
--------> 3 * 100 + 250
5. 300 + 250 + 1758
(the number of times that I like to eat outside (3) is shifted two places to the left cos of this step)
6. 300 + 250 + 1758 - 1987
(pay close attention to this part [250 + 1758 - 1987] cos here 250 + 1758 give you 2008 and subtracting 1987 from 2008 is obviously going to give me my age... duh!!)

So the final answer is 300 + 21 and you get the magic that this trick claims to put up.

The other lie that this trick imposes on us is that this magic will work only for this year... But if a bit of logic is applied, I say anyone who is born after 1758 can use this trick. All he has to do is change the number in step 5 appropriately... So if I want to calculate my age using this trick next year, I just add 1759 (if I plan to calculate after my birthday has passed) instead of 1758 in step 5. The problem here is that this trick wont work for people who are above 100 years old cos the hundredth place holds the number representing the number of times you eat outside. Try it!

Steps 2, 3 and 4 ensure that the number of times that you eat outside is shifted two places to the left by multiplying it with 100...

More to come if you enjoyed this...

Sunday, August 17, 2008

Synaptics Touchpad problem in Linux

I just got my laptop, my brand new DELL XPS M1530 preloaded with Windows Vista Home Edition. As soon as I opened it, I installed a partition manager and created revelant partitions to install Fedora. Now comes the part that had me confused for a whole 24 hour (no sleep).

Installating Fedora 9 was fine with the touchpad functioning except for the tapping click functionality that all touchpads have inbuilt. However, that did not bother me cos I hate the tapping click option anyway. Installation over, system reboots into Fedora and BOOM! The touchpad is dead. When I tried to play with it a bit, it started running around the screen as if it had never been so happy to see me, making a right-click and a left-click wherever it liked to. May be it was playing the "catch me if you can" game?!

After working for 4 days to figure out the problem, I still failed to obtain a solution. Above all I did not even have a USB mouse and this made be go back to the stone age of GUI computing --- typing commands and using the tab key to navigate though the GUI elements.

Tonight may be the sleep fairy ignored me and spared me the entire night which is when I embarked on a kind of campaign to surely find the solution. After a strenuous 4 hour search starting at 11 PM local time, I started to understand the problem and finally found the solution.

The Solution:

I tried many suggestion posted on various forums: primarily LinuxQuestions.org, FedoraForum.org and UbuntuForums.org. However, for my case the answer lay in UbuntuForums.org which stated that I change the grub.conf to add another kernel option i8042.nomux=1 and it worked on reboot. I still have not figured out the purpose of this kernel option and how it works. But once I do get to know its purpose, I will put it up in here.

So for now, as far as my understanding goes, add the kernel option i8042.nomux=1

As information on the purpose of this kernel option would be really appreciated.