Saturday, December 29, 2012

Why using single alphanumeric for status code is a bad idea.


This screen uses A as approved for status code. That screen uses A in status for something else (e.g. archived, arrived and some even not start with such as Invoiced). Let's not get into numeric because it gets even worst. My thought of this is that developer / analyst just too lazy to add another character to clarify things a bit more.

Why can't just put two or more characters to make the status code more meaningful and unique between screen? Example: AP = Approve, AR = Archived, AV = Arrived. Maybe the screen doesn't have enough space to fit another character or there is just too much typing, either case, I still believe clarity comes first.

Nevertheless, for developer / analyst, please avoid using single character for status code (especially the same code used in different screen) in application design / development and help create a more user friendly world. That will make the world a better place to live, at least for me. Thanks. ;)

Saturday, November 10, 2012

Oracle cursor exit can be better

I read a linkedin discussion on the cursor where if the cursor %NOTFOUND statement is place after the processing statement, the result will printed the last fetch twice. Example from the discussion below:

DECLARE
I EMPLOYEES.FIRST_NAME%TYPE;
J EMPLOYEES.SALARY%TYPE;

CURSOR C1

IS
SELECT FIRST_NAME,SALARY
FROM EMPLOYEES
WHERE EMPLOYEE_ID BETWEEN 100 AND 105;

BEGIN


OPEN C1;

LOOP
FETCH C1 INTO I,J;
DBMS_OUTPUT.PUT_LINE(I||' SALARY IS '|| J);
EXIT WHEN C1%NOTFOUND;
END LOOP;
CLOSE C1;
END;
/


The correct way was to put the %NOTFOUND a line after the FETCH cursor so the %NOTFOUND statement can be validated straight away after the FETCH statement. Example:

OPEN C1;
LOOP
FETCH C1 INTO I,J;

EXIT WHEN C1%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(I||' SALARY IS '|| J);
END LOOP;
CLOSE C1;
END;


Then it puzzled me. Why there is need for an extra line of EXIT WHEN C1%NOTFOUND which can caused potential bug and confusion? Since it's related to the fetch statement, why not oracle put them together as an option? Example:

My idea, not oracle actual code
OPEN C1;
LOOP
FETCH C1 INTO I,J
EXIT WHEN C1%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(I||' SALARY IS '|| J);
END LOOP;
CLOSE C1;
END;


This way it causes less confusion and less bug prone.

Well, it just an idea.

Reference
Linkedin Discussion - Hi one small doubt

Saturday, November 3, 2012

Fan noise in AMD APU chip for Ubuntu 12.04

I have installed Ubuntu (Wubi option) on my laptop with AMD APU chip (A6-4400m with internal 7520 GPU and dedicated 7670m GPU). Lately, I have been experiencing loud fan noise but it was normal when I was using Windows 7. I suspected that it may be a bug in Ubuntu that caused high usage of CPU resources. However, the processes monitor did not show high CPU hogging caused by applications. Then I realized that it was the GPU that made all the noise.

After couple of tries in updating the proprietary driver and manual install AMD driver, finally I got the AMD catalyst  control installed and selected the power saving GPU option (including settting maximum battery saving in powerplay option). What the setting does was turning off the dedicated GPU, which is resources hogging and hence, the fan noise. After turning that off, Ubuntu uses the built in GPU the fan noise is gone. :)

Update 13/01/2013: I noticed the fan noise still exist even though I have switched off the dual graphic option. I checked the system monitor to investigate which application was hogging CPU resources and it turned out to be compiz, which mainly used for user interface 3Dd effect. From this discovery, I'm now using 2D option (At Ubuntu login, click on the Ubuntu logo just above the password field and choose 2D option) in order to turn off the compiz feature. Anyway, I'll monitor whether this will help to reduce the fan noise and CPU hogging for couple of weeks.

Update 01/11/2015: After a couple of attempts, I finally switched to Xubuntu with the minimal user interface that solve the cpu hogging isuse.

Links
https://help.ubuntu.com/community/BinaryDriverHowto/ATI

Saturday, October 20, 2012

How to update swype beta in ICS?

I have tried more than 10 times to update my swype beta on my Galaxy Nexus running ICS but it always stuck. The swype connect just won't download the update. After checking the news from lifehacker where there is a new version release:

http://lifehacker.com/5953131/swype-beta-adds-cross+device-dictionary-sync-hotwords-and-swype-for-tablets

I tried to manual update the keyboard. Here is the steps:

  1. Make sure the swype beta installer is the latest version. (1.3, http://beta.swype.com/)
  2. Uninstall the swype keyboard from phone. Please note that uninstall the keyboard will erase the personal dictionary. However, I find that to build up my dictionary was easy so I go ahead instead.
  3. After old swype keyboard is removed, run the swype beta installer and download the keyboard again.
That's it and it works. There are more keyboard theme to choose and personal dictionary sync to cloud feature. I don't know how frequent the sync will be and I guess it may eat up my battery. So, I turn it off and choose to sync it manually.

Friday, June 8, 2012

Last day at work

My family and I are migrating to Australia. It was sad that I have to leave my colleague and the job I loved here - and move on to another country. Nevertheless, I was still working till the last drop today. My colleague was embarrassed to seek my advise and guidance although by now they should be able to pick up the work with their own. Some even says to call/email me for support while I'm still in Malaysia for another 2 weeks, before taking the late flight to Australia. :D

My heart wanted to stay with this company and grow with them but my mind wanted to go. Everyone understands that family commitment comes first and it was unfortunate that I have to leave after working just one and half years with this company.

After sending the thank-you-and-goodbye email, hand over the remaining work to my boss and finally a photo session, I picked up my stuff heavy hearted and have a final cigarette moment with my new boss before leaving (although I'm just a casual smoker).

I wished them all the best in their career and I hope the same for me when I start my new life in Australia.

P.s. Never thought of life can be rebooted but now I can see one coming. :P

Wednesday, April 11, 2012

Do we need cartesian join?

I have written so many SQL script and non of them requires cartesian join based on business requirement. I have seen union, left and right join. Cartesian join? No where in sight.

However, the cartesian join was found in mistake where developer has forgotten to put in the necessary join condition between the tables. This has caused the query to join all the rows from each other and resources has been wasted due to this mistake.

My questions for this join in database system as follows:
  1. Why the database system allows cartesian join since it was not used most of the time? 
  2. Why can't cartesian join be required to specify in the SQL script such as union, left or right join? 
  3. Why can't the database system alert  (an error will be sufficient) the developer that one specific table has no relationship or filter defined and therefore, the table is no longer required?
My guess on the 3rd point is that it was too complex to write the logic to catch cartesian join. Perhaps there are tools out there that providing this feature. However,  I do hope in future database system, all cartesian join should be required to specify in the query.

Thursday, March 22, 2012

Use AND, OR in IF statement if they are related.

Kinda simple isn't it? However, in my working experience I saw people using IF for no apparent reason. Example of a simple and easy to understand IF statement:

If start_date = 31/12/9999 then start_date := sysdate; end if;
If end_date = 31/12/9999 then end_date := sysdate; end if;

Very straight forward. Set the default date to sysdate if value is found as 31/12/9999 for start_date and end_date.

Then I saw people turn the above if into something below

if start_date = 31/12/9999 and end_date = 31/12/9999 then

start_date := sysdate;
end_date := start_date;

end if;

There are nothing wrong with the IF statement until I asked the question:

Are start_date and end_date are related? Why do they have AND relationship?

Then the developer provided a lot of explanation where all boils down to less keystroke (are they?)

In short, the AND or OR in IF statement always represent a relation that can't be ignore by asking question like below:

Are they related (changing one would affect the other)? Why do they have AND/OR relationship?

Probably there is no need of AND or OR if the above question can't be answered. Furthermore, the downside is just more keystrokes for a complete IF statement.

P.S. Changing the AND to OR in the IF statement will cause more problems.

Monday, March 5, 2012

RIP "select value into variable from dual" in PL/SQL world.

I got an email on the other day that "select value into variable from dual" will be fully retired from pl/sql script. Well, it's understandable how it get there it the first place.

Initially, SQL script has created and run using the sql plus environment. In order to create and assign a value to variable, "execute select value into variable from dual" is commonly used. There's nothing wrong with it and it always get the job done. Until a new system came along and developer is able to use procedures and functions. However, old habit is hard to die when the developers migrated the old script to new system, they brought along the "select value into variable from dual" with them.

Well, I can't blame them as there are thousand of scripts to be migrated and time wasn't on their side. Now, with almost everything gone into the system, they finally realized that "select value into variable from dual" wasn't efficient and DBA wasn't too happy when they saw so many "select value into variable from dual" pop up in their screen. In the end, developers have to clean up the mess one by one and changing the script using "variable := value;" instead.

RIP "select value into variable from dual". We gonna missed you. :P

Tuesday, February 21, 2012

Please don't abuse DISTINCT.

Usually the analyst provide the specification book to me develop the report. Of course the analyst has the idea what to expect on the outcome along with the filters specified. However, when it comes to analyst has no idea what they should be expecting and if they found duplicate in the report, what they'll advise is to applied DISTINCT.

I could understand that applying DISTINCT is the fastest way to solve the problem but it will increase the database execution cost. The solution might have hidden in one of the unique field or certain combination of filters applied but will take much effort to discover, especially for complex SQL.

Well, let see how far DISTINCT could help us until one day it might finally gives up.