Thursday, June 11, 2015
Loving my neighbour "as myself"
I would like to propose a thought experiment that probably does not reflect reality, but does immediately reduce our judgemental attitude towards others while increasing our compassion.
And here it is:
What if you got to the end of this life after doing your best, and found out you have not just lived one life on earth, but many lives. You were the worst of humanity and you were the best of humanity. You were that annoying person, and you were that useless person. You were a hollywood star, and you were a prostitute in Calcutta.You were Ghandi, and you were Ted Bundi. You were the pastor in your church, you were your own abusive father. You were all the people you thought you could never be, and all the people you would never be. You find out that all the other people in your life were not just "doing their best" , but they were in fact you doing your best.
I want to assume that if I was someone else I would be making different choices, doing better. I want to say "I am doing well because of my good choices". "Your attitude, your issues are because of your bad choices." "If I was you I would just choose different." I'm becoming more aware with age that my choices are really limited to the options that are given to me. And even when given good healthy options I have chosen to go with the unhealthy ones. I am not above reproach. But I am still doing my best. I have been stuck in bad habits and addictive thinking patterns, and I have found relief and victory not because I am good, but because the answers became available to me as I struggled to find happiness.
I'm not projecting that we don't have free will, and that everyone would make the same choices given the same situation. I'm just asking the question: Why do I assume I would be doing better? Do I really think there is something more noble, more flawless about my consciousness than my neighbours just because I think I'm doing better than them?
When thinking about our human experience being shared in this way, I realise I am so small minded to think only of improving the quality, purpose, and happiness of my own life. If everyone is me, and there is only one person here on the earth, I am suddenly overwhelmed by the brokenness and pain of humanity. All my judgements of others are immediately nullified through identification. I am living everyone's broken life. It's me that desperately needs help. It's me that is stuck without answers or options. Its me that is powerless to change without help.It's me that is abusing and fighting and taking advantage of and impoverishing others, all because I don't know (or cannot choose because of my own pain) a better way.
But I am also encouraged. I don't need to think of the changes I make in this world being limited to what one man can do in one lifetime. Humanity must move forward. I have learned to love and see others as equals, and therefore everyone can. It may take many more generations, but I believe in the power of free will to make our lives better. I believe in the character of God. I believe we are slowly learning to become one humanity, where we truly see "our neighbour as ourself"
Sunday, October 24, 2010
Fleshing out a Remote User Interface in C#
Following my previous post where I threw some ideas out about how to architect a remote WPF user interface, I have now had the chance to flesh out more of the details. I will attempt to dig a little deeper into the implementation without getting bogged down with the details in this post.
- View-Model classes are data-only classes that implement INotifyPropertyChanged in order to inform the view when properties (or collections) change state.
- The only functional behaviour associated with these classes is achieved by providing properties that implement the ICommand interface.
- All instances of objects are instantiated by the model, never by the view
[ServiceContract]
public interface IProxyViewModelService
{
[OperationContract]
Instance GetViewModel(string sessionId);
[OperationContract]
List<ViewModelUpdate> GetUpdates(string sessionId);
[OperationContract]
void SendUpdates(string sessionId, List<PropertyUpdate> updates);
[OperationContract]
void SendCommand(string sessionId, CommandInvocation commandInvocation);
}
- Serializing the current state of the view model object so it can be re-created on the client
- Provide notification of property-updates and collection-modifications to all registered clients
- Applying updates to properties from the clients
- Keeping track of registrations
- Reconstructing view model objects from the serialized form as provided by the server
- Applying collection modifications and property updates as they are propagated from the server
- Notifying the server of changes to properties that the client makes
- Mocking ICommand interfaces to invoke service calls
I must explain that although the ViewModel class should conform strictly to the requirements I specified at the beginning of the article, there is one more requirement that I must mention. It must have a parameterless constructor so that the proxy object can be created on the client side. This poses a problem: Often our server side objects have dependencies (on database repositories and the like) that should be passed in on the constructor. To support this scenario there needs to be some mechanism for the implementation of the View Model to inherit from a base class. It is the base class that defines the interface that the View requires, and it is the base class that will be de-serialized on the client.
We can see from the diagram above that the view can be programmed independently of whether it is a remote interface or not, except for the knowledge about whether the session/connection is still alive. A small consideration when trying to provide a WPF UI to a Windows Service by any other means!
Tuesday, September 14, 2010
Remote User Interfaces in WPF
- keep the user interface responsive, and
- not waste cpu time and network bandwidth when there is nothing to update.
- Build up a tree of service objects that perfectly describes the state of the entire view-model so that it can be transferred over the wire and replicated at the UI end.
- Identify each object by a key (it's path in the tree?) so both server and client can notify of changes to that object
- Watch every watchable object in the view-model and queue the state changes so it can be picked up when the UI polls.
- Keep track of who the live clients are, with timeouts/ max queue size.
- Dynamically construct a view-model from the tree it gets from the server upon registration.
- Transfer method calls on view-model interfaces into an equivalent service call to be invoked on the "real" model ( e.g. SaveCommand , RoutedCommand)
- Translate property changes and communicate them to the server as{objectId,propertyName,newValue}
- Poll for property changes (in background thread), and apply them to the replicated-model (in the dispatcher thread)
- The client will recieve a tree representation of the entire viewModel (with all collection items) when it registers itself. It might use it's IP address as it's registration id.
- The client will poll (using it's registration id), and the server will block and wait for something to happen to the viewModel (namely the LogMessages collection getting modified)
- As soon as a log message comes in the server will reply with a status update (in this case it is a collectionChange{item inserted at 0} for the object identified "ILogViewModel\LogMessages")
- The client inserts the LogMessage according to the update it received
- The Wpf binding ensures that the view is updated also.
Monday, June 7, 2010
Should programming languages be extensible?
Introduction:
Modern object-oriented programming languages provide, at their most basic level abstraction (through interfaces), encapsulation (through private class members) , programming by difference (through inheritance/decoration), and composition (of data through containers and of logic through declaring sequencial operations) . These 4 concepts give us the power to divide a complex problem into more bite-sized chunks, providing knowledge barriers in order to hide information unrelated to the bite-sized piece the developer is working on at the time.Modern languages also inherit some very important but non-object-oriented abstractions too. This is because some abstractions we would like to create do not naturally fit into the object-oriented model where data and logic are encapsulated together. Some examples are :
- Purely functional abstractions (like mathematical operators)
- Pure data abstractions (like DTO's)
- Memory Management
- Threading issues like deferred execution, locking, asynchronous calls
- Aspect oriented programming / cross-cutting concerns
The more language features we include, the more complex the language becomes. This is why most popular languages only implement the features that increase productivity, and leave out the ones that create more reliable code. Besides, some of the abstractions can be massaged into an object oriented framework or library. The only problem with using the OO counterparts is:
1) The syntax does not have a natural language type flow
2) There is no compile time checking
3) They often rely heavily on reflection.. a feature which typically has costly performance overheads
This article explores the concept of giving the developer the ability to pick and choose language features, or even create new language features specific to their domain.
The way we do things currently
From the application developers point of view, the language he uses should be everything he needs to express the requirements in a non-ambiguous way. This is achieved by providing language layers, of which only the bottom layer is the actual programming language. Each layer can function as an extension of the layer below it, or it could hide the details of the layer below it. The former case is similar to inheritance, the later similar to encapsulation.Here is an example of a typical web services application and it's layers
| Application wiring (often represented with a diagram, or as a IOC-configuration file or web.config) | |
| Features (The part that most closely represents the requirements specification) | |
| Reuseable framework and library components | Domain specific classes (encapsulate the business objects) |
| Compiler language | |
The way of the future?
I would like to suggest another layer just above the "Compiler language". I think the compiler language should be very simple and support very few features. Just above this layer should be a set of features that are part of the compilation process, providing language elements that are executed and verified at compile time.In the same way we include namespaces in a class header file we should be able to import just the language features that are needed . This could be defined at the scope of the application, or more finely scoped to the namespace/class level. If we were able to do this, then the base language would be able to support any number of arbitrary language features, even ones that are mutually exclusive of each other.
One thing is for sure. If we had the power to create our own language features, we wouldn't be waiting for microsoft to bring out their next release of .Net before we start using generics(v2.0), link(v3.5), or dynamic types(v4.0)! It would also be very nice to not have to develop your modules in Java just because you want checked exceptions, or Eiffel just because you want design-by-contract.
So what are the roadblocks to providing this kind of extensibility? We have been creating applications that are reliable and extendable by using good OO techniques and test driven development for years. We can add modules in small units and verify the application works as expected. Is it too hard to apply the same principles to compiler design?
I'm looking for some feedback on that question.
The base-level-compiler would need to provide only a few language features, plus hookins for the feature extensions. The compiler could be re-compiled and retested with each new feature added, or it could provide a plugin type architecture.
Concrete examples of things you could do with an extensible compiler:
- Language features to support state patterns, and then on top of that syntax like: until (some event) do {...}
- Being able to extend the metadata of a class without modifying the class's definition.
- Many frameworks and toolkits that use reflection , dynamic code generation, or code weaving can be re-written to do their work at compile time.
Roadblocks in C#
It seems that in C# many language features are hacks where the compiler needs explicit info on class definitions in order to do lots of "special case" compilation. For example [AttributeUsage] and [ThreadStatic] attributes. The compiler has specific knowledge of these attributes, which shows a dependency of the compiler on a compiled MSIL library??!! Other examples are :- foreach/yield -> depends on IEnumerable
- using -> depends on IDisposable
- try/catch -> depends on Exception
- linq -> depends on IQueryable
- dynamic -> depends on DynamicObject
Writing code for processors with many cores
Tuesday, March 9, 2010
Inversable Functions
string urlEncode(string plaintext){ .. contents... }
string urlDecode(string encodedtext){ .. contents... }
Have you ever noticed that the code in the second function is just doing the inverse operations of the first , but in the reverse order?
That is redundant code in my mind. And redundant code has more opportunity to introduce bugs because I may update the first function and forget to update the second , or update the second incorrectly.
We should therefor have a general programming construct whereby we can mark certain functions as inversable. A function is automatically inversable if it is itself an ordered collection of inversable functions/operations.
In this way we should be able to use an inverse operator like so:
string url = urlEncode("52%");
Assert.AreEqual("52%",^urlEncode(url));
Or something like that anyway... Notice the ^ operator for doing the inverse.
Or maybe we could declare the name of the inverse function in the definition:
string urlEncode(string plaintext) : inverse urlDecode
{ .. contents... }
which generates a comiple error if the function is not actually inversable. Then we can call
Assert.AreEqual("52%",urlDecode(url));
Saturday, July 18, 2009
Introduction
I'm Andrew, a developer working predominantly with C#.
I've only really been in the game for about 3 yrs now, and I have a lot to learn, but I'm starting to feel like there's a lot we can do to improve the way we program.
I'm not a fantastic researcher, I'm more of "an ideas man" (think The Castle). There are lots of times I am looking for a solution to really common programming problem, and I just cant seem to find any solution that solves it in a really abstract and complete way.
The solutions we have (ie languages,toolkits,frameworks) provide useful abstractions, but are more often than not leaky, and nearly always incomplete. I say an incomplete abstraction nearly always increases the amount of knowledge required to understand a section of code.
In the mathematics world we have a beautiful abstraction called a matrix. If we can turn a set of simultaneous linear equations into a matrix, it represents a very useful and complete abstraction that we can do all sorts of simple operations on. Like find an inverse, or an eigen-vector. It takes some time to learn the abstraction, but by golly once you learn it you never have to look beyond the surface to see whats actually happening underneath.
As I've been working with C# 3.5, NHibernate, CAB (Composite Application Block) , ASP.Net, and the Microsoft MVC framework, I've been noticing some real holes, and being a person who is not content to just complain about things, I've decided I need to put some ideas out there on where the existing solutions don't cut the mustard, and some suggestions as to what we could do about it.
I hope that by putting out my ideas, and getting lots of criticism, that our communal understanding would be refined, and we will come up with some really useful stuff that might actually change the way we program!
