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.

15 of 264 comments (clear)

  1. Maybe C developers are more honest by angryargus · · Score: 5, Insightful

    Regardless this seems like a pretty crappy study. There's many other phrases like kludge or XXX to have considered.

    1. Re:Maybe C developers are more honest by Anonymous Coward · · Score: 5, Insightful

      C developers are good enough to know when what they're doing is an ugly hack.

      If PHP developers were at the same standard, every line would end with // Ugly Hack.

    2. Re:Maybe C developers are more honest by dgatwood · · Score: 5, Insightful

      C developers are good enough to know when what they're doing is an ugly hack.

      If PHP developers were at the same standard, every line would end with // Ugly Hack.

      I think the reason PHP is #2 on the list is that the people who are still writing PHP are mostly pretty good. The ones who were awful have all moved on to Python or Ruby or whatever the scripting language of the week is these days.

      In fact, I'd be willing to bet that a sizable percentage of the folks who are still actively using PHP are C programmers. I use it for all my web programming because it is exceptionally easy for me as a long-time C programmer. I basically write C with dollar signs and a few other minor tweaks, and it works. Even better, if there's some piece of code that has to be blisteringly fast, I can port it from PHP to C faster than you can say sed 's/\$//sg'. Okay, it really isn't quite that trivial, but it is pretty close.

      And yes, I do occasionally take advantage of being able to mix PHP and HTML, but not very often. I mostly just use it as a compile-free web programming language with better string handling and basic support for classes.

      --

      Check out my sci-fi/humor trilogy at PatriotsBooks.

  2. There might be a bit more to it. by hamster_nz · · Score: 5, Insightful

    C coder know a ugly hack when they see one, and when they write one.

    I would conjecture that nearly every line of Perl scripts is an ugly hack, so nobody bothers to add a comment... 8-)

  3. The ultimate ugly hack? by hamster_nz · · Score: 5, Insightful

    Fast inverse square root (sometimes referred to as Fast InvSqrt() or by the hexadecimal constant 0x5f3759df) is a method of calculating x1/2, the reciprocal (or multiplicative inverse) of a square root for a 32-bit floating point number in IEEE 754 floating point format.

    http://en.wikipedia.org/wiki/F...

    Anybody got any better Ugly Hacks to share?

    1. Re:The ultimate ugly hack? by Anonymous Coward · · Score: 5, Insightful

      Duff's device

      C's default fall-through in case statements has long been one of its most controversial features; Duff observed that "This code forms some sort of argument in that debate, but I'm not sure whether it's for or against."

  4. Nonsense... by SlovakWakko · · Score: 5, Insightful

    The whole C language is one beautiful hack, scary at first but once you get to know it in some really messed up sw project you can't help but love it. The balance between freedom and structure is excellent.

  5. Only meaningful if weighted by blind+biker · · Score: 4, Insightful

    These numbers should be weighted to the amounts of code in the various programming languages on GitHub. There may be lots of C "codefiles" with the "ugly hack" string in them, but there probably is a lot of C code overall on GitHub, too.

    --
    "The agriculture ministry is not in charge of Gundam" - Japanese ministry official.
  6. Re:File this under "NO SHIT" by AmiMoJo · · Score: 5, Insightful

    Maybe the reason C has more is that the specific string "ugly hack" is more commonly used by C programmers. Languages like Javascript are really ugly and full of nasty hacks, but that's normal for them so no-one comments on it.

    --
    const int one = 65536; (Silvermoon, Texture.cs)
    SJW, n: "Someone I don't like, and by the way I'm a fuckwit" - AC
  7. Re:Such is C by ShanghaiBill · · Score: 5, Insightful

    C Code EVERYWHERE has the most "ugly hacks"

    Ah, but C also has the most beautiful hacks.

  8. Re:Low hanging hack... by chiasmus1 · · Score: 5, Insightful

    After looking at those examples, it seems to me that C programmers can claim something is an "ugly hack" because it was not what they wanted or because someone else's code was messed up. The C code hacks where there because they could not see an elegant solution. Programmers for other languages probably do not even know that the code they are writing is ugly.

  9. it's a C idiom by bugs2squash · · Score: 5, Insightful

    "/* ugly hack to... */" is a modest expression of pride describing concise, functional, readable and elegant C code in the same way as the term "//elegant approach to..." in C++ describes some borderline-insane misapplication of the STL with the incomprehensibility of perl and the verbosity of java.

    --
    Nullius in verba
  10. Re:File this under "NO SHIT" by someone1234 · · Score: 4, Insightful

    In this study, an ugly hack was determined by the string "ugly hack" appearing in code comments. It was a totally scientific study.

    --
    Patents Drive Free Software as Hurricanes Drive Construction Industry
  11. Re:Such is C by dgatwood · · Score: 4, Insightful

    C Code EVERYWHERE has the most "ugly hacks"

    C code is ugly hacks. But how else are you going to write an efficient ring buffer?

    --

    Check out my sci-fi/humor trilogy at PatriotsBooks.

  12. Re: Such is C by luis_a_espinal · · Score: 5, Insightful

    Is that really something to brag about?

    Yes. If you don't understand why, you have no place in engineering.