Tuesday, 19 March 2013

DevWeek 2013: Overview


You can use this post either as an index of upcoming posts or an incredibly brief summary of the things I found interesting over the week.

For my colleagues, my full notes are in TFS in: "M:\TFS\C++\MooD\Docs\Misc\DevWeek 2013"

There's also a memory stick with all the slides on if anyone is really interested.

Monday

SharePoint 2013

  • Code runs under full trust.
  • 50% faster than predecessor (with 24Gb of RAM)
  • Farm / App / Sandbox solutions.  Should try and use Apps
  • Powershell is worth learning and useful for SharePoint development

Tuesday

Welcome to DevWeek

  • A question of craftsmanship (funny lecture + some links to interesting material)
  • Advances in the cloud computing platform (an advert for Azure)

Design patterns in the real world

  • Various patterns demonstrated using "Game of Life" example
  • Each class can contribute to many design patterns, not just one.

From the user to the unit test - how to start using tests

  • A description of SCRUM
  • Using Gherkin to specify scenarios
  • Arrange -> Act -> Assert
  • Selenium to test web

Light-weight architectures for everyone with the ASPNET WebAPI

  • WebAPI allows HTTP protocols without needing IIS / ASP.NET

Wednesday

Modern JavaScript

  • Encapsulation via Closures
  • Self invoking functions
  • Module pattern / revealing module pattern.
  • Confirmed that Sam's later work was using the right pattern.

Living happily with the GC

  • Using PerfMon to keep track of Gen0/1/2 collections
  • How to reduce frequency of slow collections
  • Why destructors are evil in C#

Evolution of the Entity Framework

  • Can auto migrate databases up/down versions
  • Code first POCO style development (plain old C# object)

Writing code that others can read.  A survival guide (for others)

  • Use Resharper
  • Commenting / consistency / clarity
  • Single responsibility principal
  • Function bigger than a screen is an alert to refactor

Thursday

Design for testing

  • Red, green refactoring
  • Use IoC / Dependency Injection
  • Confirmation that we're kind of doing it right (in some bits of the code base!)

How to asses user experience

  • Checklists of things to look for
  • "Feng GUI" is a good website which simulates eye tracking
  • Overlay a grid on your dialog to see how messy it is.

Emergent Design

  • Justifications for using TDD
  • Do things at the "Last Responsive Moment"
  • Try not to over engineer.  Rather respond to change as it happens.

Applied NoSQL in .net

  • MongoDB allows JSON objects stored against a primary key
  • Means that less JOINs happen
  • Very fast, depending on your data requirements.

Thursday, 14 March 2013

Code snippets in Blogger

Use the following link
http://www.manoli.net/csharpformat/format.aspx
And add custom CSS to your site (as the link advises)

A class which implements 'for each' in unmanaged C++

This is a way to make just about any class implement a C++ 'for each'.  In this example the existing way of iterating round a list is as follows:

CTypedPtrList<CPtrList,int*> myList;
POSITION pos = myList.GetHeadPosition();
while(pos)
{
    int* p = myList.GetNext(pos);
}

You need to implement a begin() and end() function which return an iterator class.
The iterator class must implement:
    void operator++();
    T operator*() const;
    bool operator!=(const iterator& other)

Once you have done this then the compiler will automatically allow you to write your iterator like this:
for each(int* p in myList)
{
}

Note that if your variable is const you may need to implement a version of everything which is const.

See below for a full implementation example built on CTypedPtrList:

template <class T> class PList : public CTypedPtrList<CPtrList> 
{
public:

    // Support for iterators.
    class iterator
    {
    public:
        iterator( PList<T>* p, POSITION pos ) 
            : m_pList(p), m_pos(pos), m_pointer(NULL) 
        {
            if( m_pList )
            {
                m_pos = m_pList->GetHeadPosition();
                if( m_pos )
                    m_pointer = m_pList->GetNext(m_pos);
            }
        }

        void operator++(int) 
        {
            if( m_pos==NULL ) m_pointer = NULL;
            else    m_pointer = m_pList->GetNext(m_pos);
        };

        void operator++()
        {
            this->operator++(0);
        };

        T* operator*() const { return m_pointer; }

        bool operator!=(const iterator& other) const 
        {
            return m_pointer!=other.m_pointer;
        }
    protected:
        PList<T>* m_pList;
        POSITION  m_pos;
        T*        m_pointer;
    };
    //
    iterator begin() { return iterator(this, GetHeadPosition()); }
    iterator end()   { return iterator(NULL,NULL); }
};

A word of caution about the unmanaged C++ 'for each' and 'auto' keywords

Recently I had the following code:

 
std::map<CString, std::vector<CString>> mapIdToChildren;
for(std::map<CString,std::vector<CString>>::iterator it = mapIdToChildren.begin();it!=mapIdToChildren.end();++it)
 std::sort( (*it).second.begin(), (*it).second.end() );
 

And tried replacing it with the 'for each' keyword:
for eachauto it in mapIdToChildren )
 std::sort( it.second.begin(), it.second.end() );
 

But found that the result is unsorted..
What is really happening is that the 'auto' is expanded to the following which means the vector is copied, so the original object remains unsorted:
for each( std::pair<CString,std::vector<CString>> it in mapIdToChildren )
 std::sort( it.second.begin(), it.second.end() );
 

Unfortunately the following code doesn't compile..
for each( std::pair<CString,std::vector<CString>>& it in mapIdToChildren )
 std::sort( it.second.begin(), it.second.end() );
 

Another failure:
for each( std::map<CString,std::vector<CString>>::iterator it in mapIdToChildren )
 std::sort( (*it).second.begin(), (*it).second.end() );
 

In conclusion you should be careful when using the 'auto' keyword in conjunction with 'for each' because you may not be getting what you think.

Tuesday, 12 March 2013

DevWeek 2013: Intro

Last week Steve Cooper and I visited London Village in order to learn more about what's cutting edge in Software Engineering.  Thankfully we both returned unscathed from the big smoke and learned a thing or two.  I shall attempt to jot down these pearls of wisdom in the following posts.  Oh and here are couple of nice pictures of the impressive main hall and lots and lots and lots of techie men.


A note on DevWeek itself:  The location is very nice, we had one lunch break basking in glorious sunshine while we dangled our feet over the edge of a fountain and watched the world go by.  Oh dear, now I've made it sound like a date.

I would advise people choosing lectures to pick very specifically titled ones.  An hour and a half isn't very long so the more general titles to do with design or testing or architecture seem to barely scratch the surface where as the specific ones can get down to the meat of the problem.