Contents

197 Articles
12 Comments

Search

10 years Ago

Building pseudo-DSLs with C# 3.5

Published by marco on

DSL is a buzzword that’s been around for a while and it stands for [D]omain-[Specific] [L]anguage. That is, some tasks or “domains” are better described with their own language rather than using the same language for everything. This gives a name to what is actually already a standard practice: every time a program assumes a particular format for an input string (e.g. CSV or configuration files), it is using a DSL. On the surface, it’s extremely logical to use a syntax and semantics most... [More]

Designing a small API: Bit manipulation in C#

Published by marco on

A usable API doesn’t usually spring forth in its entirety on the first try. A good, usable API generally arises iteratively, improving over time. Naturally, when using words like good and usable, I’m obliged to define what exactly I mean by that. Here are the guidelines I use when designing an API, in decreasing order of importance:

Static typing & Compile-time Errors
Wherever possible, make the compiler stop the user from doing something incorrectly instead of letting the runtime handle it.... [More]

Waiting for C# 4.0: A casting problem in C# 3.5

Published by marco on

C# 3.5 has a limitation where generic classes don’t necessarily conform to each other in the way that one would expect. This problem manifests itself classically in the following way:

class A { }
class B : A { }
class C : A { }

class Program
{
  void ProcessListOfA(IList<A> list) { }
  void ProcessListOfB(IList<B> list) { }
  void ProcessSequenceOfA(IEnumerable<A> sequence) { }
  void ProcessSequenceOfB(IEnumerable<B> sequence) { }

  void Main()
  {
    var bList = new List<B>();
    var... [More]

Creating fluent interfaces with inheritance in C#

Published by marco on

Fluent interfaces—or “method chaining” as it’s also called—provide an elegant API for configuring objects. For example, the Quino query API provides methods to restrict (Where or WhereEquals), order (OrderBy), join (Join) and project (Select) data. The first version of this API was very traditional and applications typically contained code like the following:

var query = new Query(Person.Metadata);
query.WhereEquals(Person.Fields.Name, "Müller");
query.WhereEquals(Person.Fields.FirstName,... [More]

Supporting Data-entry in Database Applications

Published by marco on

The following is an analysis and brainstorming of a problem in generalized database browser GUIs, like those generated by the Quino metadata framework.


The User Story

Let’s start with the user story that generated this idea:

“A user was entering data using our database software and complained of losing data. After verifying that the lost data was not due to an obvious software bug, we determined that it was because of how she was assuming the software worked. That is, she would use the... [More]”

Microsoft Code Contracts: Not with a Ten-foot Pole

Published by marco on

After what seems like an eternity, a mainstream programming language will finally dip its toe in the Design-by-contract (DBC) pool. DBC is a domain amply covered in one less well-known language called Eiffel (see ISE Eiffel Goes Open-Source for a good overview), where preconditions, postconditions and invariants of various stripes have been available for over twenty years.

Why Contracts?

Object-oriented languages already include contracts; “classic” signature-checking involves verification of... [More]

Remote Debugging with [ASP].NET

Published by marco on

When a .NET application exhibits behavior on a remote server that cannot be reproduced locally, you’ll need to debug application directly on the server. The following article includes specific instructions for debugging ASP.NET applications, but applies just as well to standalone executables.

Prerequisites

There are several prerequisites for remote debugging; don’t even bother trying until you have all of the items on the following list squared away or the Remote Debugger will just chortle at... [More]

The Dark Side of Entity Framework: Mapping Enumerated Associations

Published by marco on

This article was originally published on the Encodo Blogs. Browse on over to see more!


At Encodo, we’re using the Microsoft Entity Framework (EF) to map objects to the database. EF treats everything—and I mean everything—as an object; the foreign key fields by which objects are related aren’t even exposed in the generated code. But I’m getting ahead of myself a bit. We wanted to figure out the most elegant way of mapping what we are going to call enumerated associations in EF. These are... [More]

Eject/Change a CD from Windows inside a XEN-VM using VNC

Published by marco on

This article was originally published on the Encodo Blogs. Browse on over to see more!


At Encodo, we currently run Debian Etch on our servers, with a Xen hypervisor managing a bunch of individual virtual machines (VMs). Most of the VMs also run Debian Etch, but one of them runs Windows Server 2003 instead. We use this machine for testing integration with Microsoft technologies like Sharepoint, Exchange and so on. Recently, we had to re-install the Exchange instance on that server and were... [More]

Elegant Code vs.(?) Clean Code

Published by marco on

This article was originally published on the Encodo Blogs. Browse on over to see more!


A developer on the Microsoft C# compiler team recently made a post asking readers to post their solutions to a programming exercise in Comma Quibbling by Eric Lippert (Fabulous Adventures in Coding). The requirements are as follows:

  1. If the sequence is empty then the resulting string is “{}”.
  2. If the sequence is a single item “ABC” then the resulting string is “{ABC}”.
  3. If the sequence is the two item sequence “ABC”, “DEF” then the resulting string is... [More]

Cleaning up Old Code

Published by marco on

Once you’ve been coding for a while, you’ll probably have quite a pile of code that you’ve written and are regularly using. It’s possible that you’ve got some older code in use that just works and on which you rely every day. At some point, though, you realize that you have to get back in there and fix a few things. That happened recently with the upgrade of the earthli WebCore and attendant applications from PHP4 to PHP5 (which is ongoing). The earthli codebase was born in 1999 and was... [More]

Customizing Facebook Previews from your Website

Published by marco on

When someone posts a link to your web site on Facebook, it retrieves a preview and presents that as the default text, along with a selection of pictures it found in the page. Clearly, Facebook has some sort of scraper that extracts what it thinks is the best preview text from a given URL. Sometimes it works well, sometimes not. Luckily, you can tune your pages for Facebook requests, emphasizing the parts you think are important and belong in the preview.

It’s anybody’s guess how the scraper... [More]

Debugging PHP

Published by marco on

PHP is a programming language like any other; like any other, it’s possible to construct a bug complex enough that it can only reasonably be solved with a debugger. Granted, most PHP code is quite simple and limited to single pages with single include files and a limited library or framework. However, the advent of PHP5 has ushered in more than one team with the courage to build a full-fledged web framework. You would think that the state of PHP development had concordantly improved to the... [More]

Entity Framework: Be Prepared

Published by marco on

This article was originally published on the Encodo Blogs. Browse on over to see more!


In August of 2008, Microsoft released the first service pack (SP1) for Visual Studio 2008. It included the first version (1.0) of Microsoft’s generalized ORM, the Entity Framework. We at Encodo were quite interested as we’ve had a lot of experience with ORMs, having worked on several of them over the years. The first was a framework written in Delphi Pascal that included a sophisticated ORM with support... [More]

11 years Ago

Mercurial, Python & Debian

Published by marco on

After nearly a decade of using Perforce for my private source control, I’d decided to switch to Mercurial. Mercurial is a distributed version control system and open-source and all kinds of awesome and I won’t go into why I made the switch here. Suffice it to say it makes it much easier to release code and work with others.

Mercurial itself is an easy installation and I had it running both on my OS X 10.4 and Windows XP in a flash. I even installed the newly released HgTortoise plugin, which... [More]

Using an OpenSSL certificate for Courier IMAP

Published by marco on

Courier IMAP has a default certificate for SLL communication, but it’s only valid for a year and has bogus, default information in it. You can use a utility to generate a new certificate and, with a little perseverance, find the configuration file from which it draws its parameters. With these parameters, you can make a slightly better certificate, but it’s better to use OpenSSL to generate a proper certificate, based either on a trusted certificate or self-signed. However, OpenSSL’s default... [More]

Sorting Algorithms Head-to-head

Published by marco on

 If you’re faced with a pile of data that needs to be sorted, you can use the Animated Sorting Algorithms by David R. Martin to decide, based on what kind of data you think you’re going to have. Click a little green refresh symbol in the rows to watch the algorithms race on the same dataset or click a column header to watch the same algorithm attack best- and worst-case scenarios simultaneously.

 

PHP Gets Closures / Lambda Functions

Published by marco on

The recently-published RFC: Lambda functions and closures by Christian Seiler & Dmitry Stogov (PHP) has all the details about a patch for PHP that adds support for closures to PHP 5.3 and higher. It looks like the proposal was initially made in December of 2007 and the process lasted about half a year. Compare and constrast with Java’s long struggle to get closures, which isn’t over by half[1].

The syntax is pretty straightforward, though not as elegant as the lambda syntax adopted by C# (and likely others of whose syntax I’m not aware,... [More]

Metadata in Software Development

Published by marco on

This article was originally published on the Encodo Blogs. Browse on over to see more!


 Download

This paper sketches a brief background of metadata, lists the advantages and drawbacks to existing approaches and provides some examples on where metadata can be useful. It describes Encodo’s approach to metadata with a brief overview of the basic elements and ideas on how to avoid the limitations of existing solutions.

What is Metadata?

Metadata is, by definition, data about an application’s... [More]

Encodo C# Handbook

Published by marco on

This article was originally published on the Encodo Blogs. Browse on over to see more!

 Download

The first publicly available version of the Encodo C# Handbook is ready for download! It covers many aspects of programming with C#, from naming, structural and formatting conventions to best practices for using existing and developing new code.

Here’s the backstory on how and why we decided to write a formal coding handbook.

Here at Encodo, we started working with C# less than a year ago. We... [More]

12 years Ago

Office Formats

Published by marco on

Microsoft recently released documentation for their binary office formats in both PDF and their own XPS format. The PDF for Word weighs in at 2.8MB and has 210 pages. Why are the Microsoft Office file formats so complicated? by Joel Spolsky, provides a lot of good reasons for why the formats are so complicated (most rooted in history), like speed, complexity of the task, purely internal formats (until now), etc.

Where Spolsky veers off the path (and he almost always does) is in reaching a bit too far with his... [More]

Improving Online Chatting

Published by marco on

The article Two-Party Threaded Chat by Peter Arrenbrecht addresses the problem of multiple threads of discussion within a single conversation. Without face-to-face contact, the threshold for interruption is much lower and answers will not always neatly line up under their questions. A conversation may have many of these “threads”, though individual ones are usually quite short-lived. Chat clients are currently limited by their purely serial approach to inserting text into a conversation.

The solution proposed in... [More]

Generics and Delegates in C#

Published by marco on

This article was originally published on the Encodo Blogs. Browse on over to see more!


The term DRY—Don’t Repeat Yourself—has become more and more popular lately as a design principle. This is nothing new and is the main principle underlying object-oriented programming. As OO programmers, we’ve gotten used to using inheritance and polymorphism to encapsulate concepts. Until recently, languages like C# and Java have had only very limited support for re-using functionality across larger... [More]

The All-Downside Architecture

Published by marco on

If you’ve ever thought that PHP was too fast or used too little memory or that Java’s class encapsulation was too restricitive, boy has Quercus: PHP in Java got the solution for you. At last, PHP developers can enjoy the benefits of enterprise computing complete with abominable startup times, appalling refresh speeds and PermGen errors every 15 minutes. And Java developers can finally leave their half-assed web frameworks behind and get behind the ultra-organized global namespace with a little... [More]

13 years Ago

When Tapestry’s @Inject* Silently Fails

Published by marco on

This article was originally published on the Encodo Blogs. Browse on over to see more!


Most Tapestry programming involves writing event handlers and operations on page objects. In order to execute these operations, you need access to properties of the form and properties of the session and application in which the page resides. For convenience, developers can add references to all sorts of objects in the system using various forms of the @Inject* annotation (like @InjectPage, @InjectObject... [More]

Versioned Objects with Hibernate

Published by marco on

This article was originally published on the Encodo Blogs. Browse on over to see more!


Hibernate is a persistence framework for Java. Among the many perks it purports to bring to the table is automatic versioning for objects in the database. That is, when saving an object to the database, it increments a version number. Any process that attempts to store a different version of the same object is rejected. This is all extremely flexible and can be added to a POJO using an annotation:

 ... [More]

Override an Implementation in HiveMind

Published by marco on

This article was originally published on the Encodo Blogs. Browse on over to see more!


If you are not already familier with HiveMind, read Setting up a Service in HiveMind for an introduction.[1]

In the article mentioned above, we learned how to set up a new HiveMind service. What if we want to replace the implementation for an existing service? Is it even possible? Why would you want to do that? This article answers these questions in the context of a real-life example from one of our... [More]

Session and Requests in HiveMind

Published by marco on

This article was originally published on the Encodo Blogs. Browse on over to see more!


If you are not already familier with HiveMind, read Setting up a Service in HiveMind for an introduction.[1]

Almost every application is going to need to have information that is session-specific. This is accomplished by adding a member to Tapestry’s application objects list and assigning it the proper scope. With a scope of “session”, HiveMind makes sure that each session in the web application has its own... [More]

Setting up a Service in HiveMind

Published by marco on

This article was originally published on the Encodo Blogs. Browse on over to see more!


HiveMind is the IOC manager used together with Tapestry; it’s in charge of bootstrapping and connecting all of the myriad objects and services available to a Tapestry application. Applications based on Tapestry are encouraged to use it to configure their application- and session-level objects and services as well.

Once it works, it works well. Getting it configured in the first place—especially when new... [More]

Missing ognl?

Published by marco on

This article was originally published on the Encodo Blogs. Browse on over to see more!


Every once in a while, when adding a new component to or changing an existing one on a Tapestry page, you’ll make a mistake. Most of the time, the exception handler page is pretty good; sometimes the exception can be quite confusing. For example, suppose we have a custom component with a single property:

package com.encodo.blogs.samples;

class CustomComponent extends BaseComponent {
  public abstract... [More]