Git, PHP and C, with great power comes a great responsibility

Ver este artículo en castellano aquí

A few days ago I had the opportunity to share a conversation about version control systems with some colleagues, specifically about git, its complexity and the recommendation or not use them. A strong argument against said that git was a complex tool, which had a higher learning curve than others, that was very easy to make mistakes and that this mistake could mean a loss of data.

This made me think, and while it is true that git is a very powerful tool (with which I have a love-hate relationship for several years), the fact that a tool or language you allow certain liberties, does not imply that they are intended to be used always. Here is an example in this question of Stack Overflow:

http://stackoverflow.com/questions/1488753/how-to-merge-two-branches-without-a-common-ancestor

A -- B -- ... -- K -- L -- M1
                             \
                              M3 -- N' -- .. -- Z'
                             /
               I1 -- I2 -- M2 -- N -- .. -- Z

In this case we have 2 different branches without a common parent, which is a somewhat unusual case according to my (short) experience. Is it bad git for allowing this operation? No, should use an usual branching pattern? Either. In fact the majority of branches management patterns are based on having a /main branch as solid as possible, and have features, users or tasks into separate branches.

Another command that we have is rebase which allows us to rewrite the history of a branch, and integrate their changes in another branch, which may seem a genuine outrage for those who consider that a changeset is a permanent snapshot.

Git is not the only, since we have other tools and programming languages, that by design have allowed us to do certain things that have been heavily over-used:

PHP

The language that is the base of sites like Facebook, Yahoo, and Youtube has not been without controversy in the 18 years that has been on duty (since 1995). Looking for peculiarities of the language, I discovered that, among other things, PHP allows us to define globals from within a function as shown in the following code block:

function foo () {
    global $var;
    // rest of code
}

This breaks all the encapsulation and variable scope rules, that are studied on a standard programming course, and certainly its use has been harshly criticized, Is PHP a bad language by implementing this functionality? No, it is possible to find a specific scenario for this functionality, and then use the features provided by the language

C

The father, grandfather, and common ancestor of many of today’s programming languages and whose main book contains less than 300 pages (the famous K & R), has been receiving criticism since 1972. One of the most criticized features is, without doubt, the *goto** statement:

int big_function()
{
    int ret_val = [success];
    if([error])
    {
        ret_val = [error];
        goto end;
    }
    if([error])
    {
        ret_val = [error];
        goto end;
    }
end:
    return ret_val;
}

GoTo allows us to perform an unconditional jump to a portion of the file. To goto detractors state that breaks the flow of execution of a program and that can be a source of errors and hinders readability. On the other hand, it is useful in side scenarios, such as the Elimination of recursion.

Recap

In the same way that we should not use the same tool for all (golden hammer anti-pattern) we must be aware of the peculiarities of the language, and that what it gives us, it provides with a specific reason, not necessarily applicable to all scenarios.

Remember Uncle Ben when using one of these tools and languages:

Uncle ben

With great power comes a great responsibility

More information and interesting articles

And you, what curious things have you spotted in your favourite programming language or tool?