How to create a fluent query interface?

How to implement composable queries: the 10k feet view It’s not difficult to realize that in order to achieve this the methods being chained must incrementally set up some data structure which is finally being interpreted by some method that executes the final query. But there are some degrees of freedom regarding exactly how this … Read more

Designing a fluent Javascript interface to abstract away the asynchronous nature of AJAX

Give a look to the following article published just a couple of days ago by Dustin Diaz, Twitter Engineer on @anywhere: Asynchronous method queue chaining in JavaScript He talks about a really nice technique that allows you to implement a fluent interface on asynchronous methods, basically methods chained together independent of a callback, using a … Read more

How to subclass str in Python

Overwriting __new__() works if you want to modify the string on construction: class caps(str): def __new__(cls, content): return str.__new__(cls, content.upper()) But if you just want to add new methods, you don’t even have to touch the constructor: class text(str): def duplicate(self): return text(self + self) Note that the inherited methods, like for example upper() will … Read more

Fluent interfaces and inheritance in C#

Try to use some Extension methods. static class FluentManager { public static T WithFirstName<T>(this T person, string firstName) where T : FluentPerson { person.FirstName = firstName; return person; } public static T WithId<T>(this T customer, long id) where T : FluentCustomer { customer.ID = id; return customer; } } class FluentPerson { public string FirstName … Read more

How do I map a char property using the Entity Framework 4.1 “code only” fluent API?

Char is not valid primitive type for entity framework = entity framework doesn’t map it. If you check CSDL reference you will see list of valid types (char is not among them). Database char(1) is translated as string (SQL to CSDL translation). Char is described as non-unicode string with fixed length 1. The only ugly … Read more

Can you monkey patch methods on core types in Python?

No, you cannot. In Python, all data (classes, methods, functions, etc) defined in C extension modules (including builtins) are immutable. This is because C modules are shared between multiple interpreters in the same process, so monkeypatching them would also affect unrelated interpreters in the same process. (Multiple interpreters in the same process are possible through … Read more