Aug 24, 2013

Looking for a new Job: the experience


On this post I've said that I was joining a great team and that I was really excited about it; I did meant that but unfortunately this journey came to an end on Feb/1/2013 when my contract was not renewed after the latest corporate acquisitions round.

In this post I'll describe the process I took to find a new job, but first lets make things as clear as possible:
  1. I am not an HR expert (far from it, I'd rather say I am a complete newbie on the subject), so take every world with a whole mountain of salt ;)
  2. yes, I did follow most, if not all, of the presented advice.
Perhaps the most important advice (and probably the hardest to follow) is: don't panic! I know that it is easier to say than to do (I've been there, remember ?), but try to keep calm and review your options carefully.

The first thing you need is to realize that 
Looking for a new job is a full time job!

It may look like restating the obvious but I haven't realized how much time it may take! So, be prepared to dedicate a lot of time to this phase (fortunately, job wise I hadn't much else to do :).

My first step was to create a list of requirements/constraints for the new job, sorted by importance; you should take into account aspects such as compensation package, relocation, type of work, etc. Depending on your constraints it'll take longer to find your new dream job.

In my case the list looked something like:
  1. It had to be fun and challenge.
  2. The company  I'd work for should at least recognize and be committed to implement/use good development practices (TDD, continuous building, pair programming, etc).
  3. Compensation should be closer to or higher than what I was earning before.
  4. Work from home if possible.
  5. Avoid relocation.
Soon after I come up with this list I started to suffer from the ROOR (Running out of resources ;) syndrome - for reasons that are not important to explain here I had almost no savings... :(.

At this point you really need to think about what you want, review your requirements list and refrain from accepting the first (or second, third, whatever) job offer you may get only because you are running out of money. 

Of course there is a hard deadline and you can't wait indefinitely  in my case I strove to get at least 4 ~ 5 job offers before taking a decision. More importantly than the number, was the quality of the offers; there was one in particular that I was really interested in so I discussed with my wife and we decided we'd squeeze as much as possible from our small savings and would try to allow me 1 ~ 2 more months before taking the decision (while I was waiting for the interviews to come I took the time to experiment with something new, but related to my field of interest). 

After some time the interviews started to come and suddenly I had participated in 3 ~ 4 of them, some in the traditional sense of the word and some virtual interviews (through skype / phone).

Some notes from these interviews (process wise):
  • Never forget that interviews are a two lane road: you are not the only that is being interviewed! You should also be evaluating the company in question.
  • Don't be afraid of challenges! Instead, use them as a motivation to you to learn and improve.
  • Be humble but not shy. Do not put yourself in the position of someone that is reluctant to disagree because you are afraid of not getting an offer: be yourself.

  • Be prepared to face ridiculous, unrealistic job skill set requirements / compensation packs. Just keep the professionalism.

  • Show enthusiasm; would you hire a candidate that looks (and behaves) apathetic in an interview?

  • Even if, in the middle of the interview, you've already made your mind and you don't plan to accept a (possible) job offer, keep the professionalism.
Fun fact: there was 2 situations that I found very strange: in one of the interviews I was asked absolutely no technical questions (at least none that I think would be able to assess my ability to do the job) and in another one the interviewer sold the company in question as the best company in the world but said that they could not get good developers to join them, hum... (guess what? I discarded both of them). 

When you finally get a job don't forget to get back to any pending job offer and let them know you are not available anymore.
Hope this was helpful.

Aug 15, 2013

Did you know? Windows 7 Cool feature

Warning: I've started to write this post a long time ago (whence references to Windows 7 as the new kid on the block) but I refrained to posting it since I could not verify the behavior; now I decided to give it another try.... :).

A common complain on Windows platform is that whenever you try to use a file already being used by another process there is no easy way to find out which process is using that file. The canonical sample is trying to delete a file using Windows Explorer:

It happens that Windows Vista introduced a new COM interface named IFileIsInUse that could be used to allow other processes to figure out which process have the file open. Unfortunately, AFAIK (and based on the MSDN documentation), applications must be aware of this interface and actively do something with it if they want to play nicely with other applications, including the OS. 

This morning I was reading some blog posts and someone suggested that Windows 7 had finally fixed this misbehavior (bug?). Cool! Now I could not resist playing a little bit with it.
My first try was to run a C# application that just kept a file open until some key is pressed and try to delete the file; Wow! it worked perfectly! 
But now I was left wondering whenever this could have something to do with CLR 4.0 changes (since I was compiling with VS 2010). You know, maybe the FCL team decided to do the IFileIsInUse interface dance internally (when you open a FileStream for instance).

In order to solve this doubt I took 2 actions:
  1. Targeting CLR 2.0 (by changing VS configuration for the project)
  2. Write a native C++ application to do the same thing as the C# one (the code bellow).
  3. Compile the same native program (2) with VS 2010 on Windows XP box (which has no support for IFileIsInUse at all)
  4. Compile the same native program (2) with VS 2010 on Windows Vista box (which does has support for IFileIsInUse)
#include "stdio.h"

int main(int argc, char* argv[])
 const char *fileName = "Test.txt";
 FILE* p = fopen(fileName, "w+");
 if (p == NULL)
  printf("Unable to create file...");
  return -1;

 printf("[%s] Press any key to close the file ", fileName);



 return 0;
and in the first two cases (i and ii) the result was the same: Windows Explorer was able to detect which application had the file open (with no extra effort from my side :)! Really nice! (Ok, I agree, Windows should have been doing this for ages, but better late than never, don't you agree ? :)

By the other hand, in the last 2 cases (iii and iv) explorer failed to detect the application that had the file open (with exclusive rights).

To me looked like on Windows 7 (and 8 also BTW) Windows Explorer is falling back to NtQuerySystemInformation if it cannot find an IFileIsInUse entry in ROT. So I wrote a simple app (DumpROT.cpp) that searched the ROT for IFileIsInUse implementations and as I suspected when I run the app that keeps the "Test.txt" file open, RotDump fails to find any IFileIsInUse in ROT (it looks like even Libreoffice fails to register opened files in the ROT). Some other programs I've tested (including Visual Studio 2012) didn't registered open files either (see the output bellow):
The -verbose command line option instructs DumpROT to show all entries in the ROT irrespective to what these entries references.

As a last test I decided to run MS sample for this interface and voilá it does register an IFileIsInUse reference in the ROT for the chosen file!

This output was obtained by running DumpROT with the same set of opened files from the previous one (since I omitted the -verbose option the tool gave no feedback). Then I run it again, but this time with -verbose option; you can see in the output that no reference to IFileIsInUse was found in ROT.  Next step was to run FileIsInUseSample (the MSDN sample with some changes to accept a file path through the command line) and executed DumpROT again; this time you can see that DumpROT found an entry to "output.txt"  (the file passed to the sample app) in the ROT.

Unfortunately I don't have MS Office installed here to check whenever it takes advantage of this feature or not.

Happy coding!


Aug 8, 2013

I love my job ;)

I am so proud of being part of the team behind Unity (even if my contributions so far are really a tinny part of it - almost nothing ;)

I've joined Unity team 5 months ago and everyday I get impressed by how much they have achieved already.

Sure, as any other job, it has its "this task sucks" moments but most of the time I'm having fun and learning new stuff (and the developers / team mates are really supportive).

Thanks all for the opportunity. I am really happy working with such great people.

Happy codding.

Aug 3, 2013

Interesting tricks with value types in .Net

A while back I was pairing with a team mate hunting a memory allocation that should not be happing (it was not a leak but it was in a method called thousands of times per second and we do believed it was not required (or at least we should try to avoid it at all costs).

After some code inspection we nailed it down to a foreach loop, something as simple as:

var list = new List<int>();

// the code bellow allocates memory. 
foreach(var item in list)
Interestingly enough, when compiled against C# 3.5 / 4.0 compilers we could not reproduce this behavior; it was only when compiling on Mono 2.6 (on mono 2.10 it didn't happened).

After some investigation (and head banging) we found the issue; for reasons that I'll not explain here (basically to avoid gc allocations) the enumerator returned by List is a value type but it happens that in order to fulfill the foreach contract it also implements IDisposable. On .Net (at least on 3.5) it happens that the compiler completely avoids boxing this enumerator but when compiled with gmcs (the mono cs compiler) a box gets generated for the code that calls IDisposable.Dispose()! (see the code bellow):

     IL_0048: ldloc.2
     IL_0049: box valuetype [mscorlib]System.Collections.Generic.List`1/Enumerator< int32>
     IL_004e: callvirt instance void [mscorlib]System.IDisposable::Dispose()
     IL_0053: endfinally
Well, it happens that MS C# compiler (and newer mono ones also) emit different IL for that finally block:
     IL_004b: ldloca.s 3
     IL_004d: constrained. valuetype [mscorlib]System.Collections.Generic.List`1/Enumerator< int32>
     IL_0053: callvirt instance void [mscorlib]System.IDisposable::Dispose()
     IL_0058: nop
     IL_0059: endfinally
See, no box instruction. Instead of boxing, the compiler loads the value type address and then asks the runtime to handle that address as a reference to IDisposable.

Really interesting (at least IMHO)

Happy codding!

Aug 2, 2013

Getting Windows 8 on a Macbook Pro

I am typing this post on a new, shine Mac Book Pro with a retina display, a big SSD and lots of memory ;)

But instead of using Mac OS I decided to go through the bootcamp route and install Windows 8 (sorry, I cant't code in C# without Resharper anymore :)

Well, since this solution is an official solution (from Apple) I expected everything to go really smoothly and without any major issues (other than the Windows 8 ones... :). This was my first disappointment with Apple; first I tried 3 different flash disks (pendrive) but bootcamp just hangs without any information why (no one can blame Windows for this ;). Some times it just said "an error occurred while copying windows files to the flash disk" (or something like that). 

I even tried 2 different external hard drives with the same outcome. In the end I decide to do it the way the "pros" does, i.e, I manually created a bootable flash drive using a Windows 8 x64 image, used bootcamp to install it (but not to install the drivers) and as soon as Windows booted after the installation finished I downloaded and installed the bootcamp drivers manually.

Finally I had an working machine (hey, it is really fast) (moving from an old Q9400  to a new I7 machine makes a huge difference) and was happy... until trying to close the notebook lid (expecting to put Windows to a good sleep) and noticing it just turned the computer off. 

While googling trying to understand what went wrong I realized this is a relatively common issue with this setup (at least lots of people was asking similar questions in various online forums); the problem is that it looks like some device driver don't support sleeping. You can confirm this by running the following command in the command line:

powercfg -a

In my case I just got this:

The following sleep states are available on this system:
    Fast Startup

The following sleep states are not available on this system:
    Standby (S1)
The system firmware does not support this standby state.

    Standby (S2)
The system firmware does not support this standby state.

    Standby (S3)
The system firmware does not support this standby state.

    Standby (Connected)
The system firmware does not support this standby state.

    Hybrid Sleep
Standby (S3) is not available.

Notice the line saying the system do not support S3 sleep state; this is exactly the state the machine should enter when its lid is closed.. 

Later I found this joy in a FAQ on Apple site:

23. My Macintosh running Windows 7 or 8 does not sleep when a Thunderbolt device is plugged in.  Is this normal?
Yes. Sleep is disabled in Windows 7 or 8 while a Thunderbolt device is plugged in.
Well done! Anyway, it looks like I do have an workaround; do not use thunderbolt devices. I'll try.

What do you think?