Wednesday, February 11, 2009

Lucky Man: Weekly Cake

I'm a very lucky man! My wife is on a cake course so each week she must bake a cake.... so I'm lucky since it mean I'm going to get cake on a weekly basis :-)

Life is good to me!

See photo of the cake she came home with last night. Yummy!!

Tuesday, February 10, 2009

Weekly Source Code: Create A GUID In .Net

A GUID is a unique identifier that you can use as a reference since its always unique.

If you need a GUID without writting any code, then visit Get-A-GUID.com which will generate a GUID for you everytime you refresh the webpage.

The code below create a GUID in C# and then display it to the console window:

class Program
{
static void Main(string[] args)
{
System.Guid id = System.Guid.NewGuid();
Console.WriteLine(id);
Console.ReadLine();
}
}

You can also store a GUID to a database, more about that in a future post :-)

PS: Been hectic at work, will write more later.

Friday, February 6, 2009

Using God's Name

Something that has been making me really angry lately, so I just want to make an efford and talk about it.

Lately I've been hearing on the TV, in the IT world (as a programmer I'm part of the IT world) etc that people use God's name in swearing etc.

For example:

- When something good / bad happens then: "Oh My God!!" rather than just "Oh Shit!!!" or "Oh Fuck!!" I would rather use "Oh Shit!!" or "Oh Fuck!!" or some other swear word if you really want to use a swear word.

- Bill Gates (or some other rich IT guy) have "more money than God!!". Well God don't need money since everything He say happens. We need money... it anyway make us corrupt etc (what is currently happening in the economy is a good example of that)

- "A visit from God!!". Well depend upon your faith God is actually with you already or is coming. God wouldn't be interested to come ask you what is the latest programming thing you did - His more interested in your life/soul/well being etc. Not if you made another million dollars or wrote another cool application etc.

So to end.... to use God's name is not good... remember that there are people in this world that don't like it, even if you don't beleive in God that is your choice etc and myself (and we as children of God) shouldn't judge you by it but then please be considerate and not do this.

It all comes down to being considerate to someone else's beleive etc.... in goverment / by law they call it "human rights" but in plain English its called: "being a good human being" or just "doing the right thing".

Monday, February 2, 2009

Weekly Source Code: Default Controlling Access - Be Careful!

I've a general rule where I never assume defaults in a language, I always assign an initial value to a variable for example... assuming defaults caused alot of problems for me in the past expecially in languages like C or C++ where defaults can actually "hurt" you. Each language also has a diffirent default behaviour that you will see below with Java vs C#.

One of the rules is to always provide the control access level modifier in OOP languages like Java and C# (the 2x languages that I use alot).

For example:

According to the Java tutorial on Controlling Access to Members of a Class when you don't provide an access level modifier it assumes the class and package level access only. Class access is fine since you do want a member variable to be avialable in its containing class but package level access is where it can hurt you, for example:

package com.echosystem.core;

public class SystemCall
{
int status = 0;
// rest of the class continue
}

here if you've other classes in the com.echosystem.core package those classes can directly access the status member variable above so you're not following OOP rules where encaptulation is important - not to go into too much detail but encaptulation is good! Also if you've another class in another package location you will notice that you can't access this status member variable.

Its important in this case to write the above code as:

public class SystemCall
{
private int status = 0;

public int getStatus()
{
return status;
}

public void setStatus(int inStatus)
{
status = inStatus;
}

// rest of the class continue
}

Here you see that the status member variable is private (make it encaptulated into the class) and you control access to it using a getter and setter methods.

C# will continue in the next weekly source code - I do need to give you time to think about this hey! :-)

Thursday, January 29, 2009

Blog Layout Template Change

I changed the layout of my blog to a white background, this is because some readers found it difficult to read the blog.

Hope the new template is okay :-)

Tuesday, January 27, 2009

Weekly Source Code: Strings Are Immutable

Happy New Year 2009! :)

The String type that is actually a class in both Java and C# are immutable meaning that once you create it, it can't get changed and manipulating it will create a new string object.

This is import for when you want to populate a string in a loop (like a for loop) since everytime it will create a new string that have a performance impact on your code.

For example:

String val = null;
for (int i = 0; i < 100; i++)
{
val += i;
val += ", ";
}

The code above will create a new string object everytime for 100 times, you might not see or notice the impact but it does have a performance impact (test it if you wish).

Its better to use a string builder/buffer class and then append the string values to it since the object is only created once.

For example:

StringBuilder val = new StringBuilder();
for (int i = 0; i < 100; i++)
{
val.Append(i);
val.Append(",");
}

The above C# code use the string builder without performance impact.

Note that in C# its called the StringBuilder class where in Java its the StringBuffer class both is similar in functionality.

Sunday, January 25, 2009

Back From Uganda

Ladies & Gents!

I had a good trip to Uganda and is back to work today :) I was off-sick for a week since I had malaria that damaged my liver but the malaria is gone now.

I will post some photos and a story soon.