Thursday, July 19, 2007
"Agile" Process Disentanglement
How deep in the jungle is the team, that we need a silver-magic-map to bring it back on the driving-road?
Wednesday, July 18, 2007
Functional idioms, Take Three
- My 1st suggestion would be to play by the rules, and pull the DoSomething(...) through the hierarchy up to A, where you need it.
- But what if you cannot do it ("it is not the way we do it in this project") ? What if, to make the matters worse, every element in the chain could be null (and not a NullObject) ? The chain would explode in a cascade of if-then-else-s to check every element for null, etc...
- Comega has something like int? = A.B.C.GetSomeIntValue(...)
- We (C#) could do:
created.PackungsgroessenEinheitText = Chain.On.Nullables<IArtikel, INormalArtikel, Packungsgroesse, string>(
artikel,
delegate(IArtikel x) { return x as INormalArtikel; },
delegate(INormalArtikel x) { return x.Packungsgroesse; },
delegate(Packungsgroesse x) { return string.Format("{0} {1}", x.Menge, x.Einheit); }
);
- we navigate throught the chain with delegates. The navigation is interrupted on the 1st null hit.
- If we watch the "chain" implementation:
public class Chain {
private Chain() {}
public static Chain On { get { return new Chain(); } }
public R Nullables(S input, Func
where S : class
where R : class {
if (input == null) {
return null;
}
return fun_1(input);
}
public R Nullables(S input, Func
where S : class
where R1 : class
where R : class {
return Nullables(Nullables(input, fun_1), fun_2);
}
public R Nullables(S input, Func
where S : class
where R1 : class
where R2 : class
where R : class {
return Nullables(Nullables(Nullables(input, fun_1), fun_2), fun_3);
}
}
- we see that this could be very nicely implemented with some C++ metaprogramming templates (see compile-time factorial).
- F# has function composition through pipelining, offering some optimizations for it
- Tail Call Optimization !?
Monday, July 09, 2007
Functional Idioms, Take Two
- Since the mini-project lives, I think we should create a sourceforge acount for it.
- I have extended the interface with IsEmpty, Count, ApplyOnce, ...
- I really like the fluent interface. SelectThenCollect is no longer necessary, we can do Select(...).Collect(...)
- if in the initial Enumerable we have m elements and we select n from them, SelectThenCollect is O(m). Select(...).Collect(...) will take O(m)+O(n). (in the current implementation).
- Open Question: the current implementation does eager-evaluation: the select is computed when the method is called. Do we need a lazy-implementation? It could look like a query definition, and the code will be more declarative:
- IEnumerating
query = Enumerating.On(several_things).Select(IsEven).Collect(ItsColor); - IEnumerable
result_items = query.Eval(); - The solution might cache, the specified delegates, for a later (lazy), usage. This might lead to some unwanted side-effects: the garbage collector will not release the objects referenced in the delegates in the query definition, until ... (the query is released).
- Through laziness we could work on very large (infinite) data streams.
Tuesday, July 03, 2007
Sudoku Solver: TDD or not
It is a nice problem to chew on, for me, as Unit-Test/TDD agilist: I think that a TDD approach does not lead to discover constraint satisfaction algorithms, it should lead to a clean, testable, SRP driven architecture. If I remember well, the XP books say that you should start with a "metaphor", a design starting point.
disclaimer: this an echo post, i just wanted to link to AIMA.