Hacker News new | past | comments | ask | show | jobs | submit login
What happens when you search 'ugly hack' in GitHub (github.com/search)
73 points by BaltoRouberol on July 17, 2014 | hide | past | favorite | 68 comments



I love the term 'ugly hack'. It's a very short way of saying 'a solution for a problem that assumes too much of the current context in which this component is called, and is guaranteed to break when the context changes'. It also implies 'this is intended to be temporary because I don't feel like doing the proper solution at this moment' which is accompanied with the intent 'we should fix this later' although most people who write it also have the wisdom that that almost never happens.

All of this is expressed in just two words :)


When I write it it usually means I know it sucks, but I'm reasonably happy with it - but if someone catches me out on it it's ok because I already criticised it myself


Excellently put. It's like lampshading[1], for code.

[1]: http://tvtropes.org/pmwiki/pmwiki.php/Main/LampshadeHanging


In my experience “ugly hack” means any technical debt that spans lines of code, as opposed to components of a system.

(Edited for clarity.)


It's actually too general. What I mean with component here can be anything from a line of code to a class hierarchy.

In a sense, using the word 'component' here was an ugly hack. I should have gone for the proper solution and properly define it. You see now that it breaks down when the interpretation changes.


I guess I understand. I objected because I felt you were assuming too much of some context in your definition of “ugly hack” :) I can't imagine using the term “ugly hack” to describe some unfortunate high-level architectural decision.


It's a worthy practice indeed. Bowing to the virtue of taking on some technical debt instead of deluding oneself that all code must be Pristine.


Sometimes, instead of "I don't feel like doing the proper solution," it's "I haven't yet figured out the proper solution," or "A cleaner solution means adding 250 lines of code to address problems we may not have."


'Ugly hack' is an ugly hack of 'kludge'.


Some results normalized by overall language popularity. Specifically, the entry in row R and column C is 1000 * (hits for C in language R) / (hits for "the" in language R) or "---" if either the numerator or denominator was small enough not to make the top-10 list on github.

All the scraping was done by hand and the numbers rounded to a limited number of places in the process, so there may very well be mistakes.

[EDIT: oops, initially I failed to paste in the actual data.]

       ugly hack      ugly beautiful       lol       wtf     buggy
   xml       ---       ---    14.330    72.775     2.489       ---
     c     6.348    35.421     0.670     0.768     3.650    32.009
  html     1.359     9.001    34.791     4.233     3.095     5.870
    rb       ---       ---       ---     4.483     3.151       ---
    py     9.051    35.614    28.506       ---    11.135    15.066
   php     3.731     8.333     1.781    39.037     1.792     3.754
   c++     2.851    12.507       ---     0.501   102.657     7.579
    js     6.850    16.826     2.643     2.635     7.406    29.761
Tentative conclusions: Python is ugly-hack-iest and (almost exactly tied with C) ugliest; HTML is most beautiful with Python a close second, XML is lolliest, C++ is WTFiest, and C is buggiest.

Tentative meta-conclusion: these numbers have no value beyond idle amusement. But they idly amused me, so that's OK.

(The weirdest result of the lot, to me, is XML coming top for "lol". If you do the search and click on "XML" on the left you'll see why it is. Lots of instances of what I think are the same file, full of "&lol;" entities. LOL, that's pretty ugly. WTF? An ugly hack, I guess.)


The &lol; entities are the "Billion laughs" attack: http://en.wikipedia.org/wiki/Billion_laughs


bwhaha that's insane


I read your table and immediately jumped to a different conclusion: That python programmers are more sensitive to ugly hacks and more likely to call them out. Not saying I'm right, but I don't know that the data can distinguish the hypotheses.


Not picking a language fight.

My intuition tells me that if your alternative hypothesis were true, then php programmers have higher standards because they ajudge more code 'ugly and C++ programmers are universally perfectionists...or at least when they are not confused which it appears they usually are.

Just for fun with hypothesizing, does Python's near 50/50 split between 'ugly and 'beautiful suggest a large degree of random use? Or more interestingly, does it suggest there is a tendency to classify middle cases as extreme cases, and is this a result of the community having 'a Pythonic Way?'


I immediately felt the same and left a comment. But what would distinguish it is if "Go" had a high proportion of such comments, where "Perl" would have a low one.


Could .py have the greatest number of "ugly hacks" because the community's standards for explicit, "beautiful" designs is higher? This would be shown if languages like Go have a much higher prevalence for "ugly hack" than a language like Perl. (Where even core language features, ahem you can complete the thought.)


I literally laughed out loud at C++ in wtf column.


There is a namespace in C++ called WTF, which probably accounts for a skew in that column.


There is a library in C++ called Web Transaction Framework(WTF): https://github.com/belzano/WTF




If you actually look at the details, these terms aren't used in the same context as we might imagine. If there was a way to filter out useless projects, this would get interesting.


As you said, big grains of salt... It would be probably more helpful if they were normalized by the percentage any particular language is used overall on Github.


So, HN's hate-child PHP is funnier, more beautiful, less ugly and less confusing than sexy JavaScript. Although Python rules them all.


To be fair, PHP has a well-known problem of a lot of people not being able to properly judge the quality of the code they write ;) [1]

[1] Of course I don't mean you, my dear PHP writing comment reader.


And no other widely used language has that problem ;)


Python seems to get a leg-up on the beauty stakes thanks to the popularity of the BeautifulSoup library :)


I love this one - someone made Java annotation for ugly hacks: https://github.com/benpage26/libxron/blob/016dd953a54eacada2...


That is some real dedication the the Java way.


"Fix ugly hack to at least be consistent with itself", haha, this is brilliant.


I'd be curious to see if there's a relationship between 'ugly hack' in code commits and the languages being used (though it'd probably say more about the programmer than the language). The bar chart on the left of the page hints that it's possible, but would have to be normalised.

My hypothesis is there'd be no real difference, but it would be fun to explore nonetheless.


I would think the left bar would remain accurate. C lets you shoot yourself and people do it. PHP is terrible for a lot of well documented reasons. Javascript is being used for things it originally never envisioned.

The hyped dynamic languages sort of surprise me, with their modern APIs. I'm guessing most of that is poor framework programing.

Finally, Java's numbers? lol. Its a brave new world. If this was 8 years ago in ejb v1.2 Java world have taken the crown.


> I'd be curious to see if there's a relationship between 'ugly hack' in code commits and the languages being used

Perl is not in their list.

Either everything we do is an ugly hack, or everything we do is simple and elegant. :)


Or... nobody writes in Perl anymore... or... every Perl developer is a seasoned Perl developer.


Welp, neither of those are true.


Another fun search on GitHub - looking for the code paradox i.e. this should "never happen".

https://github.com/search?l=c&p=7&q=never+happen&ref=searchr...


Amusingly, a lot of Python's hits appear to be hacking the import logic.

[0]: https://github.com/search?l=python&q=ugly+hack&ref=cmdform&t...


It looks like ugly hacks are far more popular than clever ones.

https://github.com/search?q=clever+hack&type=Code&ref=search...


Look for dirty hacks; still... C way ahead the rest.

Interesting that "ugly" places PHP over Javascript, but "dirty" is the other way around.

I wonder what does it mean. The comments and the "ugly" or "dirty" qualifiers are just part of the perception of the person writing the comment, and they're contributing to spread that perception to others.

What qualifies as "ugly", "dirty" and "clever", or even as "hack", may be quite different depending on the language and the community behind it.


Yeah, I don't think "ugly hack" or any other variants is frequent in bash script comments.


because "ugly hack" is a warning to however might want to fiddle with it, clever hack is more just a show off.


That, and ugly hacks are easier. I was only kidding. :-)


Haha:

https://www.dropbox.com/s/j7rwshax2e9zwln/Screenshot%202014-...

Not even PHP can come within a factor of 5 of C when it comes to ugly hacks.

EDIT: And its not exactly like there is a bias at work: http://goo.gl/ZezFiP


But is it because C programmers make more ugly hacks or that C programmers are more likely to know when they are making an ugly hack?


I think PHP is more or less just for the web, giving C programmers more ugly hack surface overall.

Also PHP itself is an ugly hack of C anyway.


There is a bias because there is more C code. The number of repositories doesn't equal to the quantity of code and if you search for general things that are used in both languages frequently then there is always more C results, for example:

https://github.com/search?p=1&q=if+&ref=searchresults&type=C...

https://github.com/search?p=1&q=return+&ref=searchresults&ty...


Fair enough. If there is a bias towards C I would guess it was more due to the situations in which C gets used, than C itself. Talking to a friend who has to try and get the same C/C++ codebase to compile for 6 different platforms (consoles) has been an eye opening experience. That kind of environment is like a slightly warm petri dish for ugly hacks.


Search for "temporary fix" https://github.com/search?q=temporary+fix&type=Code&ref=sear.... 3 million plus and counting :)


That also matches with just "fix" or "temporary". This one works better: https://github.com/search?q=%22temporary+fix%22&type=Code&re...

Now to figure out how old these are.




I was not surprised to see tex (even though it is not a popular language on GitHub). It seems that one have to resort to (ugly) hacks when dealing with it.

(That said, I love its fruits.)



A modern-day batman might do this search and then submit pull requests which fix the "ugly hacks".


it's even better when you search for "temporary hack"

https://github.com/search?q=temporary+hack&type=Code&ref=sea...


Simple question: does "ugly hack" mean "a quick fix before relase" ?


It usually means that something out of your control is acting strange and you don't know or can't properly fix it, but you have found a weird workaround that should probably not even work, or an very contrived way to achieve the result.

As one obviously only writes extremely elegant code, it is important to notify the programmer coming after that you were forced to write it this way.


I love how Ruby isn't even included in the list. RUBY THE BEST


No ugly hacks in ruby! that's a great news.


Surprised CSS isn't on the top of this list


400k results for C, the next one is 40k for PHP


Looks like Ruby doesn't have ugly hacks.


How about 'for now' :D


Wait...you mean...I find the words "ugly hack" in source files across thousands of projects on GitHub?


I have no idea why this is on the front page.


fun? meta-programming?


You and I have a very different definition of fun, and meta-programming.


Mostly C!




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: