Friday, May 17, 2013

仕事の日々#3: VB.NET anonymous methods

What we lazy coders do in C# when dealing with a non-STA WinForm on another thread is usually:

Invoke((MethodInvoker) delegate
{
    txtSomeLabel.Text = "Foobar!";
});

Today I had to deal with a piece of code written in VB.NET, and here’s how it’s done:

Invoke(
   Sub()
      txtSomeLabel.Text = "Foobar!"
   End Sub
)

No casting is required as BASIC is not a strongly typed language.

It also works with anonymous methods with parameters, you just have to use Function in place of Sub.

Tuesday, May 14, 2013

仕事の日々#2: C# byte & Java byte

Although C# could be said a rip off from Java, I would understand why Microsoft made the choice to be different from Sun – because it’s downright confusing when doing low level processing if it’s done the Java way.

Aside from String/string, boolean/bool, endianness etc. beginner coders migrating from C# to Java or vice versa would most definitely make this mistake – C# byte and Java byte

In C#, a byte is an 8-bit unsigned integer (unsigned char for you C/C++ dinosaurs out there), while a byte in Java is an 8-bit signed integer (signed char).

What does that mean?

Well, it meant you’ll screw up your code if you ignore this difference.

C#

for(byte i = 10; --i >= 0; )
   Console.WriteLine("foo");

Java

for(byte i = 10; --i >= 0; )
   System.out.println("foo");

For a more hidden problem:

C#

short i = 0xFF;
byte j = (byte) 0xFF; // (byte) is optional
if(i == j) Console.WriteLine("Yay!");
else Console.WriteLine("Nay!");

Java

short i = 0xFF;
byte j = (byte) 0xFF; // (byte) is mandatory
if(i == j) System.out.println("Yay!");
else System.out.println("Nay!");

If you’re not aware of this problem, your program will most probably compile, probably pass all your tests but randomly fails after live deployment.

Captain Obvious says:
“The samples above behave differently for C# and Java.”

Oh, to make things worse, there’s no “unsigned” keyword in Java. Great. Static casting like a magus.

仕事の日々#1: OIC & ORACLE_HOME

Here’s the scenario: I’m writing a setup deployment (installer wizard) project that uses Oracle on a 64-bit system.

Naturally, the installed Oracle Client on the target system is 64-bit. Because Microsoft Installer Executive (MSIEXEC) by default runs in 32-bit mode, and building a dedicated 64-bit project is rather tedious, I’ve resorted to including the Oracle Instant Client into my setup project file.

During setup the wizard will invoke sqlplus to run various database installation scripts. When testing my freshly baked project on the test bed, sqlplus execution ended with code 1.

Well, the problem is: my scripts are configured to exit with code -1 if errors occur during execution. Out of sheer programmer instinct I inspected my setup logs and extracted the specific failed command line out to run it on the console.

The command worked fine.

For a few hours I’ve tried to find out the culprit – changing PATH, altering the script to use “connect”, changing executing user… It just wouldn’t work.

Then I tried redirecting the standard output and error streams (which are originally hidden) from the process into my log file as well.

Sqlplus said:

Error 6 initializing SQL*Plus
Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory

The error message was very helpful, thank you.

I then checked my default environment variables using “echo %ORACLE_HOME%” – the values looked okay.

So what went wrong?

Apparently some bloody smart component written by a bloody smarty pants changed the ORACLE_HOME environment variable to the current execution directory, which is obviously not ORACLE_HOME.

I did not touch environment variables in my code – so that leaves Oracle Instant Client as the culprit.

Once I changed ORACLE_HOME to the values I find in registry right before launching sqlplus, everything worked like a charm. Bloody Oracle developers.

Yes, this affects imp.exe too.

Sunday, May 12, 2013

24歳まで

It is the time again, though this time around it is slightly earlier, before I get overwhelmed by other things.

This is the time I list down small milestones for the past biological-year.

I have to admit, it is quite difficult for me to recall…

 

November 2012: Distant Worlds Live in Malaysia

A very memorable orchestral concert, streams of memories filled with emotions gushing into your head. Distant Worlds is a definite must for Final Fantasy fans.

 

December 2012: Surviving the “Apocalypse”

Apparently we survived the so-called “apocalypse”. Yay.

 

2013

I couldn’t recall much about the events this year.

For this period of time, up until now, I am occupied by my career. Apart from sleeping and resting, most of my time is spent on work.

Most of my explorations this year are in fact circled around my field of work – virtualization, Java card, smart card OS reverse engineering, TWAIN, UX, MVC, ORM (Entity Framework), web services, web security, image processing, setup and deployment projects…

Though, I really hoped I could spend some time on other skills such as cooking, music instrument, language studies, electronics, interpersonal relationships…

I’m still struggling to squeeze them in, but my available time resources are frequently occupied by ad-hoc tasks until I somehow feel like a virtual resource pool that could be dynamically provisioned at any time.

To tell the truth, I would love to meet up with friends and listen to them talking about their lives, stroll around in malls, or watch the latest blockbuster in theatres, but what’s left of me is fatigue – social interaction became a stress to me (unless I’m only required to listen and don’t talk) and I rather coop inside my room to recharge myself, until the beginning of next business week arrives.

 

April 2013: Passing of Grandma

Witnessing the passing of grandma, whom has lived with us for the past 4 years, up to her final moments in life, had left an impression into my mind. The experience was as close as death itself.

It is not death (that scares me), it is the thought of death. It is probably not my death that I am afraid of, but the passing of people I care for, people that occupies the large part of my memories, people I depend on.

In the end our proof of existence is only the fragments of memories left in the living. If the memories are gone, so does the existence of the departed individual…

 

May 2013: Change

Putting Malaysian politics aside (don’t boo me please =w=), it is time for me to change my core principles.

I want to put emphasis on what I could do for people, and not what people should do, or could do. Death is a promise made to me from the moment I was born – my purpose of living is what I could do with the limited time given to me.

The world does not revolve around myself – I am a part of the world, I am a part of a whole, I am not the world, I am not everything.

I want to eliminate my inability to translate thoughts into actions; I want to wipe out shadows casted by my past that is preventing me from making a change.

 

May 2013: First Nendoroid

Seriously, it was a very huge surprise indeed :D