Slashdot Mirror


C Code On GitHub Has the Most "Ugly Hacks"

itwbennett writes: An analysis of GitHub data shows that C developers are creating the most ugly hacks — or are at least the most willing to admit to it. To answer the question of which programming language produces the most ugly hacks, ITworld's Phil Johnson first used the search feature on GitHub, looking for code files that contained the string 'ugly hack'. In that case, C comes up first by a wide margin, with over 181,000 code files containing that string. The rest of the top ten languages were PHP (79k files), JavaScript (38k), C++ (22k), Python (19k), Text (11k), Makefile (11k), HTML, (10k), Java (7k), and Perl (4k). Even when controlling for the number of repositories, C wins the ugly-hack-athon by a landslide, Johnson found.

4 of 264 comments (clear)

  1. Low hanging hack... by x0ra · · Score: 5, Informative
    Did any of you actually read the "ugly hacks" this is pretty low hanging stuff, not the evil pointer-arithmetics and language corner undefined behavior case type of hack...

    #ifndef __INCif_etherh /* Quick and ugly hack for VxWorks */

    // ugly hack because we don't have fscanf
    int fscanf(FILE* stream, const char* format, int* value)

    #else /* ugly hack to make it compile on RH 4.2 - WA */
    #include
    #endif

    /* ugly hack GRR */
    #if !defined(__GNUC__) && !defined(__common_include__)
    #define __attribute__(x) /* nothing */

    /* XXX argh, ugly hack to make stuff compile! */
    #define snprintf(BUF, SIZE, ...) sprintf(BUF, __VA_ARGS__)

  2. Re:Such is C by Darinbob · · Score: 5, Informative

    I think the key difference here is that when someone uses C they want efficient code to some extent. Small, or fast, or both. In other languages the culture is often "do it in the method approved by the sacred elders", and so ugly hacks may be forbidden and the slow/bulky method is preferred, according to the mantra "do not reinvent the wheel because thou are not as wise as the wheel builder". Or the presence of an ugly hack implies that the novice must clearly have been prematurely optimizing, for as the wise men say tomorrow is too soon to optimize.

    For example in Python the claim is that there's almost always only one way to do something, which either means ugly hacks are not possible, or else there's a lack of imagination amongst the programmers.

    The higher level a language is, the more it seems that the goal is to get stuff done fast rather than efficient or elegant.

    Finally, I have actually seen cases where code is labeled an "ugly hack" when it really wasn't a hack at all but rather not as tiny or or elegant as the author wanted.

  3. Re:Maybe C developers are more honest by mwvdlee · · Score: 5, Informative

    https://github.com/search?utf8...
    Javascript wins.

    PHP developers prefer murdering kittens: https://github.com/search?utf8...

    Some other fun facts:
    C developers are most ashamed of their code: https://github.com/search?utf8...
    PHP coder don't fix bugs: https://github.com/search?utf8...
    C developers' code actually get worse as it ages: https://github.com/search?utf8...

    Java developers seem to have the most trouble getting their code to work: https://github.com/search?utf8...
    Not surprising: https://github.com/search?utf8...

    Disclaimer; not corrected for any type of bias or error, of which there are many.

    --
    Slashdot social media options: AIM, ICQ, Yahoo, Jabber and Mobile Text. Why no MySpace?
  4. Re:File this under "NO SHIT" by gstoddart · · Score: 4, Informative

    Honestly, for some of us "hack" means anywhere from "an inelegant but necessary workaround", to "a really awesome and unexpected use of something", to "defeating system security", or a clueless person bashing away at something they don't understand, or "something I just whipped up".

    GP is absolutely correct ... for many of us, "hack" is a very generic term.

    --
    Lost at C:>. Found at C.