Wednesday, July 16, 2014

The Flaws in Microsoft’s Windows Store (Windows 8, 8.1)

There is no question that Microsoft’s Windows Store is convenient.
  1. It allows people to download applications in a seamless way.
  2. It allows easy upgrades of applications.
  3. It’s an incredible platform that allows anyone to develop and sell applications that can compete with the big players.
  4. It is more secure than regular desktop apps since Microsoft verifies applications before posting.
However, Windows Apps have a few major issues that Microsoft needs to address.

1: Performance

Microsoft’s Windows Store Apps have horrible startup performance.
Try this performance test on Windows:
  • Open Visual Studio and create a new Windows Store Application
  • Run the application without changes
The splash screen appears.
SplashScreen
After a few seconds, the main app starts.
  • Switch to either the desktop or another Windows Store app
  • Switch back
The splash screen appears again and stays there for at least a second.

Why does it take so long for the application to start, even though there is no user code?

The answer is that Windows stops the application and saves its state. It then reloads the app when the user switches back.

2: Attention Hog

Imagine you execute a command that takes ten seconds to complete. If you were running a traditional desktop application, you could switch to another program and then switch back when the application completes its task.
Unfortunately that is not an option with Windows Store Apps. Windows pauses the application the moment you switch away from the app.
It is true that applications can do some background work while paused. However, in my opinion, this will make the application unnecessarily complicated.
Also, Windows only gives the application 2 seconds of processor time for every fifteen minutes of run time*. That means the application might take hours to execute a command that would otherwise take seconds.
Currently the only thing the user can do is sit at the computer and do absolutely NOTHING while the application does what it needs to do.
Many applications work best when run in the background. A perfect example is your music application. It plays music in the background while you do other things. A Windows Store App is currently not an option since switching away would shut off the music.
I like listening to WARM 106.9 in my web browser. (URL: http://player.liquidcompass.net/KRWMFM) How would I listen to that if the web browser were not in the front and taking up monitor real estate?


The same is true for video processing applications that perform time-consuming tasks.
> Windows Store applications force users to give applications 100% of their attention and prevent them from multi-tasking.
What can be done?
The solution is to allow the user to decide if an application should be paused when switching away from it.
Ideally the user should have two choices:
  1. Users need a global switch to turn on or off whether all Windows Store apps are paused
  2. Users need to be allowed to create exceptions. Ideally users should be able to do this through the task manager.
Since the ability to pause an app affects power consumption, it would make sense that it be in ‘Control Panel\Hardware and Sound\Power Options’.
The user would then choose application sleep options based on if the computer is plugged in or if it is running on batteries.

By letting application run in the background like regular desktop applications, the time delay for switching applications should be eliminated. This would give users a better user experience.

3: Windows Store Crashes

I notice that Windows Store applications can be very temperamental. For example I sometimes like playing Microsoft Solitaire or Mahjong. However, it tends to crash a lot when I do the daily challenges. This tells me two things:
  1. Microsoft’s Windows Store is running on Windows Azure and it is close to its limits.
  2. Windows Store applications can’t handle when connectivity is an issue.

4: Conclusion

Windows Store applications could be incredible if Microsoft fixed the performance issue. They also can’t be run as desktop applications. This means some applications, such as a music player, can’t be packaged as a Windows Store application.
My desktop computer is not a phone. Why should I be limited to what a phone can do?
* Professional Windows 8 Programming, Application Development with C# and XAML, 2012, ISBN: 978-1-1182-0570-9, page 168

Object Oriented Programming (OOP) Tutorial

In this blog I would like to present a simple tutorial on the basic principles of Object Oriented Programming (OOP) and the design patterns that are the basis of modern programming.
For convenience I will be using C#.

1. History

The principles of object oriented programming existed even before modern computers came into being. However the so-called 






1. Basic OOP Concepts

Object Oriented Programming is built on three principles: Encapsulation, Inheritance, and Polymorphism.

1.1. Encapsulation

Encapsulation allows you to hide data and implementation details and expose them in a controlled manner through publicly exposed methods.
Objects are self-describing things with internal structure not visible to the external world. They encompass one single idea or concept and they provide methods that allow external objects to interact with them.

1.2 Inheritance

Inheritance allows you to create a new class, using the previously defined methods of a base class.
Your new class will expose the existing methods of the base class as if they were newly defined. As such, creating a method with the same signature as the base class will hide the method in the base class.
NOTE: Inheritance is not polymorphism.

1.3. Polymorphism

Polymorphism occurs when an instance of a child class is treated as an instance of a parent class. Calling a method on the parent class will then express different behaviors, based on how the child class has overridden the parent class method.

Example:

As an example, you have a class called ‘Printer’. It defines certain actions, such as ‘Print’.
You then create a child class called Cannon 233. In this class you override the Print method.
You then call the ‘Print’ method on Printer. Since Printer is an instance of Cannon 233, the document is printed using the implementation encapsulated by Cannon233’s overridden method.
NOTE: In C#, polymorphism doesn’t occur unless you use either the key words virtual or abstract.

1. 4. OOP-Class

A class is the basic construct in Object Oriented Programming. As such it supports Encapsulation, Inheritance, and Polymorphism.
Note: When people talk about classes, they are referring to pure abstract classes that don’t have any implementation details. All you have are method signatures. As such, multiple inheritance is allowed.
For example:
pubic class Printer
{
    int PrintDocument(Document doc);
   
    Preferences GetPreferences();
   
    void Cancel(int cancelToken);
}

An important thing to keep in mind is that it is not the intent of OOP to prevent code duplication. That is just a side-effect of proper OOP design.
1.4.1. Responsibilities
  • Data Consistency: A class is responsible for making sure that the data it encapsulates is in a legal state between method calls.
  • Data Hiding: Class fields (integers, strings, etc.) should always be private. This data should only be exposed through methods.
  • Data initialization: It is the responsibility of the class to begin its life in a consistent state that is useful to the user.
  • Resource Management: Classes must make sure all resources are returned to the system when a task completes.
1.4.2. Data Structures
There is a fundamental difference between a class as defined in OOP and one as defined in a modern language such as C#. Unfortunately they both use the same name, which causes untold confusion. As such I will use OOP-Class to refer to the idea that OOP tries to encapsulate.
The following are various data structures relevant to modern programming…
C# Class
Supports: Encapsulation, Inheritance, Polymorphism
The C# class is the what people think of when they say ‘class’. C# classes are OOP-Class, since they enable encapsulation, inheritance, and polymorphism.
The fact that C# classes are reference types and reside on the heap is not relevant to the concept of an OOP-Class. That’s just an implementation detail.
Interface
Supports: Encapsulation, Inheritance, Polymorphism
The C# interface is the closest thing we have to the classic OOP-Class. The reason is that it only defines the operations in terms of method signatures. As a result, multiple inheritance is possible.
Interfaces are important since they are the basis for many design patterns.
Struct
Supports: Encapsulation
In C#, a struct is Not an OOP-Class. The reason is because it doesn’t provide inheritance (and polymorphism).
Structs are data structures that are used to implement integers, floats and other value types, including composite values.
Structs implement encapsulation. As a result, methods are exposed to modify its internal state.
C# Enums
Supports: <None>
In C#, an enum is Not an OOP-Class. The reason is because C# enums are just named lists of built-in numeric types such as int and float.
Java Enums
Supports: Encapsulation
In Java, the enum is a type of struct that has methods and internal states. However, just like enums, they don’t offer inheritance.
Prototype Collection
Supports: Encapsulation, Inheritance
See:
1.4.3. Objects
Classes define functionality. However, you can’t do anything unless you define an object and assign it states that are useful to the problem at hand.
An object is a data structure containing internal data that is in some valid state.
C# Objects
Objects are self-describing things with internal structure not visible to the external world. They encompass one single idea or concept and they provide methods that allow external objects to interact with them.



1.5. Methods

In OOP, methods encapsulate the specific single action you take to transform your data from its initial state to its final state.
The purpose of methods is to encapsulate actions performed of input data. When creating methods, you must ask yourself – What are the logical operations you are exposing through your API?
1.5.1 Method Variations
In traditional OOP, there is classes only implement methods. However, modern languages have variations on the theme. This allows us to encapsulate different design patterns within the language.
Methods





Properties
In C#, properties allow you to encapsulate internal fields and expose them to the caller. This allows the class to enforce policies that ensure its internal state is always consistent between method calls.
Static Methods
Static fields and methods are an odd thing in OOP. They don’t exist in traditional OOP.


























1.6. Conclusion

A programming language is considered object oriented if it implements a class as defined above.
According to the above definition C++ is an object oriented programming language.
That’s so last century. Smile with tongue out
When I think of OOP, I think of languages such as Java and C#, where everything is an object. It is impossible to program without creating a class definition and then calling methods on the class.
With C++, object oriented programming is possible, but not required.

2. Design Patterns

Design patterns are a funny thing. Everyone who has programmed with modern languages use the patterns without knowing that they are doing so. The reason is that many of them are built into the language.




3.1.1 Struct

A struct is a special type of class that is used to define values or collections of values.
The fundamental difference between a value type object





Reference