28 February 2010

Cerita hati

Assalamulaikum wbt..

Alhamdulillah, di pg y hening ni aku bleh ar gagahkn dri menulis blog berkat keizinan dri Allah s.w.t. After struggling plus few excitement but typical improvement on my inSpora Project, i finally decided to have a time with my self..Most of the time, being normal person is tougher than debugging codes.

Minggu depan dh masuk bulan 3, terigt plak kat detik htam dlm fmili aku bile mana umah aku t'bkar akibat perbuatan abg aku sndri..tido berselimutkan langit berlantaikan bumi..pnjag citernye. Aku rse kalu buat cerekarama nie konfem sumer org ngis xhenti..Aku kagum dgn mak n abah aku..Dorang mmpu hdapi tgapan org luar, ckap2 jiran n byk ar lgi y xmmpu aku nk hdapi sndri..Teringat lgi ms aku jinjing report kebakaran Bomba dri kedai ke kedai mintak simpati org, dgn baju y aku pki pn sbb org bg sdekah..Setiap kali aku trun ke KL n mkn kt kedai2 mamak, terasa sayu, nk menitis air mata bile nmpak org2 dtg mntak sdekah, jual buku2 agama. Teringt plak aku pnah lalui sumer tue dlu..Sumer org xnk hulur.Da y sombong, da y bek hti. Sumer org mst pk - "Ape la bdak ni mntak2 sedekah xtentu psal, mk bapak xreti jg ker"..Org igt kite nk ker p tebalkn muka mntak2 nie.Kalu bleh mmg kite xnk, tp itu je cra y ader utk teruskan hdup. Nk hrapkn bantuan Jbtn Kbajikan M'kat, byk noo krenah, tunggu xdpt2 smpai org tu dh meninggal pn xmsuk2 lagi duit bantuan. Nk mntak bntuan Umno, kate dh msuk, tp ntah, xtaw msuk kat poket sape..

Dlu ms kcik kat skolah rendah, aku tkut nk mndi pg, sbb air kolah sejuk sgt. Umah kmpung mane ade water heater..Mak aku bkar arang sbuh2 tue, then celup dlm kolah bg air die hangat..Then bru aku mndi..Ms tue mmg pyah, sume duit hsil kj mk abah gune utk sapot adik bradik aku len kat U..Mk abah n aku kt rumah xder bnde nk mkan..Aku igt lg da skali tue ak tgh cedok nsi dri priuk, tetiba nsi y kt snduk tu tertumpah ke lantai..Lantai umah kmpung ni phm2 la, bkn ade tile cm umah korang, ktor la kn.Mk aku mrah giler, sbb kat umah dh xder beras nk msak..xder ape nk mkn, jd aku pn amik blik nsi y jatuh tue msuk lam pinggan aku..Giler sdih, ms tue aku xtw pape lgi, y aku tw juz ngis jer la..Dlu ms kcik, aku amik upah racun lalang kt kebun org..dpt la gak duit sikit..leh wat bli buku skolah...Bnde y plig igt ms tu adelah aku pnah kne kjar ngn lmbu jntan ms kat kebun..Giler laju..Y lg best, 1st time aku tgk lembu bleh lompat pagar kawat duri y lgi tinggi dri tinggi aku ms tue..pergh...ssh nk jmpe..Alhmdllh, rzki utk mk abah aku, aku bjya dpt lompat dlm PTS n 5A dlm UPSR wpun dlm kdaan hdup y sgt mndesak.

Tahun tue 2002, teringt plak ms tue tgh hot World Cup kat Jermen..Kwn2 sonok cite kat skolah, sape y menang sape y klah..Siap leh gduh2 lagi.Aku juz mmpu dgr je ms tue..Umah y ade ms tue xder lagi tv. Peti ais pn xder..Rumah tue pn sbb org bg tumpang dduk smntara..Sedih bile stp kli g skolah, kwn2 citer sal bola..Ssh nk gmbrkn kdaan ms tue..Bile kwn sbelah meja tnye - "Oi ko tw x Portugal klah.."..erk..aku xtw nk jwp ape.. Aku kj kmpung tiap kli da cuti pnjang utk sara byr yuran ms kt skolah agama dlu..Igt lgi kj kat kilang papan buat palet utk letak brg2.Klu korang pnah tgk org jual btu bata or tile utk lantai, dorang akn pack sumer n angkat gune alas cam susunan kayu kat bwh die. Tue la die palet, n aku kj wat tue dlu utk 30 sen stp palet..Ssh mmg ar ssh, tp nk wt cmane. Adik bradik aku sumer kat U, mk abah aku kene ar sapot..Aku sbg ank bogsu nie kne ar fhm kn..Semua y aku nk, aku bli gne duit sndri..

Rmai org kate org Felda nie kaya raya..Buah sawit mahal, getah pn mahal..Tp hkikat kperitan hidup tue org dlm Felda tue sndri y rse..Tandan sawit tue, kalu sbiji blih cpai 40 kilo..Abah aku agkt 3 biji sekali msuk dlm kete sorong..Igt senang ker nk sabit buah sawit..Aku igt lgi kat "cengkiak"..Bnde nie cam kerengga, tp lgi bsar, lagi kuat n kaler htam. Aku mmg plig fobia bnde ni sbb die pnah gigit part snsitif aku smpai bdarah ms tgh pungut biji sawit kat kbun..Aku igt lagi ade org tue meninggal on da way ke kebun sbb kene sondol ngn babi hutan..Sedih ble mk abah suh aku pndah msuk skolah Integrasi..Xsnggup nk tgk dorang sndrian kat kmpung..Sdih bile mk aku bwak aku ke kdai buku Tai Kuang kat Segamat sblom pndah skolah. Aku igt lgi mk aku ckp - "Ambik le aper2 buku y nk gune nnti, buku rujukan nyer dh cukup?? Xper nnti mk byarkn"..Sdih sbb dlu, aku bli sumer gune duit sndri, tp ms tue 1st time mk aku belikan sumer buku2 smata nk msuk SBP..Yuran dh la dkat 1000..mane nk cri duit pn ak xtaw..Aku tw aku dtg dri fmili ssh,n mk abah aku org ssh, sbb tue ak blaja sungguh2..Aku igt lgi buku rujukan Sasbadi fizik aku, smpai dh crai berai dh pages die..

Sblum msuk matrik, aku kj blik kat kmpung kat 1 kilang batu bata nie..jmpe blik kwn2 lame mmg best..Aku igt lgi tokei aku ms tu nme die Poo Chun..kwn bek abah aku sjak dri tahun 80-an lgi..Sbb ms mula2 msuk Felda, gaji Rm90 jer sebulan, so abah aku kj kt kilang batu bata ni (ms tue bru bkak)..smapi la skg..Sbb tue la aku pn kj situ gak..Kj die mmg susah, bwah trik pnas mtahari, smpi mk aku pn xleh nk beza aku ngn org bangla y kj situ, mkin byk jrwt, byk kudis..Kj aku xtentu, kdg kumpul tanah gune bajak, kdg angkat btu bata y dh siap gune polip (forklift)..tp most of the time aku kne angkat batu bata ngn tulang empat kerat ni ar..Mula2 gaji aku 20 je 1 hari, tp nek jd 30 1 hari sbb rmi bdak2 baya aku lari, xtahan kj situ..ntah la, aku wat ok jer, myb bdak2 bndar nie xbese kot maen ngn minyak htam hri2..Duit y aku kmpul tue smpat ar sapot yuran aku kat matrik tangkak dlu..

And now, aku student USM Computer Science, majoring in Network Computing..Aku kagum dgn mak abah aku smpai bile2..xkire btapa ssh nye dorang, xkire dpt mkn or x, ape y pnting sumer adik bradik aku bjya msuk U n bjaya dgn jaya nye..Abg sulung aku dlu UPM now cikgu kat skolah sukan Bandar Penawar, 2nd abg aku dlu UTM now dh ade computer company sndri, 3rd kakak aku dlu MMU now network traffic engineer utk TM asia pasific..4th, kakak aku dlu UTP now engineer kat Petronas BASF,Kerteh..

Sedih bile kenang pjalanan hdup dlu2 nie sbenanye..Tp pngalaman hidup ssh, serba kekurangan tue la y mengajar aku erti dunia sbenar y serba xadil dan kejam ni..



Wpun bkn aku pnye, tp ni la motor impian aku spnjang hayat - vespa




.

27 February 2010

Socket Programming Part II

Assalamulaikum wbt..

Alhamdulillah, first syukur kpd Allah S.W.T krn kite msih lgi dianugerahi nikmat Iman dan Islam wlaupun hkikatnye kite selalu asyik dan lalai dlm menjalankan tggjwab as a khalifah-Nya.

"INTRODUCTION"

Entry y lepas
aku da explain sikit sal ape die socket programming..Kalu korang xbace lgi, sila la bace since aku tkut da y termuntah lak nnti..1st, keep in mind that socket is like a tunnel so that my next explaination would be easy for you guys..Kat bwh nie ade screenshot process flow on how socket programming really works. Oleh kerana buku Unix Network Programming API aku kat en. Azri, mka gambo kat bwh nie adalah gambo y aku google je.




"BRIEFLY"


Socket programming melibatkan communication between server n client. Who's gonna be server n client ?? Jwpan nye adlah terletak pd kite as a programmer. Pd aku, to make it simple, Server is the one who provide the service n client is the one who request/consume the service..For instance, Facebook y hri2 korang usya tue kn. Facebook mainframe wil be the server, n your machine will be the client n request sumer msg2 kat wall..

"1ST, SERVER INITIALIZATION"


Bende y plig penting adalah server perlu ade ip address n port..Bygkn korang da rumah with one address but more doors. Korang kne la decide which "door" y korang nk gune. Port 1-1024 is reserved by IANA as a default web service cam port 80 utk HTTP, port 22 utk FTP and so on..Suggestion aku gune port 2000 and above..1st, initialize Socket class or "tunnel" n call library2 y berkaitan..Next, bind kn dgn ip address machine korang n port y korang nk gune. Xksah IPv4 or IPv6, the step is still same but the address representation n network masking is little bit different. Once korang dh bind, korang sebenarnye dh advertise through out all computer in local network y korang ade "tunnel" ke laptop korang..Be carefull since this is the actuall way on how hackers gain access on victim's computer.So aku advise try dlu dlm mode local host n your ip address should be "127.0.0.1" or "::1" for IPv6..Lepas "tunnel" dh establish, server will be in "daemon state" - a program that always running in the background n listen for any incoming request.

"CONNECTION ESTABLISHMENT"

Next, prepare your client program. Client xperlu bind ip address n port ke socket. What he need to know is with who he want to connect. Atas sbb itu, korang kene supply kat die ip address n port server y korang dh wat td..Yela, kalu x, cmana lgi die nk connect ke server..Then bile connect ke server, 1 "path" akn di establish between your client n server. Utk permulaan, xpyahla pk soal connection secure or x secure, in fact, mmg xsecure pn..Kalu nk wat style "ssl" connection with further packet encryption, sila wat ms kat phase ni.

"DATA TRANSMISION"


Once dh connect, client n server should bleh communicate n pass some string msg as a sample data. Skg nie, data trasmision depend on what type of network protocol y korang nk gune, TCP or UDP. TCP is little bit complex compared with UDP but more reliable..Kenapa?? ok aku explain.

In TCP, stp data akn di convert from host byte to network byte, tmbah dgn other TCP header like source n destination info, TTL (time to live), checksum, padding, "window" size, packet sequence n etc. Maximum transmision unit (MTU) pn agak besar but fixed. Which means kalu buffer size = 1024 byte, but korang juz nk send hruf "A" je, TCP protocol akn automatik add some padding utk mksure die reach MTU size. One more, mose of the time kite akn download muvie y bersize besar >500 MB rite. Its imposible to transmit whole file with single data packet. In reality (like what all download manager do), this 500 MB file akn dipisah2kan kpd packet2 y lebih kecik mengikut size MTU td n also "window" size..Ape die "window" size nie?? Next post insyaAllah aku akn explain sikit since ia melibatkn 3-way handshake n bla bla bla..So, packet2 kecik nie td aku lbih suke pgil as a "chunk"..Each chunk akn di bg "no giliran" or sequence number. Then all chunk will be sent regardless which one is the first or last. Bile packet2 or chunk nie arrive kat laptop korang (client), download manager akn combine or rebuild blik to form the big file again.

In UDP is totally different, each file still need to be splitted into chunks but there is no 3-way handshake, cheksum, n byk lagi. In TCP kite pgil packet, but in UDP kite pgil datagram. Since there no overload network header information, UDP datagram mmg ringan n kcik. Ditambah plak dgn xder sistem "handshake" or acknowledgment, datagram besenye mmg cepat n lagi pantas drpd send gune TCP protocol. But once again, there is no guarantee y datagram nie td akn smpai kpd client. Aku bg contoh, let say la file y besar td split kpd >1000 chunk datagrams, blum tentu datagram ke-5 akan smpai dlu dripad datagram ke-10..Thats why UDP xseswai utk send file bersize bsar, tp advantage die amat berkesan bile nk wat application y byk gune message passing (instant messanger, distributed system).

"CLOSE CONNECTION"


After data transmision hbis, client akn close connection dlu, then bru server..After that, server akn return blik kpd "listen" mode coz cm aku ckp td, server ack like a "daemon" - always running. Bile connection dh close, next client bleh establish connection bru dgn server..

CONCLUSION

Kalu nk further lgi, korang bleh wat Socket connection either in asynchronous or syncronouse mode, non-blocking or blocking state n byk lgi. Aku tw rmai y xminat nk tw bnde2 complicated cmni, but the thing is, its good to expand your knowledge n make yourself "knowledgable" person instead of doing assignment n let that particular knowledge juz "pass by" your subconscious mind..Gain the concept, n apply it whenever needed..

Gudluck..




Sumer dean list from School of Computer Sciences, USM. Cube cri mane aku..hehe






.

26 February 2010

Socket Programming

Assalamulaikum wbt..

Firstly, syukur alhamdulillah krn ngn rahmat dri-Nya aku still lgi mmpu menulis kat blog nie..Sedikit petikan kate2 Dr. Danial ms khutbah jumaat td - "Udhulu fi silmi kaaffah" - y mane mksudnye "msuklah kamu kpd Islam scra menyeluruh / total..Oleh krna minggu nie aku struggle wat socket programming, so nk share sikit ar sal bnde nie. Mudah-mudahan korang y bace bnde nie leh expand n get the new knowledge.

"INTRODUCTION"

Let say korang nk wat 1 application cam Yahoo Messanger or Windows Live or Empathy (Ubuntu) y memerlukan extensive message passing between peers. Cara plig kacang n cepat adalah dgn manipulate database n timer sperti mana my teammate Acad wat ms die 2nd year for Widget Community beliau..Ali taip msg, insert kat shared database. Then Babun ade timer, every 3 seconds check database for new incoming msg. If ade y bru, fetch and display it. Same thing when Babun taip msg kpd Ali. Cara nie mmg sng and less complicated since everyone know how to use database (MsSql, MySql, Oracle etc)..But the thing is, frequent database access amat tidak efficient n high possibility for slow data retrieval time when 100 (let say) people access the database at the same time..Contoh laen, KFC ade byk branch kat 1 Malaysia nie. Director nk latest sales data for every branches. Cara plig senang, once again, every branches update shared central database about their latest sales data. Bnde y sama jgak akn berlaku when lot of people access the same shared database at the same time - slow data retrieval or even insertion..

"SOCKET PROGRAMMING"

So, the answer is - Socket Programming. Ape die Socket?? To make simple, aku bg analogi mudah. Socket nie snang nk fhm kalu kite anggap die mcm 1 tunnel y connect between 2 machine..The main thing is mesti kene 1 side jd Server n other side jd Client.

Server should be in "daemon" state - always running or be in infinite loops sbb Server akn wait for any incoming request..For that reason, Server kene ade ip address and port number that it will listen on to. Bind ip address dgn port number, listen then accept incoming connection, thats all..Kire kite create 1 public tunnel la..Simple kn..Client plak xperlu establish port number. Just create socket class, connect with Server's ip address n port number, setel..port number nie penting sbb server ade byk port number. Kite ade reserved port from 1 - 1024, so available port 1025 till 6000++..byk kn..Just imagine kite ade rumah y byk pintu but 1 je alamat rumah, so skg korang nk suh client tue masuk ikut pintu mana.

"NETWORK PROTOCOL - TCP OR UDP ??"

Next major things are type of data packet n internet protocol. Dlm Socket Programming, ade 2 protocol y kite bleh gune, TCP or UDP..Deep explaination bleh tanye Uncle Googlerudin. Briefly, TCP nie connection oriented n UDP conectionless. Analogy mudah (cam bese), TCP nie cam korang call mak kat kmpung. Once korang dail no. tepon, korang kene tgu mak korang agkat tepon dlu bru bleh ckap rite. Thats means in TCP, connection must establish first before data transmision can be done. However in UDP, analogi nye cam korang send SMS kat pakwe. Juz taip then send kat no tepon y berkaitan. Korang xtaw pn SMS tue dh dibaca ker blum, ape y korang tw ialah SMS tue dh delivered (lum tentu pakwe korang bace lg)..In other words, UDP doesn't need established or reliable connection..

So, bile ms nk gune TCP or UDP?? My opinion, use TCP if packets sequence is important or packet size is big (more than 1024 byte), otherwise use UDP instead..Aku bg contoh, application cam Yahoo Messanger gune UDP, since ape je y nk di send, juz string perkataan or file2 kecik. But Internet Download Manager (IDM) kene gune TCP protocol, kalu x, cmana die nk tlog donloadkn muvie korang kat Syok.org y 700 MB tue ye x..

"CODE EXAMPLE"

Finnish theory class, now practical part. Kat bwah nie aku bg sample code dalam Java utk Socket programming using UDP as network protocol

UDP Server:
import java.io.*; 
import java.net.*;

class UDPServer {
public static void main(String args[]) throws Exception
{
try
{
DatagramSocket serverSocket = new DatagramSocket(9876);

byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];

while(true)
{

receiveData = new byte[1024];

DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);

System.out.println ("Waiting for datagram packet");

serverSocket.receive(receivePacket);

String sentence = new String(receivePacket.getData());

InetAddress IPAddress = receivePacket.getAddress();

int port = receivePacket.getPort();

System.out.println ("From: " + IPAddress + ":" + port);
System.out.println ("Message: " + sentence);

String capitalizedSentence = sentence.toUpperCase();

sendData = capitalizedSentence.getBytes();

DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress,
port);

serverSocket.send(sendPacket);

}

}
catch (SocketException ex) {
System.out.println("UDP Port is occupied.");
System.exit(1);
}

}
}

UDP Client:
import java.io.*; 
import java.net.*;

class UDPClient {
public static void main(String args[]) throws Exception
{
try {
String serverHostname = new String ("127.0.0.1");

if (args.length > 0)
serverHostname = args[0];

BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));

DatagramSocket clientSocket = new DatagramSocket();

InetAddress IPAddress = InetAddress.getByName(serverHostname);
System.out.println ("Attemping to connect to " + IPAddress +
") via UDP port");

byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];

System.out.print("Enter Message: ");
String sentence = inFromUser.readLine();
sendData = sentence.getBytes();

System.out.println ("Sending data to " + sendData.length +
" bytes to server.");
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress, 9876);

clientSocket.send(sendPacket);

DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);

System.out.println ("Waiting for return packet");
clientSocket.setSoTimeout(10000);

try {
clientSocket.receive(receivePacket);
String modifiedSentence =
new String(receivePacket.getData());

InetAddress returnIPAddress = receivePacket.getAddress();

int port = receivePacket.getPort();

System.out.println ("From server at: " + returnIPAddress +
":" + port);
System.out.println("Message: " + modifiedSentence);

}
catch (SocketTimeoutException ste)
{
System.out.println ("Timeout Occurred: Packet assumed lost");
}

clientSocket.close();
}
catch (UnknownHostException ex) {
System.err.println(ex);
}
catch (IOException ex) {
System.err.println(ex);
}
}
}

"CONCLUSION"

Ape y code nie buat adalah sgt simple, client connect with server, send perkataan dlm small letter, server receive n convert to Uppercase n then send blik kat client, thats all..Aku rse ckup kot code kat atas nie, juz nk show how client can communicate with server via Socket Programming..Mula2 mmg pening, tp try ar dlu..mesti best..Bleh gune ape2 java compiler, Netbeans or Eclipse (aku gune Eclipse)..No extra library, juz import java.io n java.net jer..hehe



Welcome to Socket Programming =)





.

25 February 2010

I'm wondering

Assalamulaikum wbt..

Alhmdulillah, dpt gak aku menulis blog nie wat kesekian kalinye..Minggu nie adlah minggu y amat susah utk aku..Ironik nye, minggu nie byk bnde baru y aku tw..Virtual machine, virtualbox, socket programming in OO style, .Net communicate with Java application n mcm2 lagi. Ms tinggal lagi lebih kurang 2 bulan je utk FYP aku..Sempat ke x nie..Core technology pn ximplement lagi..Cmana nk wat MMS pn aku xtaw lagi..SMS tue bleh ar..

Dlm byk2 part FYP aku nie, aku plg minat skali bhg Grid. Even aku bdak network, tp bende nie sgt2 mencbar kredebiliti aku selaku programmer beginner..Dgr lecture Dr. Chan mcm senang jer, tp apasal aku nk wat ssh giler. Mslah nye, xder org nk tnye..Tanye mmber2 pn sumer xtaw..So, knape aku minat bnde nie kalu dh tw ssh?? Ntahla, prinsip aku, kalau la 100 org kate ssh, n kite sorang bleh wat, nescaya akn menjadi "mutiara di lautan"..The thing is, aku curious nk try+tgk cmane two different application bleh communicate each other, on separate machine n even different type of OS (windows vs linux)..That inter-process communication y wat pening..Socket, RPC, RMI, JADE, JINI..zzzzz

Aper pn, computer technology nie mmg luas..Semantic, Augmented Reality, Cloud Computing, Security n byk lgi..Kn best kalu otak nie leh jdi cm Neo dlm The Matrix, msuk CD, psag plug kat kpala, trus bleh tw sumer..Bkn ape, byk bnde y aku xtaw lagi..Ilmu xjauh mane, da niat nk amik master..

Skg dh pkul 11.00 mlm, ms ntuk aku tido. xtaw nk tulih ape lgi. Wondering how on earth that Mark Zuckermberg can make Facebook while now he still 23 years old..Wondering how we cn make our own API n web service n advertise through specific port with logical domain name..Wondering how other .Net programmer can make universal class file in .dll format n only need simple reference in Visual Studio to use it..Wondering how 3-Handshake being done in TCP connection in Socket programming..Gudnite everyone..ZZZzzzzz





...

21 February 2010

C# Art


Assalamulaikum wbt..

Alhamdulliah, syukur ke hadrat ilahi kerana dengan limpah kurnia nye aku bleh ar bernafas lgi atas muka bumi nie selaku insan bernama mohd yazid..

Ok, skg nie rmai .Net programmer y masih beginner mcm aku still wat programing dlm cara y konvensional or tipikal. Sometimes its good for readability (senag nk debug), tp prasan or x, ia bleh menyebabkan kurangnye reliability in term of efficiency, performance, memory and battery consumption. Bnde nih jarang org tgk, y penting projek siap dh la kn. Tp aku sgt interested kat bnde2 cmni..sbb nye..itulah the arts of programming..tul x?

"Get and Set functionality"

First, nk explain skit sal Get n Set nie. Mcm bese, Get adalah bile kite nk dptkan value from that particular object instance, n Set bile kite nk initialize or assign value. Nk lebih clear, aku bg contoh kat bwah nie:

Contoh 1:


private string myname;

public string GetMyName()
{
return myname;
}

public string SetMyName(string name)
{
myname = name;
}

Contoh 2:

public string myname {get; set; }

Nampak obvious kn.. 2 bnde y sama, tp 1 lagi pnjang, n 1 lagi pendek jaa code nye. 1 line je..Its up to us as a programmer which one to pick. Tp persoalannye, bile masa nk gune contoh 1, n bile plak nk gune contoh 2?? Simple, gune contoh 1 bile melibatkan variable y penting, protected, or shared with other crucial function, class or object. Sbbnye, most of the time, hackers bleh hack n manipulate ape2 value bile variable di declare as a public. Solutionnye, declaration variable adalah private or protected, but kite wat another public function untuk access variable tersebut (contoh 1). Semua bnde ada drawback rite. Drawback bnde nie adalah ia memerlukan another memory space utk pass by value dlm parameter function tersebut dan code die agak pnjag sikit.Kalu variable tue xbrape important (most of the time) cam perkataan dlm textbox, penggunaan Get n Set (contoh 2) amat disyorkan oleh aku.Sbb nye, ia simple, menjimatkan ruang (1 line je) n by default, bnde nie gune pass by referrence (not by value) which means its variable would share exactly the same memory space with function call. Dengan kata lain, korang akn jimat 1 memory space n lebih efficient.

"Quick User Control Initialization"


Ok bnde nie pening sikit.Sila baca dengan teliti. User Control aku dh explain kat post2 y lepas. Jd sila bace tu dlu k. First, let say aku wat 1 user control (MyUserControl) y ader textbox (txtName) n label (lblName)..Then cam bese, cm programmer .Net y laen buat bile nk initialize User Control adalah seperti berikut:

Declaration:

Public partial class MyUserControl : usercontrol
{
Public MyUserControl()
{
InitializeComponent();
}
}

Initialization:

MyUserControl myUC = new MyUserControl();
myUC.lblName.text = "Nama: ";
myUC.txtName.text = "Mohd Yazid Mohd Jaafar";
myUC.Width = 100;
myUC.Height = 150;

This is tipical way y bese kite (n aku jgak) wat bile wat C# programming. Byk line diperlukan juz nk initialize 1 user control jer. Utk bg korang nmpak, aku bg contoh laen y lebih jimat n efficient:

Declaration:

Public partial class MyUserControl : usercontrol
{
Public MyUserControl()
{
InitializeComponent();
}

Public MyUserControl(string names, string labels, int height, int width) //Override Constructor
{
InitializeComponent();
this.txtName.text = names;
this.lblName = labels;
this.Height = height;
this.Width = width;
}

}

Initialization:

MyUserControl myUC = new MyUserControl("Mohd Yazid", "Nama: ", 100, 150);

Simple, 1 line jer utk initialization. nie la die ape y aku explain dlm post2 y lepas sal separation of class for efficiency and reliability. Xperlu byk2 code dlm main class. Xelok tamak2 nie. Share sikit code y belambak tue kat class or object y lain. Nmpak kemas, n senang nk debug. Kadang aku pelik gak. Sometimes org bangga bile kate code die dh smpai 1000 lines. Tp pd aku, lagi bagus kalu kite bleh wat bende y sama tp hanya menggunakan xsampai 500 lines pun. Tu mknanye die xreti nk utilize Object-Oriented Programming..

"Conclusion"

Orang kdang2 kate, "Buat cmni pn same gak aper..". Mmg la same bro..Its ok if korang wat hanya utk siapkan assignment or project y duedate tinggal esok ja. Tp cube byagkan kalu korang dh keje as a programmer, wat 1 apps but in the end, customer complain y apps korang nie pesal slow sgt, hang laa..itu laa..ini laaa..Kat situ la dtg nye code efficiency, memory consumption n bla bla bla..Prasan or x, Microsoft Office Word Beta 2010 tue bru jer mkan 70 - 80 KB dlm task manager korang. Software punye la besar, ader mcm2 tp ringan jer..Agak2 cmana programmer Microsoft wat mende nih..

Ape pun, utk capai 1 mission, ader byk cara. Bile ader bug, ader 1001 solution utk nye. For me, I dont care if I got A, B, C or even D for my project. But the thing is, I want the KNOWLEDGE on top of it..



En.Azam, Acad, Aku n my Dean, Prof Rosni




All Maxis Mobile Content Challenge winners



Gudluck guys..

p/s: Sumer code ditulis on the spot kat blog.Kalu ader silap, hrp dimaafi





.

09 February 2010

Sometimes...

Assalamulaikum wbt..

Sometimes..Aku teringat zaman muda2 dulu..

Sometimes..Aku teringat zaman bile ht nie tenang..

Sometimes..Aku teringat zaman bile ht nie tenang tanpa gangguan..

Sometimes..Aku teringat zaman bile ht ini hanya untuk Allah swt..

Rindu nye aku akan zaman itu..





Terkenang zaman - "Bile kejar akhirat, insyaAllah dunia akan mengejar kita" - Saydina Umar al-Khattab r.a

Kat sini aku lampirkan lirik lagu favorite wat renungan kite bersama.Lagu nie dendangan Maher Zain bertajuk Thank You Allah.


I was so far from you
Yet to me you were always so close
I wandered lost in the dark
I closed my eyes toward the signs
You put in my way
I walked everyday
further and further away from you

Ooooo Allah, you brought me home
I thank you with every breath I take

الحمد لله الحمد لله
All praises to Allah


I never thought about
All the things you have given to me
I never thanked you once
I was too proud
to see the truth
And prostrate to you
Until I took the first step
And that's when you opened the doors for me
Now Allah, I realized what I was missing
By being far from you

الحمد لله
All praises to Allah

Allah, I wanna thank you
I wanna thank you for all the things that you've done
You've done for me through all my years I've been lost
You guided me from all the ways that were wrong
And did you give me hope

O Allah, I wanna thank you
I wanna thank you for all the things that you've done
You've done for me through all my years I've been lost
You guided me from all the ways that were wrong
I wanna thank you for bringing me home

الحمد لله
All praises to Allah
الحمد لله






.

02 February 2010

Optimization VS Accuracy

Assalamulaikum wbt..

Ok come back to my world - programming. Seperti tajuk kat atas tu, hri nie aku nk cite sikit sal pendapat aku, ape y aku rase bagus n ape y aku rase xbgus utk kite selaku programmer buat especially those who are C# beginner like me.

"OPTIMIZATION & EFFICIENCY"

Sedar atau x, setiap line of programming of code y kite buat sebenarnye mempengaruhi kadar efficiency program kite as a whole. Aku bagi contoh utk buat 1 application, programmer A memerlukan 1000 line utk siapkan bende tue tp pd ms y sama, programmer B hanya memerlukan 300 lines jer. Jadi y mana y lebih efficient?? Pada aku, efficiency sesuatu programming code tue sebenanye terletak pd faktor turn around time dan memory consumption. Memang jelas kalu compare based on number of lines, programmer B mmg power, tp kalu application die buat laptop aku jd slow nk mati, xguna jugak kan. Kesimpulannya, sbb tue la kite semua selaku pelajar CS wajib amik CPT212 - Algorithm n Data Structure. Memang aku akui, aku mmg kagum gile dgn org y bleh develop sesuatu algorithm nie. Xtaw la baper byk sel2 neuron y berhubung dlm kepala die. So kenapa turn around time n memory consumption??

"TURN AROUND TIME"

Apekah die turn around time?? Aku bg 1 contoh y plig simple. Bile kite bukak page Yahoo n register akaun emel baru, brapa second y die amik utk mksure registeration kite succesful?? Kalu kite wat Transact-SQL n select some table from MS Sql, brape lama ms y diamik utk load all data kat interface?? Sumer nye berkaitan dengan masa kan..Pd pendapat aku, one thing y every programmer should think about is how long it should take to do the specified task. Aku penah baca buku Human & Computer Interaction (HCI) oleh Stalling kepunyaan Umi Mahmudah Mohd Jaafar (kakak aku) y kini sorang network traffic consultant for streamyx asia pacific. Dalam buku tue ade sebut sal 1 prinsip paling utama dlm design GUI - Respond must be given within 5-7 seconds. Dgn kata laen, lebih dri tue, user akan rase bengang sama mcm korang cbe connect USMHotspot xdpt2.

Aku bg 1 contoh implementation y mungkin akan bg serba sikit idea pasal reducing turn around time nih. Usually, ms pling byk dibazirkan dlm sesuatu application adalah utk load data or set data dlm database..Kene plak network slow, mmg cm taik ar. Setiap programmer ader cra msing2.. Tp kat sini nk bg contoh cra aku utk memudahkan pemahaman.. Besenye aku akn wat system aku xkire la web or desktop based utk pre-loading dlu sumer data2 y diperlukan n fill in dlm 1 container cam linklist, dataset or data table. Contohnye kalu application tue sal hotel management, aku akn load awal2 sumer info sal customer,registration and soon dlm 1 dataset or text file so that next time aku dh xperlu lgi access database. Hanya bile berlaku update or delete je bru aku access database n fetch blik new data. So, xderla user tue tekan 1 button, then system access database, tekan button lagi, access lagi, tekan then access lgi.Brapa byk nk access daa. Load jer sumer data awal2, store lam temporary container cm dataset, then bile nk access, access jer dri dataset tuh. Advantages cara nie ade 2 iaitu reduce number of connection y perlu kite wat (user toksah tunggu lama2) n application still works even internet connection gone.Best kan..How to do it? byk cra die, depends on what your task needs..

"MEMORY CONSUMPTION"

Haa part nie y aku plig suke nie.Penah x kalu korang wat website or desktop application then bukak task manager tgk braper byk memory consumption application korang?? Mesti xpenah kan, sbb y kite taw ialah janji siap n dpt submit on time. Actually bnde nie penting gak sebenarnye sbb not every user or customer y akn gune application kite nanti ade 2 or 3 gig RAM n Dual Core. Kite selaku programmer, kite kene la consider dorang jgak kan. Dorang pn manusia jgak mcm kite..Sbg contoh, software iNetmon utk dak2 network CS bleh capai 250++ KB total memory consumption n membuatkan laptop aku kdag2 jd slow especially bile turn on sumer module2 die. As a comparison, Office 2010 sometimes hanye dalam 70 - 100 KB jaa n kalu korang tgk, application dorang smooth jer. Senang hati nk menaip wat assignment kan..Dengan kate laen, kalu la korang bleh reduce memory consumption nie ke tahap membanggakan, insyaAllah application korang mesti super duper laju.

Aku bgi contoh la supaya korang mudah paham. Besenye kite declare variable kan. Ntah mane2 kite declare. Asal nk gune jer declare baru. Sedar or x, setiap declaration y kite wat akan menambahkan penggunaan memory. Camni, bile kite declare, system akn sediakan 1 memory address space utk variable tuh n lock utk kegunaan application kite shj. Once kite dh hbis gune, memory address tue still there n lock kecuali kalu kite dispose or null kan variable tue. Cemana aku nk explain erk. Let say la korang ade 1000 lines of programming code. Declare ar 1 global variable type string n gune jer variable tue as a temporary to store anything through out whole programm whenever needed. Jimat memory space sikit. 1 lagi adalah penggunaan List dan String. Cube compare declaration kat bwh nie:

string[] TempString = new string[100];
list TempList = new list();

Bile declare string, kite kene specify size die tul x? Belum tentu kite akn gune sumernye sampai habis. Bile declare jer string array, system dh sediakan n lock 100 memory space utk kite. membazir namanye tu..Xelok membazir ni, kwn syaitan..hehe.Solution nye, gune la List sbb list nie aku bleh kata cemana erk, ermm "memory on demand" kot.Sbb bile kite declare, xperlu specify size. Hanya bile add item dlm list tue je bru la system akn specifykan 1 memory address. Lagi efficient kan?

Contoh laen adalah penggunaan "using" statement dlm Object declaration.Aku bgi contoh code kat bwah nie:

Contoh 1:

void ReadFile()
{
StreamReader ObjReader = new StreamReader(@/"daunkelapasawit.txt");
String temp = ObjReader.Readline();
}

Contoh 2:

void ReadFile()
{
using ( StreamReader ObjReader = new StreamReader(@/"daunkelapasawit.txt"))
{
String temp = ObjReader.Readline();
}
}

Sori ar indentation xbtul, almaklum la write trus kat blog jer, mane ader intelliSense. So ape beza kedua2 contoh kat atas nie? Contoh 1 ada usual object declaration y bese kite buat. Bile kite exit function ReadFile, memory address utk Object tue actually still exist sebenanye. Makin byk bnde2 cmni, mkin berat la application kite. One of the solution kalu dlm C# adalah melalui penggunaan "using" statement. Maksudnye, systeam (or .Net Framework) akn detect bile Object tue dh x digunakan lgi (or out of the function scope), die akn automatically dispose Object tersebut.Dgn kate laen, bile dh xgune, buang jer la..Wat beratkan beg jer nk angkut ke sana ke mari.

Byk lagi cra2 utk makesure program kite running dengan smooth n steady. Nie antara cara2 y bleh kite guna selaku programmer. Ape pun, explore, try n gain knowledge by yourself is better than relying on someone..Gud luck!







.