Sunday, July 25, 2010

Who Cares? (Software Craftsmanship - Meeting 2)

I dare to say WE DO... WE CARE !!!

This Wednesday (on 21.07.2010) we had a second Software Craftsmanship meeting.

More than 50 "hungry" software craftsmen came to share their knowledge and practice their software skills.

We reviewed bad code, identified Code Smells and suggested how to improve it.

It is well known that the best way to communicate between Software Professionals is to write and read code together. Therefore we WROTE code in Dojo Style.

I am really excited to see such a community that truly cares about its craft.

If you thought there are none like you, think again...

It doesn't make any difference what type of technology you are using; There are solid Software Principles that are universal and a technology is just one of the tools you should know how to apply.

It's really up to us...

If you are for clean, maintainable and readable code, professionalism (craftsmanship over crap, [also here]) and thorough knowledge, then your place is with us.

Join our group, come to our sessions (every ~1.5 months), share your knowledge and resharpen your skills.

Here are the slides from the meeting.




In addition, you can also find below, my suggestion to the Roman Numeral exercise we did.

(Actually, I can refactor the solution even further, but in the real world scenario I think such a solution will be an overkill).
public class ShortRomanNumeral
{
    internal struct RomanMapper
    {
        public int Value { get; set; }
        public string Presentation { get; set; }
    }

    private const int MinShortRomanValue = 0;

    private const int MaxShortRomanValue = 3999;
    private const string zeroRomanPresentation = "Nulla";

    private readonly RomanMapper[] shortRomanMappers = 
    {
        new RomanMapper(){Value = 1000,  Presentation = "M"},
        new RomanMapper()Value = 900,   Presentation = "CM"},
        new RomanMapper(){Value = 500,   Presentation = "D"},
        new RomanMapper(){Value = 400,   Presentation = "CD"},
        new RomanMapper(){Value = 100,   Presentation = "C"},
        new RomanMapper(){Value = 90,    Presentation = "XC"},
        new RomanMapper(){Value = 50,    Presentation = "L"},
        new RomanMapper(){Value = 40,    Presentation = "XL"},
        new RomanMapper(){Value = 10,    Presentation = "X"},
        new RomanMapper(){Value = 9,     Presentation = "IX"},
        new RomanMapper(){Value = 5,     Presentation = "V"},
        new RomanMapper()Value = 4,     Presentation = "IV"},
        new RomanMapper(){Value = 1,     Presentation = "I"}
    };

    private readonly int value;
    private readonly string presentation;

    public ShortRomanNumeral(int value)
    {
        if (value < MinShortRomanValue || value > MaxShortRomanValue)
        {
            throw new ArgumentException();
        }
        else
        {
            this.value = value;
            presentation = CalculateRomanPresentation();
        }
    }

    private string CalculateRomanPresentation()
    {
        if (value > 0)
        {
            return NonZeroRomanPresentation();
        }
        return zeroRomanPresentation;
    }

    private string NonZeroRomanPresentation()
    {
        int currentValue = value;
        StringBuilder presentation = new StringBuilder();

        foreach (RomanMapper romanMapper in shortRomanMappers)
        {
            while (currentValue - romanMapper.Value >= 0)
            {
currentValue -= romanMapper.Value;
                presentation.Append(romanMapper.Presentation);
            }
        }

       return presentation.ToString();
    }

    public override string ToString()
    {
        return presentation;
    }
}



And here are the Unit Tests:

[TestCase(0, "Nulla")]
[TestCase(1, "I")]
[TestCase(2, "II")]
[TestCase(3, "III")]
[TestCase(4, "IV")]
[TestCase(5, "V")]
[TestCase(6, "VI")]
[TestCase(8, "VIII")]
[TestCase(9, "IX")]
[TestCase(10, "X")]
[TestCase(17, "XVII")]
[TestCase(23, "XXIII")]
[TestCase(47, "XLVII")]
[TestCase(89, "LXXXIX")]
[TestCase(3999, "MMMCMXCIX")]


public void ToString_OfANumber_ReturnsRomanPresentation(int number, string romanPresentation)
{

    Assert.AreEqual(romanPresentation, new ShortRomanNumeral(number).ToString());
}


[TestCase(-1)]
[TestCase(-2)]
[ExpectedException(typeof(ArgumentException))]
public void ToString_OfANegativeNumber_ThrowsArgumentException(int number)
{
    new ShortRomanNumeral(number);
}


[TestCase(4000)]
[TestCase(5000)]
[ExpectedException(typeof(ArgumentException))]
public void ToString_OfANumberGreaterThan3999_ThrowsArgumentException(int number)
{
    new ShortRomanNumeral(number);
}


Friday, July 16, 2010

Second Meeting of the "Software Craftsmanship in Israel" Group

On 21.07.10 at 18:00 we will meet again for our second Software Craftsmanship meeting.
The agenda is:
 Bad Code / Good Code:
 

Topics (~40-60m):
• Bad Code and Good Code Examples 
• Identifying Bad code = Code Smells 
• Tools to identify bad code. 

Hands-On part (~60m-90m): 
• Coding Hands On

If you have a laptop with your environments set-up, please bring it to the meeting.
Please register here.
The meeting will take place here.

Thursday, July 15, 2010

ALT.NET Tools Night

On 12.07.2010 we have a lot of fun meeting at ALT.NET Tools Night.

The topics were:

Test Lint - Eli Shalom.

CodeRush & Refactor Pro - Me :).

NDepend - Dror Helper.

Process Explorer - Ariel Raunstien

Iron Ruby - Shay Friedman

Testify Wizard - Lior Friedman

Below you can find three sessions I have managed to record.

(Unfortunately, I didn't manage to record more, as I needed to leave earlier.)

Enjoy!







Many thanks to Lior Friedman, Shay Friedman and Ken Egozi for organizing the event.