Search

Categories

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Send mail to the author(s) E-mail

# Monday, July 27, 2009
Thanks to:
http://davidhayden.com/blog/dave/archive/2006/05/28/2974.aspx

Anon methods, delegates, predicates.  Anon methods are simple shortcuts so don't have to declare a predicate method.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestAnonymousMethods
{
    public class Program
    {
        // using an anon method
        static void Mainx(string[] args)
        {
            int[] _integers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            int[] evenIntegers = Array.FindAll(_integers,
                                        // this is the anonymous method below
                                       delegate(int integer)
                                       {
                                           return (integer % 2 == 0);
                                       }
                );

            foreach (int integer in _integers) 
                Console.WriteLine(integer);

            foreach (int integer in evenIntegers)
                Console.WriteLine(integer);
        }

        // not using anon method
        static void Mainy(string[] args)
        {
            int[] _integers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            // passing in IsEven..a delegate which represents the IsEven method
            int[] evenIntegers = Array.FindAll(_integers, IsEven);

            foreach (int integer in _integers)
                Console.WriteLine(integer);

            foreach (int integer in evenIntegers)
                Console.WriteLine(integer);
        }

        static bool IsEven(int integer)
        {
            return (integer % 2 == 0);
        }


       
        // not using anon method and looking at predicate / delegate of Array.FindAll
        static void Main(string[] args)
        {
            int[] _integers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            // a predicate is expected
            // passing in IsEven..a delegate which represents the IsEven method
            int[] whatIsInBoth = Array.FindAll(_integers, IsDaveSequence);

            foreach (int integer in whatIsInBoth)
                Console.WriteLine(integer);

        }

        static bool IsDaveSequence(int integer)
        {
            bool returnState = false;
            if ((integer == 1) || (integer == 3) || (integer ==4))
                returnState = true;
            return returnState;
        }



    }
}

Comments [0] | | # 
# Thursday, July 23, 2009
Delegates, delegate to another method.  In this example, depending on which person is wired up - Suzanne or Amy.. depends on which method is called when the Get the ingredient button is called.


source code here..delegateIngredients.zip (91.58 KB)






    // can be used to create a variable that can point to any method that takes an int parameter and returns a string
    public delegate string GetSecretIngredient(int amount);

On the form:
        // so variable ingredientMethod of type delegate GetSecretIngredient currently points to a null method
        GetSecretIngredient ingredientMethod = null;
        private void getSuzanne_Click(object sender, EventArgs e)
        {
            // suzanne.MySecretIngredientMethod property returns a new instance of the the GetSecretIngredient delegate thats
            // pointing to her secret ingredient method.
            ingredientMethod = new GetSecretIngredient(suzanne.MySecretIngredientMethod);
        }
When button is pressed it will go to either the suzanne.MySecretIngredientMethod or the amy.AmySecretIngredientMethod
        private void useIngredient_Click(object sender, EventArgs e)
        {
            if (ingredientMethod != null)
                Console.WriteLine("I'll add " + ingredientMethod((int)amount.Value));
            else
                Console.WriteLine("I dont have a secret ingredient");
        }
Good duck example here:
http://stackoverflow.com/questions/687626/the-purpose-of-delegates



Comments [0] | | # 
# Saturday, July 18, 2009
A simple MVC (Model View Controller) implementation..code by Jimmy Chandra
http://stackoverflow.com/questions/1107720/mvc-c-simplest-possible-implementation

Why use MVC?  Similar reasons to MVP - testability and seperation of concerns

Simple.MVC.zip (167.25 KB)



1. Program.cs runs, running Main.. as is standard in a Win Forms app.  Difference from MVP is that main here is instantiating and running a controller class first of all, instead of newing up the view, which calls the controller/presenter.
static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            
            TopEmployeeController controller = new TopEmployeeController();
            Application.Run(controller.View as Form);
        }
2. Controller is instantiated and constructor called:
        private ITopEmployeeView _view;
        private Employee _employee;

        private bool _monitoring;

        public TopEmployeeController()
        {
            _employee = new Employee();
            _view = new TopEmployeeForm(this, _employee);
        }
3. Controller news up an employee (dumb).. then a view of type TopEmployeeForm, passing its self (the controller) and employee to it.

4. View (the observer) subscribes to the model (the subject) so that when model.OnPropertyChange is called, view.UpdateView is called.  This is the observer pattern, made easier in C# using events.. which is using a delegate.
// view
public TopEmployeeForm(ITopEmployeeController controller, Employee model)
        {
            _controller = controller;
            _model = model;

            //Let the model know that this view is interested if the model change
            _model.OnPropertyChange += new Action(UpdateView);

            InitializeComponent();
}
6. When Button is pressed on the view.  The controller.GetTopEmplyee method is called.  This calls model.MontorChanges:
// controller
public void GetTopEmployee()
{
if (!_monitoring)
{
_monitoring = true;
_employee.MonitorChanges();
}
}



7. MonitorChanges does some waiting code, then every second calls FirePropertyChange(). Which calls model.OnPropertyChange.
Which is really a delegate to View.UpdateView
// model
public event Action OnPropertyChange;

private void FirePropertyChange()
        {
            var propChange = OnPropertyChange;
            if (propChange != null)
            {
                OnPropertyChange();
            }
        }

8. The view method which runs every second and displays the name on the form.
// view
        public void UpdateView()
        {
            // to do with threading
            if (this.InvokeRequired)
            {
                this.Invoke(new Action(UpdateView));
            }
            else
            {
                TopEmployeeName = _model.FullName;
            }
        }




Comments [1] | | # 
# Thursday, July 16, 2009
( MVP | Patterns | Testing )
Easy to understand, working example WinForms app using MVP (Model View Presenter) pattern.

Why use this pattern?  Testability and maintainability (ie loosely coupled so less likely to break!)

Download noddy.zip (106.62 KB) (VS2008)

Notes:
View is dumb and does render logic
View never talks to the model (or any business entity eg customer) directly
Presenter retries data and manipulates
Model is the data and business rules

usually MVP sits on top of an ORM or Database Abstraction / Business Logic layer:


How it works:

1) Application comes to Program.cs which calls Form1.cs.. no MVP code here.
static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// Standard code.. nothing MVP
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }

2) Form1 (which is the view in MVP) which implements IView interface (**why**).. instantiates a new MainPresenter calling it presenter.
public partial class Form1 : Form, IView
    {
        private MainPresenter presenter;

        public Form1()
        {
            InitializeComponent();
             presenter = new MainPresenter(this);
        }

        private void btnPostCustomer_Click(object sender, EventArgs e)
        {
            presenter.PostCustomer();
        }

        // IView members
        public string FirstName
        {
            get { return txtFirstName.Text; }
            set { txtFirstName.Text = value; }
        }

        public string LastName
        {
            get { return txtLastName.Text; }
            set { txtLastName.Text = value; }
        }

        public void DisplayResult(string result)
        {
            MessageBox.Show(result);
        }
    }
3) MainPresenter constructor runs, and is passed in the view object of type IView. (**could we have just passed it in as a Form object?**)

public class MainPresenter
    {
        private IView view;
        private MainModel model = new MainModel();

        public MainPresenter(IView view)
        {
            this.view = view;    
        }

        public void PostCustomer()
        {
            Debug.Assert(view != null);

            try
            {
                Customer customer = new Customer(view.FirstName, view.LastName);
                model.PostCustomer(customer);
                view.DisplayResult(customer.ToString() + " posted");
            }
            catch(Exception ex)
            {
                view.DisplayResult(ex.Message);
            }
        }
    }
4) App is run, names are filled in, and Post button is submitted.



5) View code (form1.cs) runs presenter.PostCustomer
private void btnPostCustomer_Click(object sender, EventArgs e)
        {
            presenter.PostCustomer();
        }
6) presenter creates a new customer (which could be seen as being outside of MVP, and more in an entity later, as the model layer is usually light, and only relating the modelviews) and passes in the names.  Nothing special on the constructor of customer. 

public void PostCustomer()
        {
            Debug.Assert(view != null);

            try
            {
                Customer customer = new Customer(view.FirstName, view.LastName);
                model.PostCustomer(customer);
                view.DisplayResult(customer.FullName() + " posted");
            }
            catch(Exception ex)
            {
                view.DisplayResult(ex.Message);
            }
        }
7) Presenter calls the main model to PostCustomer which writes out to disk the Customer which has just been entered.
public void PostCustomer(Customer customer)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Customer));

            if (File.Exists("Customer.xml"))
            {
                using (FileStream stream = new FileStream("Customer.xml", FileMode.Append, FileAccess.Write))
                {
                    serializer.Serialize(stream, customer);
                }
            }
            else
            {
                using (FileStream stream = new FileStream("Customer.xml", FileMode.Create, FileAccess.Write))
                {
                    serializer.Serialize(stream, customer);
                }
            }
        }



8) Presenter calls the view to DisplayResult, passing in the customer data as a string.
public void DisplayResult(string result)
        {
            MessageBox.Show(result);
        }


Included in the download are simple tests on the ViewModel and Domain model.  Also Form2 which has a Form2Presenter.  Uses same ViewModel (hmm probably should have a seperate one), and the same domain model (customer.cs).  Next step for me is to get tests working on the Presenters.




Comments [0] | | # 
# Friday, July 03, 2009
In preparation for JPBoodhoo's course in Sydney in a months time, I'm looking at the tooling he recommends and going through this videos on dnrtv.com

this is going to be an ongoing list of ideas for me refer to.. excuse the mess!

Setting up Subversion
http://www.west-wind.com/presentations/subversion/

Console2 - console with an alpha transparency
AltTab - alt tab replacement
Resharper4.5 - makes VS2008 faster
Testdriven.net - unit testing easier
mbunit - unit testing framework


Keyboard shortcuts

Testdriven.net - bound to  in VS2008, Tools, Options, Keyboard.  testdriven.net.runtests.. Ctrl-Shift-Alt-T
rerun tests is to testdriven.net.reruntest.. Ctrl-Shift-Alt-R

Resharper
Ctrl-Alt-v  - introduce variable (highlight and it gens the variable)
Alt-Int - generate constructor and..... from an interface
F2 - rename

Comments [0] | | # 
# Thursday, April 09, 2009
Why use Events or publish / subscribe?

Any number of classes can be notified when an event is raised.

The subscribing classes do not need to know how the Metronome works, and the Metronome does not need to know what they are going to do in response to the event

The publisher and the subscribers are decoupled by the delegate. This is highly desirable as it makes for more flexible and robust code. The metronome can change how it detects time without breaking any of the subscribing classes. The subscribing classes can change how they respond to time changes without breaking the metronome. The two classes spin independently of one another, which makes for code that is easier to maintain.



Example1 - Metronome
Create a new console app, paste in the Main() code.  Then create 3 new classes (Alt P, C) - Metronome, Listener, ListenerB
A metronome ticks every 2 seconds, and two objects 'hear' it:

class Program
{
    static void Main()
    {
        // setup the metronome and make sure the EventHandler delegate is ready
        Metronome metronome = new Metronome();

        // wires up the metronome_Tick method to the EventHandler delegate
        Listener listener = new Listener(metronome);
        ListenerB listenerB = new ListenerB(metronome);
        metronome.Go();
    }
}

public class Metronome
{
    // a delegate
    // so every time Tick is called, the runtime calls another method
    // in this case Listener.metronome_Tick and ListenerB.metronome_Tick
    public event EventHandler Tick;

    // virtual so can override default behaviour in inherited classes easily
    protected virtual void OnTick(EventArgs e)
    {
        // null guard so if there are no listeners attached it wont throw an exception
        if (Tick != null)
            Tick(this, e);
    }

    public void Go()
    {
        while (true)
        {
            Thread.Sleep(2000);
            // because using EventHandler delegate, need to include the sending object and eventargs 
            // although we are not using them
            OnTick(EventArgs.Empty);
        }
    }
}


public class Listener
{
    public Listener(Metronome metronome)
    {
        metronome.Tick += new EventHandler(metronome_Tick);
    }
    
    private void metronome_Tick(object sender, EventArgs e)
    {
        Console.WriteLine("Heard it");
    }
}

public class ListenerB
{
    public ListenerB(Metronome metronome)
    {
        metronome.Tick += new EventHandler(metronome_Tick);
    }
    
    private void metronome_Tick(object sender, EventArgs e)
    {
        Console.WriteLine("ListenerB: Heard it");
    }
}    
Example2 - MetronomeArgs
We are passing the current time from the Metronome to the 2 listener objects
static void Main()
{
    // setup the metronome and make sure the EventHandler delegate is ready
    Metronome metronome = new Metronome();

    // wires up the metronome_Tick method to the EventHandler delegate
    Listener listener = new Listener(metronome);
    ListenerB listenerB = new ListenerB(metronome);
    metronome.Go();
}

public class Metronome
{
    // a delegate
    // so every time Tick is called, the runtime calls another method
    // in this case Listener.metronome_Tick
    // so objects subscribing to this delegate should look like (object sender, EventArgs e)
    public event EventHandler Tick;
   
    // virtual so can override default behaviour in inherited classes easily
    protected virtual void OnTick(TickEventArgs e)
    {
        // null guard so if there are no listeners attached it wont throw an exception
        if (Tick != null)
            Tick(this, e);
    }

    public void Go()
    {
        while (true)
        {
            Thread.Sleep(2000);
            DateTime now = DateTime.Now;
            TickEventArgs tickEventArgs = new TickEventArgs(now);
            OnTick(tickEventArgs);
        }
    }
}


// Good idea to inherit from EventArgs
// as can upcast EventArgs object in case you need to send it to an event that doesn't handle it???
// sole purpose of EventArgs class (which has no members) is to allow event arguments object to be passed to 
// event handlers
public class TickEventArgs : EventArgs
{
    public DateTime Time { get; private set; }

    public TickEventArgs(DateTime time)
    {
        this.Time = time;
    }
}

public class Listener
{
    public Listener(Metronome metronome)
    {
        metronome.Tick += new EventHandler(metronome_Tick);
    }

    private void metronome_Tick(object sender, EventArgs e)
    {
        // TickEventArgs is a superclass(?) of EventArgs... this is what we passed
        if (e is TickEventArgs)
        {
            // Downcasting e from EventArgs to TickEventArgs so can use its properties
            TickEventArgs tickEventArgs = e as TickEventArgs;
            
            Console.WriteLine("Heard it at time " + tickEventArgs.Time.ToString());
        }
    }
}

public class ListenerB
{
    public ListenerB(Metronome metronome)
    {
        metronome.Tick += new EventHandler(metronome_Tick);
    }
    
    private void metronome_Tick(object sender, EventArgs e)
    {
        Console.WriteLine("ListenerB: Heard it");
        
    }
}
References:
Big thanks on: http://stackoverflow.com/questions/724085/events-naming-convention-and-style
Metronome code is refactored from http://www.codeproject.com/KB/cs/simplesteventexample.aspx
Why use events: http://www.akadia.com/services/dotnet_delegates_and_events.html

Comments [0] | | # 
# Thursday, February 26, 2009


Thanks to the original author of the code (google m7tr1x)..

I had some great fun looking at the code, understanding how this effect works, and refactoring.

The original code is below.. I suggest scrolling down, and looking at the refactored code and pictures describing how the effect works.

Enjoy!

#define readkey

using System;

namespace m7tr1x
{
    class Program
    {
        static void Main(string[ ] args)
        {
            Console.Title = "tH3 M7tr1x 3ff3<t";
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WindowLeft = Console.WindowTop = 0;
            Console.WindowHeight = Console.BufferHeight = Console.LargestWindowHeight;
            Console.WindowWidth = Console.BufferWidth = Console.LargestWindowWidth;
#if readkey
            Console.WriteLine("H1T 7NY K3Y T0 C0NT1NU3 =/");
            Console.ReadKey();
#endif
            Console.CursorVisible = false;
            int width, height;
            int[ ] y;
            int[ ] l;
            Initialize(out width, out height, out y, out l);
            int ms;
            while ( true )
            {
                DateTime t1 = DateTime.Now;
                MatrixStep(width, height, y, l);
                ms = 10 - (int)( (TimeSpan)( DateTime.Now - t1 ) ).TotalMilliseconds;
                if ( ms > 0 )
                    System.Threading.Thread.Sleep(ms);
                if ( Console.KeyAvailable )
                    if ( Console.ReadKey().Key == ConsoleKey.F5 )
                        Initialize(out width, out height, out y, out l);
            }
        }

        static bool thistime = false;

        private static void MatrixStep(int width, int height, int[ ] y, int[ ] l)
        {
            int x;
            thistime = !thistime;
            for ( x = 0 ; x < width ; ++x )
            {
                if ( x % 11 == 10 )
                {
                    if ( !thistime )
                        continue;
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.SetCursorPosition(x, inBoxY(y[x] - 2 - ( l[x] / 40 * 2 ), height));
                    Console.Write(R);
                    Console.ForegroundColor = ConsoleColor.Green;
                }
                Console.SetCursorPosition(x, y[x]);
                Console.Write(R);
                y[x] = inBoxY(y[x] + 1, height);
                Console.SetCursorPosition(x, inBoxY(y[x] - l[x], height));
                Console.Write(' ');
            }
        }

        private static void Initialize(out int width, out int height, out int[ ] y, out int[ ] l)
        {
            int h1;
            int h2 = ( h1 = ( height = Console.WindowHeight ) / 2 ) / 2;
            width = Console.WindowWidth - 1;
            y = new int[width];
            l = new int[width];
            int x;
            Console.Clear();
            for ( x = 0 ; x < width ; ++x )
            {
                y[x] = r.Next(height);
                l[x] = r.Next(h2 * ( ( x % 11 != 10 ) ? 2 : 1 ), h1 * ( ( x % 11 != 10 ) ? 2 : 1 ));
            }
        }

        static Random r = new Random();
        static char R
        {
            get
            {
                int t = r.Next(10);
                if ( t <= 2 )
                    return (char)( '0' + r.Next(10) );
                else if ( t <= 4 )
                    return (char)( 'a' + r.Next(27) );
                else if ( t <= 6 )
                    return (char)( 'A' + r.Next(27) );
                else
                    return (char)( r.Next(32, 255) );
            }
        }

        public static int inBoxY(int n, int height)
        {
            n = n % height;
            if ( n < 0 )
                return n + height;
            else
                return n;
        }
    }
}
Here is the refactored code:
using System;

namespace matrix
{
    class Program
    {
        // fields
        static Random rand = new Random();
        
        // properties
        static char AsciiCharacter
        {
            get
            {
                int t = rand.Next(10);
                if (t <= 2)
                    // returns a number
                    return (char)('0' + rand.Next(10));
                else if (t <= 4)
                    // small letter
                    return (char)('a' + rand.Next(27));
                else if (t <= 6)
                    // capital letter
                    return (char)('A' + rand.Next(27));
                else
                    // any ascii character
                    return (char)(rand.Next(32, 255));
            }
        }

        // methods
        static void Main()
        {
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WindowLeft = Console.WindowTop = 0;
            Console.WindowHeight = Console.BufferHeight = Console.LargestWindowHeight;
            Console.WindowWidth = Console.BufferWidth = Console.LargestWindowWidth;
            Console.WriteLine("Hit Any Key To Continue");
            Console.ReadKey();
            Console.CursorVisible = false;
            
            int width, height;
            // setup array of starting y values
            int[] y;

            // width was 209, height was 81
            // setup the screen and initial conditions of y
            Initialize(out width, out height, out y);

            // do the Matrix effect
            // every loop all y's get incremented by 1
            while ( true )
                UpdateAllColumns(width, height, y);
        }

        
        private static void UpdateAllColumns(int width, int height, int[] y)
        {
            int x;
            // draws 3 characters in each x column each time... 
            // a dark green, light green, and a space

            // y is the position on the screen
            // y[x] increments 1 each time so each loop does the same thing but down 1 y value
            for ( x = 0 ; x < width ; ++x )
            {
                // the bright green character
                Console.ForegroundColor = ConsoleColor.Green;
                Console.SetCursorPosition(x, y[x]);
                Console.Write(AsciiCharacter);

                // the dark green character -  2 positions above the bright green character
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                int temp = y[x] - 2;
                Console.SetCursorPosition(x, inScreenYPosition(temp, height));
                Console.Write(AsciiCharacter);

                // the 'space' - 20 positions above the bright green character
                int temp1 = y[x] - 20;
                Console.SetCursorPosition(x, inScreenYPosition(temp1, height));
                Console.Write(' ');

                // increment y
                y[x] = inScreenYPosition(y[x] + 1, height);
            }

            // F5 to reset, F11 to pause and unpause
            if (Console.KeyAvailable)
            {
                if (Console.ReadKey().Key == ConsoleKey.F5)
                    Initialize(out width, out height, out y);
                if (Console.ReadKey().Key == ConsoleKey.F11)
                    System.Threading.Thread.Sleep(1);
            }

        }

        // Deals with what happens when y position is off screen
        public static int inScreenYPosition(int yPosition, int height)
        {
            if (yPosition < 0)
                return yPosition + height;
            else if (yPosition < height)
                return yPosition;
            else
                return 0;
        }

        // only called once at the start
        private static void Initialize(out int width, out int height, out int[] y)
        {
            height = Console.WindowHeight;
            width = Console.WindowWidth - 1;

            // 209 for me.. starting y positions of bright green characters
            y = new int[width];
            
            Console.Clear();
            // loops 209 times for me
            for ( int x = 0 ; x < width ; ++x )
            {
                // gets random number between 0 and 81
                y[x] = rand.Next(height);
            }
        }
    }
}

how it works:

The screen draws each column.. my screen is 208 wide.. so it loops 208 times, each time drawing a bright green character, dark green character, and a space.



The second loop.. the y value has been incremented by 1.



The 3rd loop



Enjoy!
Comments [1] | | # 
# Thursday, January 22, 2009

A Big thanks to everyone who came to my presentation tonight on nUnit:

In his mission to become a great developer, Dave will entertain you with 'How nUnit Inspired an Awesome Rock Song'.  Dave will demonstrate the time and heartache savings (which allowed time and energy to do the music).

Tools and technoloiges (ab)used in this talk will be:  C#3.5SP1, VS2008 Express, PHP, JSON, MySQL, and nUnit.  I'll demo the Awesome Rock Song too!

If you've heard of unit testing, this presentation is for you.  Bring your laptop and take away your first working unit test project.  Your future development projects will get easier with testing.


Lake Tekapo, NZ

Here is the powerpoint presentation: HowNUnitInspiredAnAwesomeRockSong.zip (1.1 MB)

Here is all the source code (compiled and run on VS2008Express using .NET3.5SP1).  Nunit 2.4.8 installed.: nunitPresentation.zip (606.4 KB)

We discussed favourite tools and keyboard shortcuts, in relation to being a Tenfer (programmer that is 10 times as productive as others):

blogs.msdn.com/saraford - Visual studio tips and tricks

www.launchy.net - quick launcher
CLCL - www.nakka.com/soft/clcl/index_eng.html - Clipboard multi

Visual Studio Keyboard Shourtcuts
Ctrl Shift B - Build
Ctrl K, Ctrl C - Comment
Ctrt K, Ctrl U - Uncomment
F5 - run
F10 step through when debuggin
Ctrl B, Ctrl T - Bookmark Toggle
Ctrl B, Ctrl N - Goto next bookmark
Ctrl L - Delete Line

Alt F, J - Recent projects open
Ctrl K, Ctrl D - Format a document

Ctrl M, Ctrl M - collapse / expand
Ctrl M, Ctrl O - collapse all

Split screen

Windows Shortcuts
Win L - Lock
Win E - Explorer
Win D - Minimize all window.. press again to restore
Alt D - Goes to explorer bar (try in explorer, and firefox).. tab to autocomplete
Alt F4 - Close down window
Ctrl Shift Esc - Task manager

Google tricks:
 - golf   - don't include golf in search
 "search for entire phrase" - searches for that entire phrase
 advanced settings to search in a date range

Powerpoint
  B - black screen
  W - white screen
  type slide number and press enter to go to that slide

Resharper
  Makes life faster

stackoverflow.com - great programming question and answer site




Comments [2] | | # 
# Friday, January 16, 2009
( Testing )



Girl and man looking towards Mt Cook, NZ.

To get nUnit working on VS 2008 Express, firstly download and install nUnit.

Make a new console application.  Add the 3 nunit references you see below



Open up the .csproj file.. in my case in: C:\code\stuff\HowNUnitInspiredConsole\HowNUnitInspiredConsole\HowNUnitInspiredConsole.csproj

Where you see... add in the two Startxxx lines.

 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

    <StartAction>Program</StartAction>
    <StartProgram>C:\Program Files\NUnit 2.4.8\bin\nunit.exe</StartProgram>
   
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>

Here is my first unit test for a web app:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Web.Script.Serialization;
using System.Web.Util;
using System.Net;
using System.Web;
using System.IO;
using System.Diagnostics;

namespace HowNUnitInspiredConsole
{
    class NUnitConsoleRunner
    {
        [STAThread]
        static void Main(string[] args)
        {
            NUnit.ConsoleRunner.Runner.Main(args);
        }
    }

    [TestFixture]
    public class FormTest
    {
        // 1 is dev / local
        // 2 is test
        int debugbit = 2;

        string targetUri = "";
        string targetUriNoHTTP = "";

        [SetUp]
        public void Init()
        {
            if (debugbit == 1)
            {
                targetUri = "http://192.168.139.128/drink/";
                targetUriNoHTTP = "192.168.139.128/drink/";
            }

            if (debugbit == 2)
            {
                targetUri = "http://www.davemateer.com/drink/";
                targetUriNoHTTP = "www.davemateer.com/drink/";
            }
        }

        [Test]
        public void helloWorld()
        {
            WebClient client = new WebClient();
            StreamReader reader = new StreamReader(client.OpenRead(targetUri + "test/helloWorld.php"));
            string responseFromServer = reader.ReadToEnd();

            Assert.AreEqual("Hello World", responseFromServer);
        }
    }
}



When the nUnit gui popped up, make sure it gets the correct .exe file.  I had to do a project add assembly, while the application was running.

Run your application which should pop up with something like this:


Comments [0] | | # 
# Sunday, November 09, 2008

Why ProgramGood.Net?

To have fun!
Explore the world of programming
To inspire, educate and entertain



On the way to Machu Picchu, Peru


What inspired you to start this?

Google searching - "How to Become a Great Programmer"
Great Article - 10 Years norvig.com/21-days.html
http://steve.yegge.googlepages.com/practicing-programming
http://graysmatter.codivation.com/HowIAmBecomingABetterDeveloperPart1OfInfinity.aspx

Highlights were:
Read a chapter a week from a programming book
Code the examples
Listen to Podcasts and Screencasts
Learn a new language every year!
Learn about the business of software development
Teach / Present topics
Have a mentor and be a mentor

What Topics Do You Want To Cover?

C# Language - am working through Head First C# 3.5
OOP Concepts
Types and References
Encapsulation
Inheritance
Interfaces
Collections
Files
Exceptions
Events and Delegates
LINQ

Recursion
Anonymous Types
Delegates
 
DataAdapters etc..Datasets (are they evil?)

PHP
- A useful language!
Web Services
Design Patterns
Unit Testing
ORM
Libraries
IDE's / Tools JSON/XML

Reporting Services 2000 / 2005 / 2008 - Everyone likes reports!  Good programmers have good tools.
 How to produce good reports

How To Develop Software
XP Approach vs classic Waterfall Approach
StackOverflow example of how to develop software

Test Driven Development - TDD

Testing
nUnit
nUnitASP
waitr
TestDriven.Net
NCover
cruisecontrol.net
dbunit

SourceControl
 TortoiseSVN and Subversion

Bug Tracking
Excel!

CodeGenerators / ORM / Helper
Entity framework - EntityDataSource and GridViews/DetailsViews/FormViews
Dynamic Data web projects - create all standard list/details/edit/delete pages
LINQ to SQL - don't use?

CodeSmithnHibernate
Subsonic
openaccess?
TypeMock / RhinoMocks
NHibernate
Lightspeed
CSLA

Tools
Visual Studio
  Tips on how to use Visual Studio...
Resharper
reflector

App Types

 Console
 WinForm
 WebForm
 Webservice
 WPF
 Silverlight

Patterns - What are they.. families
MS Patterns and Practises group
Enterprise Library
MVC Framework
MVP
IoC

Web ASP.NET

 Framworks and how to do stuff quickly
 Membership
 MasterPages

Open Source Projects - understand others code

 ProjectRun
 dasBlog
 examples from www.asp.net
 codeplex
 BackgroundMotion
 DineOut
 StockTrader
 Vertigo

Fun Challenges

 Project Run
 Project September
 Charity Project
 Coding Challenge (code breaker)
 Perl/Python fun ones
 Mapping - Jamie
 Project Infotainmnet
 Music Project - KitInABox
 Code Monkeys (how long to create Shakespeare)
 Treasure Sprint - treasuresprint.blogspot.com

Coding Competitions

Programmers / Developers I Admire and why

 Scott Hanselman
 JP Boodhoo
 Ron Jacobs
 Carl Franklin
 Scott Gu
 Scott Stanfield
 Adam Cogan
 Vertigo
 Peter Jonesie
 Bill Gates
 James Kovacs
 Mario Szpuszta
 Matthew Macdonald
 Ken Schwaber - scrum
 Rocky Lhotka - csla

Traits of a great Programmer

 Curiosity
 Humble
 Learn about successful projects and read source code
 Play with others code
 Have readable code

Great Books and Why

 Mythical Man Month
 Head First C# Programming 3.5
 Joel Spolskys books
 The Pragmatic Programmer
 Software Craftsmanship
 Coder to Developer
 ** - how quiet conditions are super important... 2 person office.. close doors.
Great Blogs and why
 stackoverflow
 Joel Spolsky
Thinking in Code

Languages - where they came from.. strengths and weaknesses

 OOP / Procedural / Functional
 C#
 VB
 Java
 Python
 Ruby / RoR
 PHP
 SQL
 F#
 oCaml
 Prolog
 C / C++
 Lisp
 Fortran
 Cobol

Fun Geek Language

  YAGNI - You Aint Gunna Need It
  This smells - something doesn't feel right


Where did The Domain Name Come From?

Came from iWantToProgramGood... Written English has never been my strong point, and I never seem to wrote in sentences... only statements... followed by dots....and when I went to look at domain names, register.com suggested ProgramGood.Net.. How appropriate!

Lets start the journey!


Venezuela, sunset.  About 4500m.
Comments [0] | | #