Awkward C++ null pointer usage

I have found similar code to this on Elance, during a C++ test.
This amuse me a bit as I found it quite awkward.
This code below is from this question on StackOverflow


#include <iostream>

struct foo
{
    void bar() { std::cout << "gman was here" << std::endl; }
    void baz() { x = 5; }

    int x;
};

int main()
{
    foo* f = 0;

    f->bar(); // (a)
    f->baz(); // (b)
}

Posted in programming | Tagged | Leave a comment

Some lessons learned during my job hunting with IT companies

As a developer writing source code generally means to create lines of code and then continuously find bugs and fix them in an iterative process of refining the software.
Looking for a job is not that different: you learn from mistakes and try to cope with them!
Here are some suggestions I have learned recently after having been refused by a big US company and after having accepted an offer from a UK company, which I ran away from after a terrible first day at work.

  • Never use sales technique guidelines such as “How to handle two different offers” or “What to say when the interviewer asks you if you have any questions“.
    It is still ok to know these techniques, but the truth is that your hiring manager is probably a PhD guy with several years of experience, with a QI above the average and surely with many interviews behind.
    He/She is surely very intuitive and with a mindset used to recognise patterns of behaviour.
    Your hiring manager surely knows if you are using a sales techniques because he/she has already read (and criticised ) these kind of articles and books and, although appreciates that there are common behaviours among people, he/she knows that every person is unique and might find awkward that an intelligent candidate (you) uses these techniques as many others.
    I believe that this is even more true when you try to apply for more senior positions.
  • It is not recommended to give deadlines to big companies without being open with them.
    If you have a good offer from a not so known company but still have a pending hiring process with, let’s say, a big US corporation of >10k billion of capitalisation, please do not make the same mistake I did of putting pressure on the big company saying, for example, that the other offer has a deadline.
    The reality is that big companies are flooded with CVs of smart candidates and if you are lucky to pass the first interviews there is no way you should ask to be quick. They will give your job to another candidate, because they can choose and have time (since their projects have a longer term perspective), you commonly cannot.

    If you really want to tell them that you have another offer, I might suggest to openly reveal the salary package and simply tell them the honest truth (even suggesting them the company is ok in my opinion). Big companies tend to have the smartest people in every department and they know what tricks the candidates are used to play.

  • Try to fully understand the vacancy you are apply for. FULLY.
    In your career it might happen that you get a good offer from a growing company which seems really to like you and they immediately want you on board.
    This is really great, but please pay attention to the requirements of your vacancy and ASK what you will be doing during the first day at work and WHO will you introduce you in understanding the technology of the company.

    Recently I accepted an offer from a UK company who told me to join  as soon as possible.
    I thought that I knew everything about the company, but when I had my first day at work I was left without a workstation until the late afternoon (someone forgot to buy a new workstation) staring at my white desk for hours without the minimal interaction with any member of my team (sometime people have different character from yours, but this is not important, it is not really the point).
    As I had found out later, it seems that my “manager” (or better the person who should have introduced me to the technology) was sick. The awkward point is that I have never met this guy before,and I thought that my direct manager would have been one of the guys who interviewed me.
    I did not know that there was another guy in the middle to report to somehow and nobody in my small team actually knew what I had to do, because the person deputed for that was simply not there.
    At some point I felt that the company hired me to be part of the team, but without a clear responsibility to assign to me. They knew that they needed developers, but, as this was a growing and with busy developers startup, I felt that the no one had really the time to give me a specific task.
    It was simply my fault because, excited by the offer and the technology, I had not asked what I would have done on my first day, what would have been my specific task in my small team and who should have instructed me at the beginning, even for only 10 minutes.
    Do not make my same mistakes!

Posted in Uncategorized | Tagged , | Leave a comment

How to learn C++

C++ is surely the most challenging programming language to learn, probably because it is also the most flexible and generic as you can use it for low level (embedded) and high level development.
Recently a new standard has come out and there are a lot of new interesting techniques which makes our lives easier, but the main concepts of C++ development are still valid.
Here are some suggestions to learn C++ quickly, especially if you come from another programming language (if you are a totally newbie to the Computer Science you’d better buy an introduction book).
This is a working progress list, as there is always something to learn with this language.

  • Adhere to a coding style such as the Google C++ Style Guide
    Every company out there has a coding style, a way to write the source code nicely. Following some strict rules seems a bit boring at the beginning, even restricting your creativity.
    Instead, it is a way to make the source code easier to read (we will read the source code of that function much more often than the time we have spent in writing it!).
    Understanding and use the coding style will make easier to put in practise the several options that you have when writing source code; you will understand, for example, what are the advantages of using or not using exceptions, what are the advantages of using references as input parameters, where to your const, etc.
  • Watch Youtube videos of (or attending) CppCon.
    CppCon is the main C++ conference and listening to the invaluable hints and ideas of the major C++ developers in the world is definitely the best way to speed up your learning process. These people are not only very smart but also very good speakers: you’ll learn quite a lot just watching 1 hours of their videos and then reading the related slides. It’s really an effective way if you do not like reading books.
  • Use a good compiler, enable and pay attention to ALL warnings.
    Clang is my favourite compiler at the moment, it gives you a lot of nice messages and it really helps you to understand all your mistakes.
    Paying attention to every detailed message is a bit of work at first, but in the long term it really pays off as you will start writing much more reliable code after you have understood why the compiler is complaining.
  • Read the right books!
    The C++ community is quite huge, but there are people really great and somehow the fathers of the language.
    You should not waste your time in the first tutorial for dummy: go straight to learn C++ from the people who have created, taught, forged in its standard and used in commercial environment.Here is my list:
    A Tour of C++ – Bjarne Stroustrup
    This is a quick but complete introduction on what you should know to be considered a good C++ programmer.

    Effective C++ – Scott Meyers
    This is one of the best and most common book among the developers: it simply tells you what is the best thing to do among all the possible solutions.
    This book is becoming a bit oldish as it is not updated to the recent standard, but its techniques are still effective and used worldwide (sure compilable!).

    Effective STL – Scott Meyers
    Knowing STL and its containers is basically compulsory when you use C++. This book helps you in understanding what is the best structure, algorithm to use at a given point in your source code. In my opinion in working with structures and algorithms you will gain a kind of attitude which makes you try to find the best solution for a problem.

    The C++ Programming Language – Bjarne Stroustrup
    This is a complete guide of C++. It is more a reference book than a tutorial but it is complete. Stroustrup is clearly a scientist and you can see that every detail of C++ is clearly analysed here, although sometime you feel that the book is overwhelming.
    It is so complete that includes the C++11 standard as it is quite a recent book.

    Effective Modern C++ – Scott Meyers
    This is a really new book, which I have bought it as an online version before the final paper release. It gives you a perfect idea of the ways of working with the new C++11: it is probably the first attempt to write a book only focused on this and then it may seem a bit too “futuristic”, as many features of the standard are still not common around (but look at Facebook for example).

Posted in programming | Tagged , , , | Leave a comment