Angel “Java” Lopez on Blog

October 14, 2009

Time for simplicity?

Filed under: Software Development — ajlopez @ 12:00 pm

These days, Ted Neward wrote a very interesting post “Agile is treating the symptons, not the disease” quoting a phrase of Billy Hollis, from Patterns and Practice Submit this week in Redmond. I read:

“A lot of software written back in the 90’s was written by 1 or 2 guys working for just a few months to slam something out and see if it was useful”

“The problem is the complexity of the tools we have available to us today preclude that kind of software development.”

I see the problem is more associated with technologies, not with the tools. Web services, as example. For me, web services are not a tool, like libraries, compilers, or IDE. Web services are technology. Most of the tools (i.e. Eclipse, Visual Studio) are fighting the complexity of the underlying technologies. 1 or 2 guys, today, can still create a wonderful open source library, but try to write with the same team an enterprise application, involving database, communications, security, manageability, instrumentation, and so on. There are lots of details in the underlying technologies to implement, that the complexity of any non trivial application could be (and usually is) dauting.

Back to web services. Did you visit Wikipedia page about that topic, recently? You’ll find dozens of specifications. You could spend weeks or months, trying to grasp all the technicalities involved in WS-Trust, WS-Addressing, WS-Transaction, WS-PutYourWordHere. I guess REST style adoption is a reaction to such madness (REST style, not REST principles, or RESTFul). Sometimes, libraries are coming to rescue, and sometimes, their fail. My preferred example of a failed trying to hide web service complexity is Windows Communication Foundation (WCF). I wrote about this at Windows Communication Foundation configuration madness.

Complexity in software, is not bad for itself. It could be good. Software is in every human activity. Internet popularity, fueled by the World Wide Web adoption, is now in practically every place of our days. As software developers, we are contributing to such progress. We are not pursuing our comfort zone, we are looking for software value.

Now, customer requirements are more challenging: massive multiuser access, scalability, distributed processing, online availability, are usually included in most of current enterprise applications. And there is no simple solution now to cover all the corners.

Said that, complexity is still with us, and it could be fighted. I spend most of my work hours teaching programming, and the rest of the time working on software development. I suffer the complexity of the current state of affairs in software development. The amount of details to take into account (ORMs setups, dependency injection configuration, testing setup, mock libraries, WCF or JBoss configuration… ) is so big, that our minds are lost in the middle of such jungle.

Do you remember Petzoldian age? Lots of lines to write a simple “Hello world” program that runs on Windows. Then, Visual Basic was born. Visual Basic was an effective way to hide the Windows API and behaviour complexity, saving generations of developers of struggling with handles, and LONG values where the mouse coordinates are coming in the Windows messages. That was hell, truly hell.

Do you remember reading VTOCs in IBM disks? Writing Job Control Language? Writing macro assemblers? For each of those tools, there were a solution that hides the underlying complexity, using the “old trick”: raising the level of abstraction. Instead of thinking in registers and sectors, we could manage variables, and SQL statements.

I guess it was end of eighties, beginning of nineties, were the software development in PC arena reach the top of power/complexity ratio (Turbo Pascal, Visual Basic, Access): lots of power, low complexity. Since then, we are in a free fall. The “old trick” of “rise the abstraction level” didn’t embrace again: we are still building software using third generation languages, the macro assemblers of the sixties.

One way to escape is going for the next level of abstraction. We forget about registers and Branch And Link Register instruction and adopted general programming languages. Now, we need to write software in a higher level. My bet: Domain Specific Models and Languages. But it’s only a bet. Using DSLs, DSMs, code generation (do you realize that compiling your C# program is “code generation” NOW?), we could leverage the existing technology, hiding the underlying complexity.

With so many languages, libraries, technologies to use, there is no simple solution to hide all this mess. Note that there are many kinds of complexity. One is the complexity of the customer requirements: business logic, functional requirements. That’s ok. And I think that agile methodologies are attacking such kind of complexity. But the complexity that hurts us now, is the technological one. We should stop the journey towards a Petzoldian age. (recently, I found the concept of Accidental Complexity, in a Rich Hickey talk (hmmm… I guess he named it as incidental complexity). From Wikipedia page about accidental complexity:

Accidental complexity is complexity that arises in computer programs or their development process (computer programming) which is non-essential to the problem to be solved. While essential complexity is inherent and unavoidable, accidental complexity is caused by the approach chosen to solve the problem

)

Another interesting posts, triggered by Neward original one:

Jeffrey Palermos’s Response: “Agile is treating the symptoms, not the disease” by Ted Newardç
Phil Haack’s Software Externalities
Ted Neward’s response to Haack Haacked, but not content; agile still treats the disease 

I have so much to comment about all these writings and thoughts. But they deserve other commenting posts, not to comment now.

I want to remember one more thing here: complexity is not the only challange in software development. Every succesful project could suffer of complexity AND change. Those are the problems agile methodologies are treating: fighting complexity with baby steps, eating an elephant piece by piece, and stop fearing change, embracing it, adopting disciplines to lower the cost of change in the middle of the development.

Another point: with Internet adoption, our current software development culture is flourishing, with so many ideas, reference implementations, open source libraries, patterns, practices, frameworks, and programming languages (there a new set of dynamic languages, mounted over Java and .NET). The Pandora’s box was open: I don’t see any way to close it.

In his cited post, Ted Neward wrote:

Let me rephrase Billy’s talk this way: Where is this decade’s Access?

I have some ideas, to response to that question. But now, I should go to teach .NET: I hope no big complexity hurts today class.

(Note: English is not my mother tongue, so, feel free to suggest corrections to my writing. Most of my ideas about the complexity subject should be expressed in a short way, that could be clear enough, I hope still this post could be understood: this is a fascinanting topic: how to improve the creation of software?)

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

September 8, 2009

Microsoft Surface Demo: Patient Consultation Interface by Infusion

Filed under: .NET, Interface, Software Development — ajlopez @ 9:40 am

Currently, I’m working in an agile team, development a health care and administration application. I’m a newbie to health development world, but I’m impressed about the complexity and variety of requirements and opportunities to explore and exploit. It’s an exciting field for development.

Presenting patient information to medical professionals can be a challenging job. One of the team members just discovered this video, from http://www.infusion.com Microsoft partner, demoing a Surface application to view patient information:

I read at Youtube video page information:

MICROSOFT SURFACE PATIENT CONSULTAION INTERFACE
The Microsoft Surface Patient Consultation Interface enables doctors to relate complex concepts through simple interactions.

APPLICATION COMPONENTS

The Surface Patient Consultation Interface augments and facilitates the conversations that a doctor regularly has with his or her patients through a unique, interactive representation on the Microsoft Surface. With the use of static and active media elements, a doctor is able to demonstrate and relate complex medical procedures or conditions in laymans terms to their patients.

Doctors are able to use this tool to exchange content and information with their patients, adding a feeling of security to the transfer of electronic information between doctor and patient. Through the use of slide menus, touch interaction, and a simple navigation system, the application gives doctors the opportunity to provide their patients with a valuable educational experience.

The application is divided into 2 distinct views and makes use of five interaction points:

VIEWS:

The Content View allows the viewing of shared content in a free-form fashion. This view facilitates easy observation and a simple summary of any topics shared during a session.

The Anatomic View presents content for viewing in the context of the human body. This view enables the uncomplicated observation of specific diagnosis information and educational content.

Within both views, content can be manipulated to allow doctor and patient to easily see and access information together. The three primary forms of content that can be displayed include: documents, photographs, and videos. The capability also exists for presenting additional content such as 3D models.

INTERACTION POINTS:

The Content and Anatomic views are traversed via 5 common elements.

PERSONAL IDENTIFICATION components enable both the patient and doctor to share and store information. Identification occurs when the patient or doctor places their identification card on the Surface. For the patient, the identification card provides the ability to share and receive content from their Microsoft HealthVault account. For doctors, identification allows them to share generic and educational content with the patient.

The ANATOMIC LOCATOR enables the doctor to focus on a specific area of the body. This action is performed by selecting and manipulating one of five body types that can be used for accessing content: exterior, organ, circulatory, nervous and skeletal.

The ORB MENU draws data from the patients HealthVault account when a patient enters the content view. This hierarchical and easily navigated menu enables the selection of new content for the current session through the selection and dragging of content orbs located near the patients HealthVault card.

The WEB MENU allows the doctor to display content within the Anatomical View. Once a body type is selected, key points on the body relating to the shared content are highlighted. This content includes documents, static images, and videos arranged around the point of interest.

CONTENT ITEMS are a part of the overall interaction within the application and consist of documents, photographs, and videos. These multimedia tools are embedded into the patients information, interaction points within body types, or any other educational portion of the application.

To learn more about Infusion and Microsoft Surface, visit: www.infusion.com or email surface@infusion.com.

More info about Infusion works with Surface, at their blogs:

http://www.infusion.com/surfaceblog/

There are interesting topics, as tips for Surface development and UI design.

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

March 30, 2009

First sabbatical week 2009

Filed under: Software Development — ajlopez @ 9:13 am

Past Friday I started my first sabbatical week of this year. This “extended week” should end at Monday April 6th. But the current project I’m working on was extended one more week. Usually, I don’t teach classes, nor give any speech, but this time, cause of rescheduling of other activities, I’m going to give an Scrum course and a .NET class.

So, I decided to commit to some technical goals, but to be accomplished in two weeks, before April 13rd.

The list includes:

- Write a blog post to explain the motivations and initial ideas to implements in AjProcessor.

- Minor improvements (.NET object access support), medium-size refactoring, and first published version of AjCat, and post.

- Add full support to blocks, block context, indexed variables in AjTalk, and post.

- Write and publish a post about AjPepsi.

- Initial code of a new open source project, this time in Java, and post.

Well, that’s all. I would like to put more focus in this week, but this time, I should attend other duties.

As usual, I’ll publish a closure post with the resulting outcomes.

Angel “Java” Lopez
http://www.ajlopez.com/
http://twitter.com/ajlopez

March 11, 2009

TDD and Code Kata: Writing a Lexer for AjRuby

Filed under: C Sharp, Programming Languages, Software Development — ajlopez @ 7:20 am

Usually, I write programs as code katas, to train me in some software development topics. During last months, I wrote many mini interpreters, using TDD-like approach, code coverage, and C#. Past week, I was working in the kickoff of yet another one, AjRuby. The starting point: the lexer.

A lexer is a program that analizes a source code text, and returns the tokens, the "words" that compose the program. In the case of AjRuby, I wrote a lexer that follows the Ruby language grammar. It’s not complete yet, but it’s working.

You can see my progress at my code katas Google code project:

http://code.google.com/p/ajcodekatas/source/browse#svn/trunk/AjRuby

The solution has a library project, and a test project:

It has a Token class, that represents each token:

public class Token { public string Value { get; set; } public TokenType TokenType { get; set; } }

The TokenType is an enum:

public enum TokenType { Name, Integer, Real, Boolean, String, Operator, Separator }

There is a LexerTest.cs class, containing tests like:

[TestMethod] public void ShouldProcessName() { Lexer lexer = new Lexer("name"); Token token; token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Name, token.TokenType); Assert.AreEqual("name", token.Value); token = lexer.NextToken(); Assert.IsNull(token); }

There is a test for every kind of token to be processed. Other example:

[TestMethod] public void ShouldProcessNameWithInitialUnderscore() { Lexer lexer = new Lexer("_name"); Token token; token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Name, token.TokenType); Assert.AreEqual("_name", token.Value); token = lexer.NextToken(); Assert.IsNull(token); }

I wrote the tests using TDD ideas: write the test, compile with error, fix the compiler issues, run the tests in red, fix them, get green status. I skipped most of the refactor steps. I guess the tested code could be improved, but by now, I’m trying to get a working lexer. The tests are in green state, good!

My goal is to have > 80% of code coverage, at any time during the project development:

It’s good to write something only for fun and learning. For me, it’s part of the continuous improvement every software developer should pursuit.

Angel "Java" Lopez

http://www.ajlopez.com/en

http://twitter.com/ajlopez

March 4, 2009

Windows Communication Foundation configuration madness

Filed under: .NET, Software Development, Windows Communication Foundation — ajlopez @ 10:09 am

Windows Communication Foundation was created to support the creation of distributed applicacions, trying to give us a library of communication tools, so we can reuse it, without writing the service gateways and service interfaces from scratch. Technologies like web services, evolved, and there are many versions and details to take into account if you want to have secure, relaible and interoperable communication.

The concept of a Service Model, is a great advance. But today, I have to raise my hand, only to point to something makes WCF a convoluted solution. I’m referring to WCF configuration.

If you want to use any WCF feature, beyond the simplest one, quickly you’ll be fighting with the configuration options of this beast. What is the sympton? If you miss some minimal part, your channel doesn’t work. If you miss some configuration option when creating a certificate, if you forget to do one step in a dozen or more of “to do list”, your call will not work. And you have to manage a lot of concepts, like certificates, tokens, issuers, chain of trust, behaviors, bindings, endpoints, identities, custom bindings, factories,  service hosts, channel factories, security options, enumeration types, extensions methods, and …. I could continue for hours.

A minimal example. I just browsing the web, and I found the article

WCF (Windows Communication Foundation) Example

I read there:

Being able to switch the transport layer from TCP (Secure SSL) into HTTP with some simple code, that’s amazing!

Yes, but

I did have some problems, though. The tcpBinding.Security.Mode = SecurityMode.None; is very crucial on both sides. I’m not sure what it does, but it does not turn off the security completely as I have read in my references. There is still SSL encryption, but on a lower level. It is possible to add certificates to the connection, which also makes the connection more secure.

That’s the problem. If you play exploring the different properties and methods of binding and endpoints, you’ll enter a maze without visible exit. Notice that the author is not sure about one of the configuration he is using. And this is only one option: you have dozens more to set, if you want to fine tune your service.

Yes, there is declarative configuration. You can use the WCF configuration wizard:

Ok, can you see the three tabgs, at right? They have more options to fill and understand! Can you see the tree at left? It’s only the top of the iceberg. If you expand the bindings, you’ll enter a new Narnia world:

More properties to fill, and one more tabs! You begin to feel uneasy. If you have courage, create and expand  anything in the advanced branch:

The tree is becoming a amazonic forest. I could take snapshops of each branch this wizard exposes, to publish a complete volume. Most of these options ARE REQUIRED if you want to secure your service, use tokens issued by other systems, define the authentication of the client and service, and more. And my point is: if you fail in filling and defining a minimal part of this stuff, your system is a sand castle, a tower of cards in delicated equilibrium. This is the butterfly effect: a fly of a butterfly in one configuration file, could create an storm in your system. You must pay attention to too many details. It’s common to have to pay attention to details in software development. But I guess in this case, it’s too much: it’s insane to any single human mind.

In other systems, you have lot of options, too (remember the count of properties of any form control?). But you don’t need to master all (or halft) of the details. That is not the case with WCF configuration. This state of affairs sucks. And if you like to write down directly the XML configuration, you have to fight with something like this:

 

There are few uglier thing I met in my 30 years of software development (I could enumerate: EJB configuration, Cocoon ideas, Job Control Language in the old IBM mainframes…).

I have a theory. Enrico Fermi asked: if the extraterrestials exist, where are they? The story is: they exist. They began to study our planet (remember first “flying soucers”? They was seen at Mount Rainer at forties, near Seattle… yes, they were researching the origin of all this…). For decades, they read our literature, watch our film productions, made controlled experiments with some human beings. But when they began to study WCF and EJB configuration, our planet was doomed: they declared it under quarantine, we will be out of contact, isolated from the rest of the galaxy for the next ten thousand years. The humankind is a crazy civilization, there is no hope for our future.

Ok, I must stop whining. WCF has a great service model: now, it can manage JSON, XML, and it’s prepared to be flexible and extensible. But sometimes, we must stop the ball, and balance the flexibility with the accompaning complexity. This post is the result of days of fightings with WCF, WCF examples, documentations and guidelines.

Angel “Java” Lopez
http://www.ajlopez.com/
http://twitter.com/ajlopez

January 27, 2009

AjGa: a genetic algorithm library

Filed under: Artificial Intelligence, C Sharp, Software Development — ajlopez @ 7:15 am

I was coding a genetic algorithm library, using C#. The code is in my AjCodeKatas Google Code project, at:

http://code.google.com/p/ajcodekatas/source/browse/#svn/trunk/AjGa

The main project is AjGa (with AjGa.Tests for testing):

The main interfaces are:

I use generics, with two generic types: G, as the gene implementation type, and V, as the value type (e.g. int, double), that it will be used to catalog the genomes.

IPopulation is a colletion of genomes.

IGenome  is a collection of genes, that is evaluated to value.

IEvaluator is in charge of evaluate a genome.

The implementation of IEvolution runs generations over a population, employing mutator, crossover operators, to change the population composition after each run.

There are operator interfaces, to generate one genome, mutate an existing one, or apply a crossover over two genomes.

To test the ideas, I implemented a project with gene, genome, and operators, to attack the classical Travelling Salesman Problem:

In this example, an evaluator has a list of positions of cities to visit:

 

public class Evaluator : IEvaluator<int, int> { private List<Position> positions; public Evaluator(List<Position> positions) { this.positions = positions; }

The gene type is int, and tha value of each genome is expressed as a int. The genome keeps a list of integers, representing the ordinal number of the cities to visit:

 

using AjGa; public class Genome : BaseGenome<int, int> { public Genome(int size) { for (int k = 0; k < size; k++) { AddGene(k); } }

That is, each gene is an int, and a genome with 2, 0, 1 represents: visit the third city, then the first one, and finish the trip in the second city.

You can run the WinForm project, to test the library:

The above run has a random distribution of cities. The cities can be distributed in a grid:

This way, you can test the efficient of the algorithm to reach the optimum solution.

If you want to implement a new GA project, you should:

- Define the gene type

- Define the value type

- Some operators (creators, mutators, crossovers)

Tests are green:

Code coverage in fine:

I spent 4 hours in the first version, 3 hours exploring TSP, and around 8 hours preparing and tuning the TSP WinForm application.

As usual, I enjoyed write this software!

Angel “Java” Lopez
http://www.ajlopez.com/en
http://twitter.com/ajlopez

January 25, 2009

Presenting AjSoda

Filed under: Smalltalk, Software Development — ajlopez @ 6:38 pm

A year ago, I wrote a post, in Spanish, commenting Ian Piumarta work:

Self-sustaining sysmtes, Cola, Pepsi y Mate

I proposed that an implementation of Ian Piumarta ideas, in .NET or Java, could be possible. Instead of using C as underlying language, it could be reimplemented over a virtual machine language, with a rich class framework, and an automatic garbage colector. For me, it looks as an interesting idea, that deserves some attention.

To understand Piumarta and Warth ideas, they described a minimal implementation at:

http://piumarta.com/pepsi/objmodel2.pdf
http://piumarta.com/pepsi/objmodel.pdf

You’ll find minimal object implementation, in those papers. A diagram:

(taken from

Open Extensible Dynamic Programming Systems Dls

)

This past week, I was working on an implementation in C# of such ideas. I commited my work in my AjCodeKatas Google Code project, at:

http://code.google.com/p/ajcodekatas/source/browse#svn/trunk/AjSoda

The solution has four projects (two library classes, and the respective test suites). The main project is AjSoda:

 

An introductory diagram:

IObject is the interface I wrote to represent a generic object. It has a payload, an array of references to arbitrary .NET objects:

One alternative I considered, was to point only to IObject. But I want to have the feature of access directly to native .NET objects (or Java ones, if I change the implementation language).

The more important method in IObject is Send. Using this method, you can send a message (selector plus arguments) to any IObject instance.

IBehavior is my implementation of what Piumarta/Warth named a vtable. It is the object that containts the list of method that can attend the messages sent to an IObject.

Each IObject has a Behavior property that points to an IObject. I could had choose to point to an IBehavior, but in this way, the Behavior of an object can be replaced by any object that understand a #lookup: message selector.

I don’t need to implement the closure concept, as described in Piumarta/Warth papers. Using closures, they implemented slots a la Javascript or Selft. But I have no need to take that approach in my experiments, yet.

The main implementation classes are:

Each BaseObject implements IObject, having an internal array of objects:

public class BaseObject : IObject { private object[] values; public BaseObject() { } public BaseObject(int size) { this.values = new object[size]; } public int Size { get { if (this.values == null) { return 0; } return this.values.Length; } } public IObject Behavior { get; set; }

(Note that Behavior property is an IObject, as I explained above).

The more interesting method is Send:

 

public virtual object Send(string selector, params object[] arguments) { if (selector == null) { throw new ArgumentNullException("selector"); } if (this.Behavior == null) { throw new InvalidOperationException("No behavior in object"); } IMethod method = (IMethod) this.Behavior.Send("lookup:", selector); if (method == null) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unknown message '{0}'", selector)); } return method.Execute(this, arguments); }

I don’t use this.Behavior.Lookup to get the method associated with message selector. Instead, I’m using directly the Send method, so obj.Behavior can be mapped to any IObject that knows how to implement a method lookup. This feature has a performance impact, but it ables to implements new ways of dispatching a message. You can find in the cited papers, multiple inheritance and traits implemented using this extensibility.

AjPepsi

In the code, you’ll see an additional project, called AjPepsi, where I’m implementing a parser and a byte code interpreter, of the language Piumarta/Warth used as a proof of concept in their papers. It accepts code like:

Object new [^self class basicNew initialize] Object initialize [] List : Object(head tail) List head [^head] List tail [^tail] List head: newHead [head := newHead] List tail: newTail [tail := newTail] list1 := [^List new] list2 := [^List new] [list1 head: 'Hello'] [list2 head: 'World'] [list1 tail: list2]

Object and List are prototypes, but I should pospone any detailed discussion to a future post. AjPepsi is still under development; probably, I’ll make major refactoring and implementation in the next week. I took AjTalk code as a base, but I don’t sure it was a clever decision: AjPepsi is strong prototype oriented, so I spent ten hours refactoring AjTalk to fit AjSoda ideas.

One big next feature: as in the current implementation of Pepsi/Id/Cola, I’m thinking in automatic generation of underlying language code (in this case, C# code), representing the state of a machine (classes, methods, instances).

Test are green:

Code coverage is fair:

There are some smell code to refactoring, yet. Classical example: a big switch with lot of code in byte code interpreter. But the majority of such smell is inside AjPepsi code. AjSoda is taking form, going to an stable version. It took only 4 hours of my time to write AjSoda current code, but I’m spending a lot of time writing a complete AjPepsi interpreter/parser/machine (10 hours until today).

As usual, I had a lot of fun writing all this code!

More links about Piumarta/Warth ideas:

http://lambda-the-ultimate.org/node/2483
http://piumarta.com/
http://piumarta.com/pepsi/pepsi.html
http://piumarta.com/software/cola/

Comments, suggestions, welcome.

Angel “Java” Lopez
http://www.ajlopez.com/en
http://twitter.com/ajlopez

January 10, 2009

Microsoft Tag, a new world to make

Filed under: Software Development — ajlopez @ 10:29 am

If you have so many years in software development like me, you probably remember that, for a few months, at middle 80s I guess, software development maganizes began to include a printed long vertical rectangle with little squares, at the margin of an article’s page. In that way, the authors published source code: that image could be scanned and transformed to text files. It was a great idea, that it was forgotten after the distribution of diskettes (and years after, CDs, DVDs) in the software magazine issue.

This year 2009, Microsoft launched an IPhone application, with an wide set of uses: Microsoft Pad

One idea: every object, post package, mechandise, traveling stuff, could be coded with this tag, pointing to an URL with a REST/Web Service interface, where we can update the state/position of the object, using a simple app in our mobile devices. The endpoint could describe itself, the available operations to perform on object status. Each physical object could have an updatable state in the cloud, pointed by its own tag drawing.

My first contact with this tech, was via a twitter from @MartinSalias (another use of twitter: quick and light way of getting interesing news, it could replace the RSS readers of hundreds of blogs). These days, Arvindra Sehmi published a blog post:

Microsoft Tag – Snap. Blink. Wow!

More general info at Microsoft Tag home page:

http://www.microsoft.com/tag/

To make tags go:

tag.microsoft.com

and go to gettag.mobi to download the scanning application.

Other posts:

Microsoft Releases Tag, Its Second iPhone Application

Another Useless iPhone App From Microsoft- ‘Tag’ (MSFT)

Microsoft Joins the Physical World Connections and Interactions Space with Microsoft Tag

Angel “Java” Lopez
http://www.ajlopez.com/en
http://twitter.com/ajlopez

January 9, 2009

The Clean Code Talks — Inheritance, Polymorphism, & Testing

Filed under: .NET, Programming, Software Development — ajlopez @ 8:55 am

I’m a fan of Twitter. One account I’m following to, is @delicious_prog, that sends many tweets each day, related to programming and software development in general. In one of that tweets, I found the post

The Clean Code Talks — Inheritance, Polymorphism, & Testing

by Daniel Wild, where he includes a Google Talk video:

by Misko Hevery in Google Tech Talks.

It’s very clear and interesting. It’s a talk explaining the uses of polymorphism, and the way to test it. I pleased to find in this video many similar arguments to the ones I use in my dev talks. Recently, I was using polymorphism in my AjCat interpreter (a cat-like programming language interpreter written in C#)

http://code.google.com/p/ajcodekatas/source/browse/#svn/trunk/AjCat

This is my Integer Binary Operation: 

public abstract class IntegerBinaryOperation : Expression { public abstract int Apply(int op1, int op2); public override void Evaluate(Machine machine) { int op2 = (int) machine.Pop(); int op1 = (int) machine.Pop(); machine.Push(this.Apply(op1, op2)); } }

The Add and Subtract operations override the Apply method:

public class IntegerAddOperation : IntegerBinaryOperation { private static IntegerAddOperation instance = new IntegerAddOperation(); private IntegerAddOperation() { } public static IntegerAddOperation Instance { get { return instance; } } public override int Apply(int op1, int op2) { return op1 + op2; } public override string ToString() { return "add_int"; } }
public class IntegerSubtractOperation : IntegerBinaryOperation { private static IntegerSubtractOperation instance = new IntegerSubtractOperation(); private IntegerSubtractOperation() { } public static IntegerSubtractOperation Instance { get { return instance; } } public override int Apply(int op1, int op2) { return op1 - op2; } public override string ToString() { return "sub_int"; } }

It’s very similar to the example presented in the video. I was a bit lazy in my operator implementation in AjPython (an interpreter, again, in C#, work in progress):

http://code.google.com/p/ajcodekatas/source/browse/#svn/trunk/AjPython

 

public class BinaryOperatorExpression : BinaryExpression { private Operator @operator; public BinaryOperatorExpression(Expression left, Expression right, Operator oper) : base(left, right) { this.@operator = oper; } public override object Evaluate(Environment environment) { object leftvalue; object rightvalue; leftvalue = this.Left.Evaluate(environment); rightvalue = this.Right.Evaluate(environment); switch (this.@operator) { case Operator.Add: return (int)leftvalue + (int)rightvalue; case Operator.Subtract: return (int)leftvalue - (int)rightvalue; case Operator.Multiply: return (int)leftvalue * (int)rightvalue; case Operator.Divide: return (int)leftvalue / (int)rightvalue; case Operator.Power: return System.Convert.ToInt32(System.Math.Pow((int)leftvalue, (int)rightvalue)); } throw new System.InvalidOperationException(); } }

but I’m confident in refactoring, I have a test base covering this operators.

It’s good to find this talk, I recommend it, thanks to @delicious_prog and Daniel Wild!

Angel “Java” Lopez
http://www.ajlopez.com/en
http://twitter.com/ajlopez

December 30, 2008

Thirty years of software development

Filed under: Software Development — ajlopez @ 9:01 am

Thirty years ago, I was a teenager, living near Buenos Aires, Argentina, trying to decide what to do with my life. I knew some things about digital computers (enough to understand binary notation, logic circuits, 4 bits decimal digit codification…) but I did’t know anything about programming software. In those times, only few had access to a computer, usually IBM mainframes. By chance, I began to read about software, and I took a course on programmin. Then, my first program was written, in COBOL, IBM style.

I still remember the paper sheets that were used to write COBOL programs: rows and columns, comments must begin in column 7, upper case letter. Oh! Data division, procedure division, and the intrincacies of Environment division. Punched cards with inextricable Job Control Language commands, an extinguished (I hope) language with origins in ancient Egypt. PERFORM … THRU… OCCURS…. 01, 02, 88 levels, ooopps… Where is all that stuff now? Still running in many financial and banking systems.

But I had no computer to run the programs. I wrote programs, and test them in paper. It was not easy. All this was in late 1978. At the next year, I found a book about IBM 360 assembly language. I began to dream with BALR (Branch And Link Registers) instructions and macro expansions. Yes, I was a truly software geek.

After school, I went to Universidad de Buenos Aires, to learn more about computers and programming. I learnt about digital computers, Algol-W, BCPL, more IBM 3×0 assembly language but more about mathematics, algebra, calculus, and formal thinking. It was a great time, my mind was open. Since then, formal mathematics are with me, every year of my life. I love math more than software. But in those years, I decided to study computer science: that field was having a raise in acceptance in Argentina job market, and I needed the money… oopss…. what a coincidence…. I still need the money… ;-)

BCPL was interesing: it was a compiled language, running in IBM mainframe but in other machines too. Its compiler was written in BCPL itself: that idea was lighting to my mind. Self-defined language were (and are) great. I met BCPL after reading a reprint of an old Scientific American, about CPL, a more ambitious attempt that never grew up.

Fortran IV was another language used to learn programming at those days. I still remember Hollerith fields, and the lack of recursion. Mc Craken books were classic best sellers. I didn’t touch Watfor or alike:  only Fortran IV.

All these programs I wrote, ran on the university’s mainframe. I wrote the text of programs in paper, someone else punched the cards. I gave the cards to an administrator on wednesday, and THE NEXT week wednesday, I received the results. If I were committed a mistake, I should redo the work, and wait ANOTHER week to see the new results. I could read the punched cards only “reading” the holes. EBCDIC was a friend (ugly, the letters were not in consecutive places).

Ah! Another language: RPG II. What a language! Five kinds of sheets to fill, most of their fields specialized on cut control to produce reports. Well, RPG stands for Report Programming Generator. Only with RPG III it started to have true languages features, but again, I missed that version.

One day, I bought a recently arrived magazine, Dr. Dobb’s. What a revelation! This was my first encounter with C language: you can write in lower case (as in Algol and BCPL, a C predecessor), you can write anywhere (no comments at column 7).  It supported recursion, pointers, dynamic memory allocation, a true revelation to anyone proficient in COBOL. IBM machines had no notion of dynamic memory or a stack. DEC-like machines and processors were the “early adopters” of those ideas. There was a new set of characters, ASCII, with consecutive letters, wow!

But my first true love was Lisp: I worked with a minimal implementation written by Gregory Chaitin (he had visited my university some years before), where each verb was expressed with only one character. Variables had only one character wide name. It had some polish-like notation. Chaitin wrote his interpreter in Fortran, that in those times it lacked recursion. He used internal arrays to simulate recursion. I sat down, and write my own implementation in 8086 assembly language, hours debugging the stuff… Yes, I was brain damaged, I’m still fighting my illness…. ;-)

I began to access to personal computers. But before PCs, I worked with mini computers, Microdata ones, that ran Pick operating system. Pick OS was written for a virtual microcode, so it could be ported to any hardware that have an implementation of such “virtual machine”. It’s a shame that Dick Pick died in the 90s. His OS had interesting ideas: memory and disk were the same, without difference. You could have a sector/frame in memory or in disk. Your registers of your process were saved in sector N, and other process had its sectors saved in sector M, and so on. A file could start at sector N+3000, or in any other sector. Console verbs were codified in sectors. So, if command X were in sector 4320, you can rewrite that sector to implement a new version of the command. I don’t remember the exact details, but any command corresponded to the name of the file, and its first line had the sector number assigned to run the command. If you copied the file with another name, you had a command alias. Pick OS had a shell language, and an interesting implementation of basic, called Pick Basic. It was the first language that I had available to create recursive programs. So, I wrote my first Lisp interpreter, but with Pick Basic. It was a weird implementation: the language has no notion of pointers, so I implement lists in strings, CAR was a substring operation, it has no circular list. I was so young! ;-)

Interesting, Pick Systems had a variant of runoff, the first program I used that generates text manual, with font support. I printed that documentation on Printronix printers, that had hammers to plot points on the paper. Ouch.

With those printers, I could control the print to the pixel, so I could write a drawing program: it read a file with object descriptions, calculate the lines, and plot them as 2D/3D on Printronix. What a way of having fun… ;-)

There were lot of personal computer branches: Ohio Scientific, Cromemco, Ontel… I remember the Ontel: it used big removable disks, half meter wide. Some day, I brough one Ontel disk to a restaurant, and they denied me the entrance: they thought I had a bomb.

The file system in Ontel were weird: no FAT (File Allocation Table). Each sector has a pointer to the next sector in the file. I remember one day: my boss and me went to a customer office, on a weekend. We must work creating full days a demo for monday. Then, my boss made a mistake, editing the sectors: all file links were lost. We spent the morning manually relinking the most important files, with the only guidance of sector content. It was like resolving a more-than-thousand-pieces puzzle.

Ontel was programmed in OPL: Ontel Programming Language, a kind of assembly, only one instruction per line. But it has a decent screen editor: the first time I sat in front of an Ontel, I stayed 24 hours (truly) only playing with it (all night/day programming, and listening Queen, a new band from England): after punched card, and a full week cycle to compile/test, an screen editor and a command line compiler were a shock to me.

Ohio Scientific had a gorgeus memory: 64K (I guess my university mainframe had the same capacity). 32K dedicated to the basic interpreter. The other 32k was for my program. Every line had a number. You write the line 10, then the line 20. If you wanted to add more logic between, you must use the intermediate numbers. But contrary to Ontels, Ohios support multiple terminals.

Compiling in those machine made you multitasking: yes, when compiling, you could do other tasks: make coffee, go to bath, chat with young women in customer office… ;-) … Compiling could be a lengthly process in some machines.

More machines: I wrote COBOL programs in tape, for NCR small machines. I must split some programs in many pieces, because the compiler exhausted the memory. The screen and report section had their birth in those years.

The first real personal computer was an IBM. It had only one diskette driver. You must boot with one diskette, then retire it, and put another diskette, with edlin editor. GWBasic was the interpreter I used. But before DOS, I programmed with CP/M. Yes, Gary Kildall baby. Oh, my gosh. No directories. Only files. The programs were loaded in fixed memory. No relocation, or relative address. The first 128 bytes were reserved to pointers. The execution started at 100h. 8080 with 4 registers. Then, 8086 bring us AX, AL, AH…. SI, DI stands for source increment, and destination increment… You had to use such registers to copy memory blocks, ough! DS, CS pointed to data and code segments, so now I had relocation, and relative address. A great advance.

I vaguely remember some work with Multiuser CP/M. Yes, had a version then with multi user support. But it was late: DOS had begin to dominate the world.

No database support in DOS. Then, I wrote a full balanced-tree index, to use from GWBasic… yes, again, in assembly language. Now, I just realized I needed medication in those days… ;-) . Years later, we’ve got Btrieve, a liberation.

Ah! The Int 21h, a port to heaven in DOS days. To backward compatibility with CP/M programs, the instruction at 0h had a jump instruction to Int 21h. Exe loader fill the exact address to jump.

Did you remember Sidekick? I must rewrite config.sys, and add files=40 to have enough file handles to run Borland’s baby.

And command.com? It resided at upper memory. Whenever it was overwritten, the OS reloaded it. And BIOS? I worked for IBM Argentina, and I had access to one of the ten (yes, 10!) BIOS Reference Manual that were available in my country. It included full source listing, in assembly language. I still remember the clock interrupt, and reading the interrumpt to attend keystrokes.

I used to read Byte, TechJournal, Computer Language magazines, and my favourite, Dr.Dobb’s. I enjoyed reading about Small C and  Cain and Hendrix’ implementation. I was amused on some implementation, as Leo Zorman’s C compilers in CP/M and DOS. I remember the ads from Vrije University, offering a cross compiler (I guess it was Tanenbaum’s work) for u$s 9999.

Thanks to IBM machines, I had my first real encounter with Unix-like system: the venerable Xenix from Microsoft ran on IBM PCs. IBM had another offer: AIX-like on PCs, and a PSystem, Pascal based OS. But DOS took off to gain the market. I made a discovering at IBM local office: they were using a Global Network, to communicate all branches. You could ask something to another product group, for example, in Australia, via an electronic message, and got an answer the same day. It was my first experience with such kind of communication. Now, we have Internet.

I explored the Dialog system: one of my first works involved searching in documents. Dialog was an online system to search papers, books, via keywords. With a team, we wrote a similar system for a government agency of my country, Argentina. It could be considered a Google predecessor…. ;-)

I learnt Smalltalk, in my free hours; there was no Smalltalk classes in my university. But I only could learn about it, because the hight cost of any machine needed to run the graphics Smalltalk environment uses. The same was with Golden Common Lisp, and some expert systems: too much expensive to me (hardware and software), so I continued to write my own experiments.

I could continue writing commenting those eary years for days. But the point is: it was fun, and it was interesting. Software development is a fascinating topic. Lesson learnt: change is the only constant in this profession and art.

But more important that software and technology, I was lucky: these years, full of activities, gave me the opportunity to meet amazing people. People was the real gain of all these professional years. I want to thanks to everyone, friends, fellow developers, customers, that stand with me, in this long journey. This post is only a fragment of my early memories, only focused in technologies. But the important things were in other place: the people I met. Thanks to all!

Images from
Confessions of an Antediluvian Geek – A personal history of computing
WikiPedia Commons File-Punched_card.jpg
Old Computers Museum
My personal experience with technology, from the early years of computers in the 1970’s to today in 2008

More related links
Historic Documents in Computer Science
http://delicious.com/ajlopez/computerhistory

Angel “Java” Lopez
http://www.ajlopez.com/en
http://twitter.com/ajlopez

Older Posts »

Blog at WordPress.com.