"Hello World!" as a tool for evaluating programming skills

    Assessing the level of professional skills of a programmer is a very difficult task. Everyone solves it in their own way: someone offers the candidate to take a very voluminous test, consisting of a thousand questions, someone offers to solve a very difficult task right away, etc. These approaches have a right to exist, but at least they require a lot of time. Usually you need to quickly assess the level, then the easiest way is to offer to solve a very simple problem in the programming language of interest. I propose using the program with which the study of any language begins - “Hello world!” As such a task.
    On the one hand, this is a very simple task, but on the other, as practice shows, even it is at the same time very difficult. Let us consider in detail what options for solving this problem are written by real people and what they show.
    Option 1 is the correct program that works with an error.
    #include 
    void main()
        {
        printf( "Hello, world!" );
        }
    


    What is wrong here? The text is displayed in the console, the program seems to work ... But, remember, in the context of the operating system, any program returns an exit code. This code (you need to remember the assembler) is stored in the eax register (on a 32-bit platform to be completely correct). In the example above, we do not put anything in this register, but the operating system does not change the logic of its work. Therefore, most likely some garbage located there will be interpreted as the result of the work of our program. And since this is most likely (99.99%) not a zero value, this means that our program ended in error.
    Here is the “right” option from the point of view of the operating system:
    #include 
    int main()
        {
        printf( "Hello, world!" );
        return 0;
        }
    

    In the penultimate line, we return 0 as the result of work - everything is successful.
    We go further, it’s better, but still there is something to improve. We look at the line with the output of the line to the console, there is a reason for a comment from the compiler - unsafe output. Here is a safer option:
    #include 
    int main()
        {
        printf( "%s", "Hello, world!" );
        return 0;
        }
    

    I think this option is understandable without explanation (for the rest it will not be difficult to find an explanation in Google).
    It seems that the last option cannot be improved, or not? What are the suggestions? As you know, a program without comments costs nothing, so maybe they are missing just them or not? I believe (and not only me alone) that a comment is also needed here, but which one? What to comment on and how to prevent butter butter. They write computer-readable programs at school in the 9th grade (or even earlier), but sometimes they don’t even write programs that are understandable to a person even at university.
    Here is an example program with comments (i.e., documented) in the style of the Doxygen self-documenting system.
    ///@file hello_world.cpp
    ///@brief Учебная программа, выводящая в консоль приветствие «Hello, world!».
    ///@author idimm 
    #include 
    ///@brief Главная функция, непосредственно выводящая в консоль приветствие. 
    int main()
        {
        printf( "%s", "Hello, world!" );
        return 0;
        }
    

    Some explanations - this code contains minimal information at the file level (who is the author, version, general description) and at the function level (what the function does). This example shows that even such a program can contain valuable comments.
    But this is not the last option. Let us need to display a greeting in Chinese, how to do it? Firstly, it can be implemented in various ways, and secondly, it will require additional knowledge about working with character data (strings). I will not give an example of solving this problem, but it is not as simple as it seems. I recommend doing it yourself.
    Thus, even the simplest task can tell a lot about programming skills.

    Also popular now: