214 Articles


6 years Ago

Should you return null or an empty list?

Published by marco on

I’ve seen a bunch of articles addressing this topic of late, so I’ve decided to weigh in.

The reason we frown on returning null from a method that returns a list or sequence is that we want to be able to freely use these sequences or lists with in a functional manner.

It seems to me that the proponents of “no nulls” are generally those who have a functional language at their disposal and the antagonists do not. In functional languages, we almost always return sequences instead of lists or... [More]

Optimizing data access for high-latency networks: part IV

Published by marco on

 In the previous two articles, we managed to reduce the number of queries executed when opening the calendar of Encodo’s time-tracking product Punchclock from one very slow query per person to a single very fast query.

Because we’re talking about latency in these articles, we’d also like to clear away a few other queries that aren’t related to time entries but are still wasting time.

Lazy-loading unneeded values

In particular, the queries that “Load values” for person objects look quite... [More]

Optimizing data access for high-latency networks: part III

Published by marco on

 In the previous article, we partially addressed a performance problem in the calendar of Encodo’s time-tracking product, Punchclock. While we managed to drastically reduce the amount of time taken by each query (>95% time saved), we were still executing more queries than strictly necessary.

The query that we’re trying to optimized further is shown below.

var people =
  Where(p => Session.GetCount(p.TimeEntries.Query) > 0).

This query executes one... [More]

Optimizing data access for high-latency networks II

Published by marco on

 In the previous article, we discussed a performance problem in the calendar of Encodo’s time-tracking product, Punchclock.

Instead of guessing at the problem, we profiled the application using the database-statistics window available to all Quino applications.[1] We quickly discovered that most of the slowdown stems from the relatively innocuous line of code shown below.

var people = 
  Where(p => p.TimeEntries.Any()).

First things first: what does... [More]

Optimizing data access for high-latency networks: part I

Published by marco on

 Punchclock is Encodo’s time-tracking and invoicing tool. It includes a calendar to show time entries (shown to the left). Since the very first versions, it hasn’t opened very quickly. It was fast enough for most users, but those who worked with Punchclock over the WAN through our VPN have reported that it often takes many seconds to open the calendar. So we have a very useful tool that is not often used because of how slowly it opens.

That the calendar opens slowly in a local network and even... [More]

Questions to consider when designing APIs: Part II

Published by marco on

In the previous article, we listed a lot of questions that you should continuously ask yourself when you’re writing code. Even when you think you’re not designing anything, you’re actually making decisions that will affect either other team members or future versions of you.

In particular, we’d like to think about how we can reconcile a development process that involves asking so many questions and taking so many facets into consideration with YAGNI.

Designing != Implementing

The implication... [More]

Questions to consider when designing APIs: Part I

Published by marco on

A big part of an agile programmer’s job is API design. In an agile project, the architecture is defined from on high only in broad strokes, leaving the fine details of component design up to the implementer. Even in projects that are specified in much more detail, implementers will still find themselves in situations where they have to design something.

This means that programmers in an agile team have to be capable of weighing the pros and cons of various approaches in order to avoid causing... [More]

Dealing with improper disposal in WCF clients

Published by marco on

There’s an old problem in generated WCF clients in which the Dispose() method calls Close() on the client irrespective of whether there was a fault. If there was a fault, then the method should call Abort() instead. Failure to do so causes another exception, which masks the original exception. Client code will see the subsequent fault rather than the original one. A developer running the code in debug mode will have be misled as to what really happened.

You can see WCF Clients and the “Broken”... [More] by David Barrett

REST API Status codes (400 vs. 500)

Published by marco on

In a project that we’re working on, we’re consuming REST APIs delivered by services built by another team working for the same customer. We had a discussion about what were appropriate error codes to return for various situations. The discussion boiled down to: should a service return a 500 error code or a 400 error code when a request cannot be processed?

I took a quick look at the documentation for a couple of the larger REST API providers and they are using the 500 code only for... [More]

Mixing your own SQL into Quino queries: part 2 of 2

Published by marco on

In the first installment, we covered the basics of mixing custom SQL with ORM-generated queries. We also took a look at a solution that uses direct ADO database access to perform arbitrarily complex queries.

In this installment, we will see more elegant techniques that make use of the CustomCommandText property of Quino queries. We’ll approach the desired solution in steps, proceeding from attempt #1 – attempt #5.

tl;dr: Skip to attempt #5 to see the final result without learning why it’s... [More]

Mixing your own SQL into Quino queries: part 1 of 2

Published by marco on

The Quino ORM[1] manages all CrUD—Create, Update, Delete—operations for your application. This basic behavior is generally more than enough for standard user interfaces. When a user works with a single object in a window and saves it, there really isn’t that much to optimize.

Modeled methods

A more complex editing process may include several objects at once and perhaps trigger events that create additional auditing objects. Even in these cases, there are still only a handful of save... [More]

Java 8

Published by marco on

 This article discusses and compares the initial version of Java 8 and C# 4.5.1. I have not used Java 8 and I have not tested that any of the examples—Java or C#—even compile, but they should be pretty close to valid.

Java 8 has finally been released and—drum roll, please—it has closures/lambdas, as promised! I would be greeting this as champagne-cork–popping news if I were still a Java programmer.[1] As an ex-Java developer, I greet this news more with an ambivalent shrug than with any... [More]

Quino: efficiency, hinting and local sorting

Published by marco on

In Quino: partially-mapped queries we took a look at how Quino seamlessly maps as much as possible to the database, while handling unmappable query components locally as efficiently as possible.

Correctness is more important than efficiency

As efficiently as possible can be a bit of a weasel statement. We saw that partial application of restrictions could significantly reduce the data returned. And we saw that efficient handling of that returned data could minimize the impact on both... [More]

Quino: partially-mapped queries

Published by marco on

In Quino: an overview of query-mapping in the data driver we took a look at some of the basics of querying data with Quino while maintaining acceptable performance and memory usage.

Now we’ll take a look at what happens with partially-mapped queries. Before explaining what those are, we need a more concrete example to work with. Here’s the most-optimized query we ended up with in the previous article:

var query = Session.GetQuery<Person>();... [More]

7 years Ago

LESS vs. SASS: Variable semantics

Published by marco on

I’ve been using CSS since pretty much its inception. It’s powerful but quite low-level and lacks support for DRY. So, I switched to generating CSS with LESS a while back. This has gone quite well and I’ve been pretty happy with it.

Recently, I was converting some older, theme stylesheets for earthli. A theme stylesheet provides no structural CSS, mostly setting text, background and border colors to let users choose the basic color set. This is a perfect candidate for LESS.

So I constructed a... [More]

Rolling your own languages and frameworks

Published by marco on

The blog post/article So You Want To Write Your Own Language? by Walter Bright (Dr. Dobbs) contains a lot of interesting information, related to only to parsing, but also to runtime and framework design. Bright is well-known as the designer of the D programming language, so he’s definitely worth a read.

I thought he jumped back and forth between topics a bit, so I summarized the contents for myself below:


Bright identifies Minimizing keystrokes, easy parsing and minimizing the number of keywords as false gods.... [More]

Quino: an introduction to query-mapping in the ORM

Published by marco on

The following article was originally published on the Encodo blogs and is cross-published here.

One of the most-used components of Quino is the ORM. An ORM is an Object-Relational Mapper, which accepts queries and returns data.

  • Applications formulate queries in Quino using application metadata
  • The ORM maps this query to the query language of the target database
  • The ORM transforms the results returned by the database to objects (the classes for which were also generated from application... [More]

Generating JSON from Dart object graphs

Published by marco on

 A while back, I participated in an evaluation of languages that could replace JavaScript for our web front-end development language at Encodo. We took a look at two contenders: Dart and TypeScript. At the time, Dart was weaker for the following reasons:

  • It had not yet been released
  • It had little to no tool support
  • Integration with existing JS libraries was somewhat laborious

Though TypeScript has its weaknesses (it has technically not yet hit a 1.0 release), we eventually decided to go in... [More]

The Ruby language: where you can randomize your base class

Published by marco on

 I have never really examined Ruby in detail but it seems to be even more of a treasure-trove of ad-hoc features than PHP.

It takes full advantage of being evaluated at run-time to offer features that I haven’t seen in even other dynamic languages. Some of these features seem like they might be nice shortcuts but also seem like they would be difficult to optimize. Not only that, but they seem so obscure that they would likely will trip up even more seasoned users of the language.

At any rate,... [More]

Apple Developer Videos

Published by marco on

It’s well-known that Apple runs a walled garden. Apple makes its developers pay a yearly fee to get access to that garden. In fairness, though, they do provide some seriously nice-looking APIs for their iOS and OS X platforms. They’ve been doing this for years, as listed in the post iOS 7 only is the only sane thing to do by Tal Bereznitskey. It argues that the new stuff in iOS 7 is compelling enough to make developers consider dropping support for all older operating systems. And this for pragmatic reasons, such... [More]

Brilliant articles by the funniest guy at Microsoft

Published by marco on

I recently stumbled upon some Essays from the funniest man in Microsoft Research by Raymond (Old New Thing). He is such a funny writer that this article, against convention, will consist mostly of citations rather than an even mix of citations and paraphrasing that I naturally consider to be much more lucid and pithy. I quote at length to do the material justice, for documentation and to ensure that you all download the PDFs to see if there is more where that came from (there is). All emphases have been added.

Mobile... [More] by James Mickens (Microsoft Research)

How to fool people into giving up their email address

Published by marco on

On Codecademy, you can learn to program in various languages. It starts off very slowly and is targeted at non-technical users. That’s their claim anyway—the material in the courses I looked at ramps up pretty quickly.

Anyway, the interesting thing I saw was in their introductory test. It struck me as a subtle way to get you to enter your email address. I’d just recently discussed this on a project I’m working on: how can we make it fun for the user to enter personal information? The goal is... [More]

The HTML5 AppCache and HTTP Authentication

Published by marco on

The following article was originally published on the Encodo blogs and is cross-published here.

The following article outlines a solution to what may end up being a temporary problem. The conditions are very specific: no server-side logic; HTTP authentication; AppCache as it is implemented by the target platforms—Safari Mobile and Google Chrome—in late 2012/early 2013. The solution is not perfect but it’s workable. We’re sharing it here in the hope that it can help someone else or serve... [More]

Entity Framework Generated SQL

Published by marco on

Microsoft just recently released Visual Studio 2013, which includes Entity Framework 6 and introduces a lot of new features. It reminded me of the following query that EF generated for me, way, way back when it was still version 3.5. Here’s hoping that they’ve taken care of this problem since then.

So, the other day EF (v3.5) seemed to be taking quite a while to execute a query on SQL Server. This was a pretty central query and involved a few joins and restrictions, but wasn’t anything too... [More]

Ignoring files with Git

Published by marco on

The helpful page, Ignoring files (GitHub), taught me something I didn’t know: there’s a file you can use to ignore files in your local Git repository without changing anyone else’s repository.

Just to recap, here are the ways to ignore a file:

  • Global .gitignore: you can designate basic exclusion directives that apply to all repositories on your system. This file is not committed to any repository or shared with others. Execute git config –global core.excludesfile ~/.gitignore_global to set the file... [More]

Some new CSS length units (and some lesser-known ones)

Published by marco on

I’ve been using CSS since its inception and use many parts of the CSS3 specification for both personal work and work I do for Encodo. Recently, I read about some length units I’d never heard of in the article CSS viewport units: vw, vh, vmin and vmax by Chris Mills (Dev.Opera).

  • 1vw: 1% of viewport width
  • 1vh: 1% of viewport height
  • 1vmin: 1vw or 1vh, whatever is smallest
  • 1vmax: 1vw or 1vh, whatever is largest

These should be eminently useful for responsive designs. While there is wide support for these new units, that... [More]

.NET 4.5.1 and Visual Studio 2013 previews are available

Published by marco on

The following article was originally published on the Encodo blogs and is cross-published here.

The article Announcing the .NET Framework 4.5.1 Preview provides an incredible amount of detail about a relatively exciting list of improvements for .NET developers.

x64 Edit & Continue

First and foremost, the Edit-and-Continue feature is now available for x64 builds as well as x86 builds. Whereas an appropriate cynical reaction is that “it’s about damn time they got that done”, another... [More]

Deleting multiple objects in Entity Framework

Published by marco on

The following article was originally published on the Encodo blogs and is cross-published here.

Many improvements have been made to Microsoft’s Entity Framework (EF) since I last used it in production code. In fact, we’d last used it waaaaaay back in 2008 and 2009 when EF had just been released. Instead of EF, I’ve been using the Quino ORM whenever I can.

However, I’ve recently started working on a project where EF5 is used (EF6 is in the late stages of release, but is no longer generally... [More]

Merge conflicts in source control

Published by marco on

I was recently asked a question about merge conflicts in source-control systems.

“[…] there keep being issues of files being over written, changes backed out etc. from people coding in the same file from different teams.”

My response was as follows:

tl;dr: The way to prevent this is to keep people who have no idea what they’re doing from merging files.

Extended version

Let’s talk about bad merges happening accidentally. Any source-control worth its salt will support at least some form of... [More]

8 years Ago

A provably safe parallel language extension for C#

Published by marco on

The paper Uniqueness and Reference Immutability for Safe Parallelism by Colin S. Gordon, Matthew J. Parkinson, Jared Parsons, Aleks Bromfield, Joe Duffy (Microsoft Research) is quite long (26 pages), detailed and involved. To be frank, most of the notation was foreign to me—to say nothing of making heads or tails of most of the proofs and lemmas—but I found the higher-level discussions and conclusions quite interesting.

The abstract is concise and describes the project very well:

“A key challenge for concurrent programming is that side-effects (memory operations) in one thread can affect the... [More]”