Living in the Tech Avalanche Generation

A practitioner’s introspective on technology

Using Ruby Naming Conventions in C# code? Is that madness?

During my journey in learning Ruby / IronRuby, I have caught myself often naming things in C# with a Ruby convention or BDD test naming regime. To be extreme here’s an example:

var customer_to_make_preferred = Get_Customer_By_Id<ICustomerMakePrefered>();

//OR METHODS LIKE THIS

public void Group_By_Orders_And_Print_To_Console_Window()
{
    //…..etc
}

I really find a benefit in greater understanding when reading code when I take this approach. Now it’s true I have been programming in C# for some 10 years and I don’t know if this kind of behaviour will see me excommunicated from the circle of brethren or not but I would like to know what others think.

Opinions please! And yes I know this is gonna be like waving a red flag in front of a raging bull :). And for the Ruby people, I am only proposing the extended underscored naming convention and nothing else – it’s all about naming and that’s it – ya basta!

Share/Save/Bookmark

6 Comments so far

  1. Steve June 10th, 2009 6:44 am

    Looks like two functions needed:
    Group_By_Orders
    Print_To_Console_Window

    I think naming conventions should be “universal” and not based on just a particular language

    [Reply]

  2. Simon Segal June 10th, 2009 7:35 am

    Hi Steve

    Yep agree on the functions of course. If naming conventions were indeed universal which ones would you prefer? My colleague Mark happily accepts naming tests (whether they be BDD / TDD or plain old unit tests) with this scheme but warned me that he despised the idea for method scoped variables. Moments later he noted that it was something that he probably objected to simply out of established habits and not for any practical reason.

    [Reply]

  3. Simon Segal June 10th, 2009 7:54 am

    I should probably add that I have found this naming convention useful when doing proof of concept work on internal DSL’s with C#. For example:

    NorthwindLangQuery
        .BeginQuery()
        .Customers()
        .With_An_Id_Equal_To(“ALFKI”)
        .With_Orders_Shipped_From(“Germany”)
        .That()
        .Are()
        .Older_In_Years_By(2)
        .EndCustomerQuery()
        .Flatten_And_Print_To_Console_Window();

    [Reply]

  4. Mark Harris June 10th, 2009 9:40 am

    Simon,

    “despised” is rather a harsh word. I guess that if naming is something that was universal then this would not be something to debate.

    IMHO it comes down to readablitiy and how well the name of the variable/method etc give the people who will be charged with understanding what i have done.
    I know can read

    public void Group_By_Orders_And_Print_To_Console_Window()
    {}

    just as easily as i read

    public void GroupByOrdersAndPrintToConsoleWindow()
    {}

    and to me there is no difference in my understanding of the intent of the method.

    [Reply]

  5. Simon Segal June 11th, 2009 12:14 am

    Mark

    I think my brain finds the underscore somewhat like a whitespace in this regard and hence my preference.

    [Reply]

  6. Steve June 12th, 2009 6:46 am

    I’m fine with that naming scheme for tests - I use that as well :)

    [Reply]

Leave a reply

Creative Commons Attribution-ShareAlike 2.5 Australia
Creative Commons Attribution-ShareAlike 2.5 Australia