Archive

Monthly Archives: July 2015

Intro

I have improved my software development practice by building a Visual Studio extension. This extension has boosted my productivity by enabling me to rapidly generate user story modules to support my emergent design practice.

Bizmonger Extensions

One extension that I have built to support my development efforts is the UserStory project template. This project template can be downloaded from the Visual Studio gallery or from Visual Studio’s Extensions and Updates dialog.

To download the extension from Visual Studio perform the following:

  1. Select Tools | Extensions and Updates.
  2. Select the Online tab.
  3. Ensure the Visual Studio Gallery is selected.
  4. Type “Bizmonger” in the search bar.
  5. Install both “Bizmonger.UserStory” and Message Snippet

Extensions_dialog

Bizmonger.UserStory

Bizmonger.UserStory is a portable class library that serves as an individual module for an arbitrary user story. I wrote this extension to support architectures that are organized by user story modules instead of relying on obscure folder names like “Views”, “ViewModels”, and “Model”. For example, when viewing projects within a solution that supports a user story driven architecture, one would observe projects that are actually based on the user stories that the software was intended for. For example, there could be a module called “Login”. Another module could be called “ViewProfile”. Thus, there could be another module within the solution called “EditProfile”.

I recently wrote an Android app in Xamarin.Forms using the described pattern:

stories

That app supported two user stories. One user story involved enabling a user to choose from a menu of clips so that he/she could place textual content on a clipboard and then paste the content onto a text message or email. That user story was called the ViewMenu module. The other user story involved editing content in order to update and archive the content for later use. This was done in the EditContent module of the app.

Adding a UserStory Module

With the Bizmonger.UserStory extension installed:

  1. Select File | New | Project.
  2. Type “UserStory” in the search bar.
  3. Select the UserStory project and assign it the name: ViewMenu.
  4. Click OK button.

new_userstory

When the project gets created you should observe the following project structure:

added_userstory

NOTE: I created a folder called “Stories” add moved the project under it.

Composite ViewModel

In the project, you will observe an expandable view-model. I call this type of view-model a Composite ViewModel. A Composite ViewModel is a set of partial view-model classes. Each partial class of the view-model isolates a specific responsibility of the view-model. I discovered this structural pattern after growing tired of maintaining monolithic view-models. I was just fed-up with having to scroll up and down the editor of a view-model class just to either debug or extend it.

The isolated responsibilities that make up a composite view-model are the following:

      • ViewModel (state)
      • ViewModel.commands
      • ViewModel.internal

Messages
The Messages class contains user-defined message ids that can be placed on the MessageBus to dispatch notifications to decoupled subscribers of a message.

ViewModel
The composite view-model parent node is responsible for initializing commands and conveying state. Specifically, it registers subscriptions, instantiates commands, and conveys state.

    public partial class ViewModel
    {
        public ViewModel()
        {
            MakePromises();
            ActivateCommands();
        }

        public bool DidSomething { get; set; }
    }

ViewModel.commands

ViewModel.commands isolate the behavior of the view-model from its state.

    public partial class ViewModel
    {
        public ICommand DoSomething { get; set; }
        void ActivateCommands() => DoSomething = new DelegateCommand(obj => _messagebus.Publish(Messages.REQUEST_SOME_ACTION));
    }

ViewModel.internal
ViewModel.internal manages internal state through its encapsulated logic.

    public partial class ViewModel
    {
        MessageBus _messagebus = MessageBus.Instance;

        void MakePromises()
        {
            _messagebus.Subscribe(Messages.REQUEST_SOME_ACTION, RespondToSomeAction);
        }

        void RespondToSomeAction(object obj)
        {
            DidSomething = true;
        }
    }

Adding a Unit Test

test_dialog

  1. Select File | New | Project.
  2. Select Unit Test Project.
  3. Name the test project: “ViewMenu.Tests”.
  4. Observe the “ViewMenu.Tests” project is added to the solution.
  5. In solution Explorer, rename “UnitTest1.cs” within the test project to “_ViewMenu.cs”
  6. Add a reference to the ViewMenu project
  7. Replace the following unit test:
    [TestClass]
    public class _ViewMenu
    {
        [TestMethod]
        public void TestMethod1()
        {

        }
    }

With:

    [TestClass]
    public class _ViewMenu
    {
        [TestMethod]
        public void do_something()
        {
            // Setup
            var viewModel = new ViewModel();
            var doSomething = viewModel.DoSomething;

            // Test
            doSomething.Execute(null);

            // Verify
            Assert.IsTrue(viewModel.DidSomething);
        }
    }

Go ahead and run the test.

Conclusion

In conclusion, I have improved my software development practice by building a Visual Studio extension. This extension has boosted my productivity by enabling me to rapidly generate user story modules to support my emergent design practice. Thus, I have shared a tutorial to get developers started with this visual studio extension. I then provided additional steps on how to unit test a user story module. I welcome feedback.

NOTE:

Scott Nimrod is fascinated with Software Craftsmanship.

He loves responding to feedback and encourages people to share his articles.

He can be reached at scott.nimrod @ bizmonger.net

500x_programmer[1]

Intro

Are you a professional developer or a professional debuggerer?

Find out by answering the following questions:

o    Do you spend most of your time building software or debugging it?

o    Do you spend a significant amount of time stabilizing the software that you wrote when a build is requested or is your code typically ready at a moment’s notice?

o    Do you spend most of your time debugging your code by launching an application and then putting the application into a state just to test your logic?

If you have answered yes to any of these questions, then perhaps you are a professional debuggerer.

Professional Debuggerers

I have recognized a problem with the vast majority of programmers within the software industry today. They have limited effectiveness in building lasting software. I think that this breed of programmer should not be called a developer based on a developer’s definition. Hence, they don’t spend a company’s budget actively developing software. However, they do spend a considerable amount of time debugging it. As a result, I hereby declare these set of programmers “Professional Debuggerers”. These programmers are the source to why the majority of software takes so long to build and extend, and are also the prime reason why software gets rejected by the end-user based on quality concerns. This is because they’re not building software at all. Instead they’re routinely spending their company’s budget debugging code instead of developing it.

As a consultant, I have worked in a number of software shops and have recognized this anti-pattern. Professional Debuggerers are programmers who have not yet developed the ability to write proven code. It’s kind of ironic how they are fluent in a programming language. However, they are unable to use their programming ability to automate checks and balances in order to validate their code’s integrity. As a result, these programmers tend to spend most of their time debugging code instead of developing it.

Professional Developers

Even though professional debuggerers make up the majority of the industry, there are a limited number of professional developers. These programmers do not spend the majority of their time debugging. Instead, they spend the majority of their time building software. These programmers have grown their ability to write effective automated tests so that they can ensure their codes’ integrity as it evolves. Professional Developers have cultivated a skill to identify breaking changes immediately, within seconds of introducing new code. In addition, they have developed a ritual for writing an automated test for each bug that’s found in their code. As a result, bugs within their software are exposed only one time throughout the software development life cycle or are otherwise caught and handled immediately after resurfacing. This quality control reduces development time and expenses significantly.

Professional Developers are not inclined to first launch an application and then put the application into a state to debug it. Instead, these professionals first attempt to reproduce an anomaly by first writing an automated test to expose the issue. They can then identify the issue and resolve it with confidence that their resolution does not inflict breaking changes to other parts of the system based on existing test automation. If a new unit test that targets an anomaly does not flush out the bug, then developers can resort to launching their application in an effort to identify the root cause of an anomaly.

Professional developers understand that automating checks and balances for their code saves both them and their client frustration, and at the same time, reduces the cost of building and maintaining software. Hence, this is why this breed of programmer is called a professional. They acknowledge that they can write error-prone code and therefore exercise professionalism in implementing checks and balances so that anomalies are identified within milliseconds of introducing new code instead of several minutes, days, weeks, or months. Again, this is what separates professional developers from professional debuggerers.

Conclusion

In conclusion, are you a professional developer or a professional debuggerer?

o    Do you spend most of your time building software or debugging it?

o    Do you spend a significant amount of time stabilizing the software that you write when a build is requested or is your code typically ready at a moment’s notice?

o    Do you spend most of your time debugging your code by launching an application and then putting the application into a state just to test your logic?

If you have answered yes to any of these questions, then perhaps you are…

NOTE:

Scott Nimrod is fascinated with Software Craftsmanship.

He loves responding to feedback and encourages people to share his articles.

He can be reached at scott.nimrod @ bizmonger.net

Intro


I recently wrote an Android app using a framework called Xamarin.Forms. Xamarin.Forms is a cross-platform UI framework that enables developers to share code across all major mobile platforms (IOS, Android, and Windows Phone) that’s written in C# and XAML. After implementing this app, I would like to report my findings.

Test Automation

Writing an Android app using Xamarin.Forms allowed me to leverage my existing C#, XAML, and test automation skills. Hence, improving my craft with tools that I’m already proficient in is very important. I once dabbled with Android Studio and quickly realized that I was both spoiled and more productive with Visual Studio. Working within Visual Studio enables me to stay in rhythm by depending on test automation to send feedback about my code’s integrity during code construction. Android Studio did not recognize unit tests as a first-class citizen to the IDE. Therefore, I found myself having to research how to configure basic unit tests to run. As a result of me spinning my wheels, I decided to return back to Visual Studio and its amazing support for test automation out the box. However, I did learn that the Portable Class Library does not support the “ExcludeFromCodeCoverage” attribute. Not having this support obscures the code coverage that matters to me. Hence, I could simply place the ExcludeFromCodeCoverage attribute over my code-behind class which would improve my code coverage report based on actual business logic being tested versus UX logic.

XAML

Xamarin.Forms uses a different dialect of XAML. Yes, there is still databinding, styles, data templates, and controls. However, there are subtleties when leveraging their form of XAML that differs from Windows’ XAML. For example, as of now, there’s no MultiBinding or RelativeSource binding. These binding types are extremely convenient for presenting a UI that reflects a number of factors. Also, I still haven’t observed useful intellisense within their XAML editor even though they claim that intellisense is supported within their framework. In addition, some basic properties are still not supported as an abstraction for the major platforms. For example, custom logic (i.e. custom renderer) is required for each platform to set an editor’s background color and foreground. This means that you cannot declare an editor in XAML and set the editor’s background to yellow and it’s foreground to blue. I also learned that there’s a bug where multi-line editors that are set to read-only will put all of the content within that mode to just one line. This means that a read-only editor does not show multiple lines of content. A read-only editor will only show one line.

Visual Designer

Xamarin.Forms does not support a visual designer yet. As a result, I added a WPF project to my solution to mock my view layouts and then leveraged the structure of that XAML to build a UI under my Xamarin.Forms project.

Deployment

I still am unable to deploy my Xamarin app to Google’s Play store. I receive an error every time I attempt to upload my app. I’m sure that if I keep trying, eventually I will get the support that I need to get the app deployed to the store.

Conclusion

In conclusion, I recently wrote an Android app using a framework called Xamarin.Forms. Xamarin.Forms is a cross-platform UI framework that enables developers to share code across all major mobile platforms (IOS, Android, and Windows Phone) that’s written in C# and XAML. I have summarized my findings of building an app with this framework. Overall, I see huge potential with this framework. Unfortunately, I believe it is somewhat risky to leverage this framework within its current state to build UX intensive applications. The application that I wrote can be found on GitHub.

NOTE:

Scott Nimrod is fascinated with Software Craftsmanship.

He loves responding to feedback and encourages people to share his articles.

He can be reached at scott.nimrod @ bizmonger.net

Intro

In .NET, we can stop relying on code regions within a class and instead use partial classes and file nesting to isolate code. An example of nested classes is the following: NestedFiles Regions are sections of collapsible code within a class. A “Helpers” region is shown below.

        #region Helpers
        private void OnLoadContent(object obj)
        {
            var repository = obj as IRepository;

            var dbContent1 = repository.Get(1);
            var dbContent2 = repository.Get(2);
            var dbContent3 = repository.Get(3);
            var dbContent4 = repository.Get(4);

            Content1 = dbContent1 != null ? dbContent1 : new Content() { Id = 1, Value = "Copy & paste me (1)" };
        }

        private void OnContentRequested(object obj)
        {
            var text = obj as string;
            var content = GetContent(obj);
            _messagebus.Publish(Messages.REQUEST_CONTENT_RESPONSE, content);
        }
        #endregion

The following is an extended example of how regions can be used for properties and private methods:

public partial class ViewModel : ViewModelBase
    {
        public ViewModel()
        {
            _messagebus.Subscribe(Messages.REQUEST_SET_CLIPBOARD, obj => CopyMade = true);
            _messagebus.Subscribe(Messages.CONTENT_SELECTED, OnContentSelected);
            _messagebus.Subscribe(Messages.REQUEST_LOAD_CONTENT, OnLoadContent);
            _messagebus.Subscribe(Messages.REQUEST_CONTENT, OnContentRequested);
        }

        #region Properties
        Content _content1 = null;
        public Content Content1
        {
            get
            {
                return _content1;
            }
            set
            {
                if (_content1 != value)
                {
                    _content1 = value;
                    OnPropertyChanged();
                }
            }
        }

        

        bool _copyMade = false;
        public bool CopyMade
        {
            get
            {
                return _copyMade;
            }
            set
            {
                if (_copyMade != value)
                {
                    _copyMade = value;
                    OnPropertyChanged();
                }
            }
        }

        Content _selectedContent = null;
        public Content SelectedContent
        {
            get
            {
                return _selectedContent;
            }
            set
            {
                if (_selectedContent != value)
                {
                    _selectedContent = value;
                    OnPropertyChanged();
                }
            }
        }
        #endregion

        #region Helpers
        private void OnLoadContent(object obj)
        {
            var repository = obj as IRepository;
            var dbContent1 = repository.Get(1);

            Content1 = dbContent1 != null ? dbContent1 : new Content() { Id = 1, Value = "Copy & paste me (1)" };
        }

        private void OnContentRequested(object obj)
        {
            var text = obj as string;
            var content = GetContent(obj);
            _messagebus.Publish(Messages.REQUEST_CONTENT_RESPONSE, content);
        }
        #endregion
    }

As you can see, the class definition is becomes obscured when all sections are expanded. As a result, we may find ourselves scrolling up and down class definitions to maintain a class implementation. Having that type of user experience can be burdensome. There should be an alternative method for segregating sections of code.

Partial Classes

Partial classes enables multiple files to share a class definition. An example of a common partial class is a XAML file. MainWindow.xaml and MainWindow.xaml.cs is often observed in WPF projects. Partial classes can also be used as an alternative to regions. For example, we can take our past view-model class and change its state to a partial class. Example:

  • ViewModel.cs
  • ViewModel.support.cs

ViewModel.cs can expose the public properties of the class. ViewModel.support.cs can harbor member variables and private methods for the view-model. Example: project_nested_files In order for partial classes to be supported, the following partial class declaration must be made:

public partial class ViewModel

Then we can remove the private members and methods from the view-model class and put it in a supporting partial class. Example:

    public partial class ViewModel : ViewModelBase
    {
        public ViewModel()
        {
            _messagebus.Subscribe(Messages.REQUEST_SET_CLIPBOARD, obj => CopyMade = true);
            _messagebus.Subscribe(Messages.CONTENT_SELECTED, OnContentSelected);
            _messagebus.Subscribe(Messages.REQUEST_LOAD_CONTENT, OnLoadContent);
            _messagebus.Subscribe(Messages.REQUEST_CONTENT, OnContentRequested);
        }

        Content _content1 = null;
        public Content Content1
        {
            get
            {
                return _content1;
            }
            set
            {
                if (_content1 != value)
                {
                    _content1 = value;
                    OnPropertyChanged();
                }
            }
        }

        

        bool _copyMade = false;
        public bool CopyMade
        {
            get
            {
                return _copyMade;
            }
            set
            {
                if (_copyMade != value)
                {
                    _copyMade = value;
                    OnPropertyChanged();
                }
            }
        }

        Content _selectedContent = null;
        public Content SelectedContent
        {
            get
            {
                return _selectedContent;
            }
            set
            {
                if (_selectedContent != value)
                {
                    _selectedContent = value;
                    OnPropertyChanged();
                }
            }
        }
    }

The supporting partial class that defines members and private methods can be the following:

public partial class ViewModel

{

MessageBus _messagebus = MessageBus.Instance;

public void OnContentSelected(object obj)

{

var content = GetContent(obj);

SelectedContent = content;

}

private void OnLoadContent(object obj)

{

var repository = obj as IRepository;

var dbContent1 = repository.Get(1);

Content1 = dbContent1 != null ? dbContent1 : new Content() { Id = 1, Value = "Copy & paste me (1)" };

}

private void OnContentRequested(object obj)

{

var text = obj as string;

var content = GetContent(obj);

_messagebus.Publish(Messages.REQUEST_CONTENT_RESPONSE, content);

}

private Content GetContent(object obj)

{

var text = obj as string;

var contentList = new List<Content>() { Content1 };

var content = contentList.Where(c => c.Value == text).FirstOrDefault();

return content;

}

}

Note how we have two class declarations for the same class. This is only possible using the “partial” declaration.

Nesting files

We can consolidate partial classes by nesting them under the exposed interface of the class: NestedFiles To do this perform the following:

  1. In Visual Studio, navigate to Tools | Extensions and Updates
  2. Select the Online tab
  3. Search for “File Nesting”
  4. Install the extension

Extentions_NestedFiles After the extension is installed, within Solution Explorer, right-click a class file and select: File Nesting | Nest Item. You can then select a parent file to nest the selected file under.

Conclusion

In conclusion, within .NET, I explained how we could stop relying on code regions within a class and instead use partial classes and file nesting to isolate code.

NOTE:

Scott Nimrod is fascinated with Software Craftsmanship. He loves responding to feedback and encourages people to share his articles. He can be reached at scott.nimrod @ bizmonger.net

SoftwarePuzzle

After I studied Microsoft Biztalk’s architecture, I found that relying on a messaging architecture works very well for building software. As a result, I no longer rely on orchestration in which a Director / Builder is required to direct a process and also have knowledge of all of the dependencies in order to execute that process.

I now build software where a client simply places a message on a messagebus for decoupled subscribers of that message to process and when that message is processed, a response from a subscriber is placed on the same messagebus for the initial client to observe and respond to. After all, why should my client even know about the server in order to make a request? The less my client knows about its dependencies, the easier it is for me to extend testable software. Hence, clients should not have to describe how to carry out an operation. Instead, clients should only spin-up requests for servers to respond to autonomously.

NOTE:

Scott Nimrod is fascinated with Software Craftsmanship.

He loves responding to feedback and encourages people to share his articles.

He can be reached at scott.nimrod @ bizmonger.net

thLN7AMXFA

I have been plugging away on Android development. As a hardened XAML Developer, it’s been painful for me to adapt.

1. TDD is hard using Android Studio.

I just do not see how to hit the ground running with the Red-Green-Refactor methodology. I am convinced that TDD is the best way to build systems in 2015. I get into the “zone” so much easier when writing code and getting an immediate reaction to notify me of the codebase’s current state. Unfortunately, I have failed to identify TDD as a first class citizen for Android Studio. I have searched the internet and just have not found any support to hit the ground running. In fact, I have noticed that unit test support is also not a first class citizen in the NetBeans IDE either. I have found that getting started requires some serious ceremony.

2. Cannot declaratively manage interaction logic

As a man, I partition everything and will stereotype anything. Code is no different. I have found value in separating interaction logic from view-models. I have also found XAML to be more maintainable because it does adhere to separation of concerns. Hence, XAML is focused on interaction logic only. As I attempt to adapt to Android development, I do not have this type of separation. In an activity, I have state and request management mangled together. Because of this cohesion, this code becomes more challenging to test and maintain.

3. No data binding

Data binding reduces the plumbing code that I would have to write for the UI to reflect a model’s state. Android does not appear to have this support yet. As a result, more code has to be written to connect the UI to the model.

In conclusion, I am recognizing how spoiled I am with Visual Studio. There are several productivity tools that the IDE provides that I took for granted. I hope that Android studio continues to evolve at a rapid pace because going from Windows Development to Android Development is painful.

NOTE:

Scott Nimrod is fascinated with Software Craftsmanship.

He loves responding to feedback and encourages people to share his articles.

He can be reached at scott.nimrod @ bizmonger.net

I have added a code snippet to quickly declare messages for pub/sub architectures.

These messages can be used in conjunction with the MessageBus I have provided on Nuget.

If you are unfamiliar with a MessageBus, then checkout my article on it.

Enjoy!

NOTE:

Scott Nimrod is fascinated with Software Craftsmanship.

He loves responding to feedback and encourages people to share his articles.

He can be reached at scott.nimrod @ bizmonger.net