Popular Code Conventions on GitHub

code, open source, github 0 comments suggest edit

The first GitHub Data Challenge launched in 2012 and asked the following compelling question: what would you do with all this data about our coding habits?

The GitHub public timeline is now easy to query and analyze. With hundreds of thousands of events in the timeline every day, there are countless stories to tell.

Excited to play around with all this data? We’d love to see what you come up with.

It was so successful, we did it again this past April. One of those projects really caught my eye, a site that analysise Popular Coding Conventions on GitHub. It ended up winning second place.

It analyzes GitHub and provides interesting graphs on which coding conventions are more popular among GitHub users based on analyzing the code. This lets you fight your ever present software religious wars with some data.

For example, here’s how the Tabs vs Spaces debate lands among Java developers on GitHub.

java-tabs-vs-spaces

With that, I’m sure nobody ever will argue tabs over spaces again right? RIGHT?!

What about C#?!

UPDATE: JeongHyoon Byun added C# support! Woohoo!

Sadly, there is no support for C# yet. I logged an issue in the repository about that a while back and was asked to provide examples of C# conventions.

I finally got around to it today. I simply converted the Java examples to C# and added one or two that I’ve debated with my co-workers.

However, to get this done faster, perhaps one of you would be willing to add a simple CSharp convention parser to this project. Here’s a list of the current parsers that can be used as the basis for a new one.

Please please please somebody step up and write that parser. That way I can show my co-worker Paul Betts the error of his naming ways.

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.

Comments

avatar

17 responses

  1. Avatar for xpaulbettsx
    xpaulbettsx September 17th, 2013

    I never debated that the ReactiveUI coding style is *popular*, only that it is the Ineffable, One True Way to write C# code. Other ways may *exist*, but they are like simple Caveman scratching compared to the beautiful script of the ancient Elven Tongue, Tengwar ( http://en.wikipedia.org/wik... ).

    :trolleybus:

  2. Avatar for n/a
    n/a September 18th, 2013

    4 spaces for 1 tab. That seems about right.

  3. Avatar for Ian Barry
    Ian Barry September 18th, 2013

    With C# code conventions I think that to a degree, coders who may have started with a dynamically typed language like javascript over a static typed language like C# would prefer coding conventions for example: curly brace with a space or without a space as opposed (seen often in javascript) to those who started with C# who would from my experience have a curly brace with a new-line, or is that just me...?

  4. Avatar for James Curran
    James Curran September 18th, 2013

    Funny thing comparing the Java & Javascript results:

    In many categories (notably Tabs vs Spaces, but others as well), the "more characters" option is more popular in Javascript than Java. IOW, people who write in a interpreted language -- where source code size actually matters -- prefer coding styles which lead to larger source files.

  5. Avatar for sosiosh
    sosiosh September 18th, 2013

    The problem with a lot of conventions is that they are adopted out of personal preferences, while the goal of all the conventions is a common language to increase the comprehensibility (is that a word?) of the code for the benefit of OTHER developers. And the only thing in any of these religious wars that actually can adapt to an individual's personal preferences is that tabs always look the way BOTH the reader and the writer of the code want. When looked at through the lens of coding style increasing readability, tabs wins the logical argument over spaces. Every. Single. Time.

  6. Avatar for Kevin Whalley
    Kevin Whalley September 18th, 2013

    Can the StyleCop parser / engine be used to speed this along?

  7. Avatar for devtools.korzh
    devtools.korzh September 19th, 2013

    Yeah, writing a parser would be great. Thanks for highlighting!

  8. Avatar for Matthew Whetton
    Matthew Whetton September 19th, 2013

    That sites great - I'm really surprised at how even the all caps for constants category is (for java). I wonder how much the tabs vs spaces results are effected by IDE default settings?

  9. Avatar for David De Sloovere
    David De Sloovere September 25th, 2013

    For C#, StyleCop was the first thing that came to mind. My team uses it and I couldn't code without it anymore. It takes some time to get everybody on board, but it pays off. I think it also follows the 'Framework Design Guidelines'.

    So we've got this great tool, but I don't know why not everyone is using it.
    Maybe because it's a plugin (and only for Visual Studio) and most people don't know about it? (Although I can be added to the build process easily.)

  10. Avatar for haacked
    haacked September 25th, 2013

    The last time I used StyleCop (admittedly it was a while ago) you couldn't tweak the rules.

    > It takes some time to get everybody on board, but it pays off. I think it also follows the 'Framework Design Guidelines'.

    The Framework Design Guidelines pertains to the public API design of your code and not how the curly braces are laid out etc.

    I believe the team put out some recommendations on code style somewhere, but not even the teams within Microsoft all followed one coding style.

    If StyleCop let me tweak the rules to fit my organization's thoughts, I'd be totally down for it.

  11. Avatar for Christopher B. [christb@MSFT]
    Christopher B. [christb@MSFT] September 25th, 2013

    This comment has forever changed the way I write code. Indeed, my own eyes, my lens into this world, has been altered in ways unimaginable.

  12. Avatar for tai game chien thuat
    tai game chien thuat October 18th, 2013

    tai
    game chien thuat mien phi
    để thỏa sức thể hiện, tai game chien
    thuat mien phi
    cực hấp dẫn

    tai game chien
    thuat mien phi
    tại đây nhé

  13. Avatar for Love Angels
    Love Angels November 14th, 2013

    However, to get this done faster, perhaps one of you would be willing to add a simple CSharp convention parser to this project tai facebook mien phi

  14. Avatar for Love Angels
    Love Angels November 14th, 2013

    tai facebook ve dien thoai CSharp convention parser to this project

  15. Avatar for Love Angels
    Love Angels November 14th, 2013

    code web is c sharp ? tai facebook cho dien thoai

  16. Avatar for Love Angels
    Love Angels November 14th, 2013

    If StyleCop let me tweak the rules to fit my organization's thoughts, I'd be totally down for it. tai facebook ve dien thoai java

  17. Avatar for Alpheus
    Alpheus March 27th, 2015

    One thing I'd like to know (and one thing that would probably be difficult to measure) is how many developers prefer so-called "smart tabs": basically, using tabs for indentation, and spaces for alignment.

    For example, if I were declaring a class method, I would indent the function, and if the arguments continued on to the next line, I would tab to the indentation level of that function, and then put spaces to align the next arguments. Similarly, if I'm aligning end-of-line comments, I would use spaces, and these would remain constant, regardless of tab size.

    This format allows individuals to specify their tab sizes to their heart's content, while preserving alignment! I also like how making tabs visual also illustrates the alignment of the code.

    Now, having said this, I would also have to point out that this table should be taken with a grain of salt: while I prefer "smart tabs", in practice, I usually use spaces, because that's what's required by the coding standards of the organization or project I'm working on.