N3R – Not Realy an RSS Reader

Last summer Google canceled its Google Reader service and thoroughly shaken the RSS ecosystem (in lack of a better term). Some people switched to other services and those who could live without RSS probably just stopped using the RSS completely. I was using RSS reader daily (or sometimes hourly) and I tried to switch but I couldn’t; no other service offered me user experience I wanted from RSS reader. And that was because I didn’t use RSS as intended.

So, how do I use RSS then?

First, I don’t actually use a “reader” part. Sites I’m visiting from RSS reader are mostly blogs or web comics. If I only read an article from an RSS reader, I’m missing on comments which can be as important as the main article. I also want to support the site I’m regularly reading by visiting it and seeing ads or clicking on them.

Then why I use RSS at all?

I actually use it not for reading but as a reminder, a notification that there is a new blog article or web comic. I can’t (don’t want to) visit all sites every now and then to see if there is anything new, but that’s why I have computers. So, my ideal reader will show me that there are new articles, clicking on them will open the original site in a new tab/window and will mark the clicked item as read. That’s all. Google reader had iGoogle gadget that allowed me to do just that. It wasn’t perfect, sometimes it behaved strangely, but it worked.

What’s the solution?

When Google announced that it will shut down iGoogle and Google Reader, alternatives just didn’t exist. I made an account on most of alternative services but neither had the features I need or can be used as I want. I just couldn’t find anybody who shared my view on RSS so I couldn’t hope that somebody will put user interface just the way I like it. (I just found out that I’m not the only one who is using RSS “wrong” (thread on HN). I was busy back then and I didn’t took time to create my own reader but when Google finally shut down those services, I exported the OPML file and created a quick and dirty reader in PHP for my own use. And now it’s six month as I’m using my own service and I couldn’t be happier with it (and nobody ever added any unnecessary features). It works just like I wanted. It’s not really an RSS reader so I acronymed it to NRRR and even shorter to N3R.

About the service

Service runs in the background and downloads data from feeds few times a day, depending on frequency of updates from a feed. I can import my list of feeds from OPML or add one manually by copying a feed link. In the reader page I see list of all unread items, oldest first. If I click on an item it takes me to the original page and mark the item as read. I can also mark the item read without visiting the page. When I refresh the page, I see only unread items.

screen-feeds screen-list

I had to make it in hurry so I didn’t want to spend time on login/registration part. I have a special link that logs me in and I can make one for every user. As long the link is private, so it’s the data.

You want to use it?

If you too, dear reader, didn’t find any alternative service or you want simple service like n3r, request your account on invitation page and I’ll send you your login link. My server can handle few more feeds.


HgChecker

When I used Subversion as the SCS, I had all my projects in one repository, and every commit went to the central server. I looked at root folder and I knew commit status of all projects.

Now I use Mercurial and I have multiple unrelated or loosely related projects and every project is a separate repository. My dev folder is structured like this:

  • /dev
    • /Apps
      • /App1
      • /App2
    • /Reporting
      • /ReportingApp1
      • /ReportingApp2
    • /Scripts
      • /Importer1
      • /Exporter2
    • /TestArea
      • /TestProject1
      • /Test2
    • /Utils
      • /Util1
      • /Util2

So, after a frantic week where I made fixes to old code, changed some scripts, worked at current development project and tested some new techiques in test projects, I asked myself:

  1. Have I commited every change in every project?
  2. Have I pushed every change to remote server?
  3. Is there any change in remote repository I can pull?

TortoiseHg icons give me some clues but they often can be wrong. I have to remember what I changed or check every project one by one. I’m not good at remembering things and I hate repetitive work that computer could do for me so i just had to write another utility to keep track of my projects.

Here’s how it works:

  • Configuration is done in config.ini
  • HGChecker will traverse folder hierarchy beginning from [ProjectRootDir]
  • It will check if any subfolder is project folder using patterns defined in [FindProjectRootFilePattern] or [FindProjectRootDirPattern]
  • It will run hg.ex defined in [HgExecutable] with status, incoming and outgoing parameters.
  • It will translate responses from hg and show the results in console, coded as following:
    • ? (cyan) – project is not source controlled
    • M (blue) – uncommitted changes
    • ↑↓ (red) – no valid default remote repository
    • ↑[#] (yelow) – there are # outgoing changes to push
    • ↓[#] (yelow) – # incoming changes available from remote repository

So, I have a scheduled a task that runs HGChecker every day at the end of the workday. Usually I strive to commit when I’m done, push when it’s ready and add every project to source control. But I’m not perfect and I easily forget. HGChecker is there now to remind me.

hgchecker-console

When this screen shows up, I immediatelly know the following:

  • I have some uncommited changes in App1 and there are two remote changes I must pull – there is merge on the way
  • It seems I created ReportingApp2 project but I didn’t add it to source control
  • I have commited one change to Importer1 but I didn’t push it to remote.
  • Importer 2 is source controled but it doesn’t have default remote repository

 


NDepend: First impressions

I recently got NDepend to use it as a measurement instrument for a research paper on software engineering I’m doing at the university. Folks at NDepend were kind enough to grant me a free license (thanks) so I’m recording my experience with it.

NDepend looks very complex and it seems it wants to show you all it got. It really has impressive number of features and developers probably have great troubles to show them all without dumbing down the user interface. Going feature by feature won’t get me anywhere so I’ll rather explore how NDepend handle the most interesting features for me: code metrics and code duplication detection.

To test it, I have one MVC project I’ve finished just a few months ago as a side job. It is small CMS application for tourist agency, hastily done which left it with much room for improvement. Let’s see what NDepend says about the project and comment on that.

Code quality

ndepend-query-rulesRules are in form of LINQ queries

Quick summary of methods to refactor

NDepend quickly found the worst methods of the project, fortunately only six of them. Just looking at their names I can see they are trying to do too much: ProcessRequest(HttpContext), LoadHomePageView(), Details() and LoadEditView() are really vague names. What exactly I’m guilty of? Lines of Code are on limit, around 30 which is not too bad (we are talking about 6 worst methods). I try to keep my methods visible on one screen and that is the result. Number of instructions and cyclomatic complexity are similarly low and no method passed the warning threshold. Another metric I keep low when programming is IL Nesting Depth and it shows (no medal from NDepend, just a green dot). I avoid arrow shaped code and use the “get the heck out” tactic. What is wrong with those methods is the number of variables, more then 10 in each method with max of 15. They do too many different things: loading data, parsing, transforming and returning. Each of this segments could be extracted as a new method with descriptive name and the method in question would be much clearer.

Methods potentially poorly commented

Ah, the code comments. I heard everything: from “Comments are worth more the code” to “Comments are dangerous liability”. I got into the “comments-are-bad” camp. If your code needs explaining, you’re probably doing something wrong. For example, you can comment a block of 10 lines of code and explain what they do. But you could also extract that code in the separate method and name it so it’s understandable and no comment is needed. You can explain a clever one-liner with 10 lines of comments but I would rather have 5 lines of code I understand without comments. So, naturally I was happy that NDepend mostly agrees with me and warns only about long methods without enough comments. It found 9 such methods in my code, some even without comments at all. Adding comments would be a quick fix but I’ll try to refactor them first.

Types with too many methods

Only one. But I really did mess that one up. It’s the Session class that contains references to the service objects like BookingService and TranslationService. But for some functions I couldn’t decide in which service to put them in and they ended up in Session class (temporarily I thought). So this class now has Login(), LoadSidebarView() and SaveSettings() functions none of which has anything to do one with another. Maybe the day will come when I could write the project without such class. But it’s not this day.

Code duplication

…is the source of all evil, they say. NDepend uses some clever method for detecting methods that call similar set of functions. I didn’t find visual interface for code duplication detection, instead I had to use Power Tools, a command line program. It did find 21 suspects, few of which really are problematic code. Most of the duplicates have to do with how I load data for view and edit forms. I have LoadEditView and LoadView as separate function that load very similar data. It is something I have to fix. Next it found that the code for booking and enquiry are almost identical and I could probably merge it. Then it found that I use separate functions for booking from the home page and from the offer page but they do almost the same job. And finally, I display recommended offers in header, sidebar, home page and below other offers and NDepend found that I’ve duplicated this function 4 times. Nice catch.

ndepend-code_duplication

Key points

What I really like in NDepend:

  • Rules are writen in query language, I can use the defaults, change the query temporarily or write my own
  • Rules are heavily commented and even linked to StackOverflow discussions if it is debatable

Learning English articles

It seems I just can’t learn English articles. If I take some random online test I’ll do pretty well. These tests usually take form of isolated sentences and as such they are pretty naive, easily gamed. But how do I know if I use articles right when I’m writing, like now. My helpful brother checked some of my writings and pointed out the mistakes, after which I was like “Oh, sure, I knew that rule, how did I missed it?” Since he can’t check everything I write in English, I wondered how to learn those damn articles better.

There is nothing that could automatically check my texts, but I found another way. What if I take already proofread text, remove all articles and then try to insert my own and compare it to the original. That could work. So I went coding. And this is the result: learn-english-articles

I implemented this scenario:

  1. Load a short text from Wikipedia.
  2. Application strips articles from the text.
  3. User fills the missing articles.
  4. Program displays comparison between original and user’s text.

It took me some time to write the right algorithm to compare texts. It’s easy to just show the difference but I wanted more; I wanted to color code different errors (missing article, wrong article, surplus article) and calculate a score. I did it finally, so this is the first version: learn-english-articles

So, that was my project February 2013, part of One-project-a-month.


Code generators

Code generation is one of the software development techniques I wanted to exploit for a long time. It is currently underused or is used in the wrong way. Examples are:

  • Form designers
  • ORMs
  • Domain-specific languages
  • Software factories

Drag and drop form designers generate code in behind for controls and widgets. ORMs generate POCO classes from table schema. Domain-specific language is a tiny programming language that is used to solve a specific problem. Software factories support model driven, pattern oriented approach.

My desired approach is a combination of all above but it avoids their weaknesses. Form designers and ORMs solve problems in one layer only, view and data, respectively. Domain-specific language cross cuts the layers but is specific to one problem domain. Software factories are predestined to become rigid and bloated behemoths. Also, they all hide generated code from developers which can’t be a good idea.

They are useful for developers who don’t have enough knowledge in the area so they use generators instead of learning to code. It’s useful at the beginning, but with disastrous effects later when their ignorance starts to creep out.

My approach is to generate code that the developer would write anyway, but without code duplication and repetitive writing. Every team could write a generator for their project to enforce their architectural decisions and coding conventions.

Code generator should generate:

  • SQL statements
  • DTO objects
  • Business logic template
  • Test templates
  • Placeholders for user interface widgets
  • Validation logic

Code generator should:

  • Support Command-Query separation
  • Avoid CRUD design
  • Help with code maintenance

One project a month

There is some buzz on Twitter about One-game-a-month challenge(#OneGameAMonth). Point is to make a game each month, 12 games in a year. It’s gamificated and social.  There were similar events before, like game-in-a-week or game-in-a-day competitions. Those are for game developers, but I like the idea and I would want to try it for software projects in general.

It could be interesting to try a project-in-a-month challenge. Every month you devise an idea, implement it and publish it.

What’s great about it:

  • You wont be stuck with the same project for a long time, designing or polishing it indefinitely
  • You’ll do what’s really important for the project
  • Once a month you’ll cover the complete software lifecycle
  • What you learn in one month, you can immediately apply the next month

Quick rules:

  • Rules are actually guidelines – it’s not a competition
  • One idea at a time – do not prepare ideas for the next month
  • You can imitate an existing idea, but add some twist or change a point of view

 

My projects generally tend to fail. I condemn them to fail as soon I start working, and for various reasons:

  • I want too much. I create ideas for software, service and business model. I could spend years to actually implement them.
  • I over-architect. I’m so afraid of spaghetti code and dependencies that I spend too much time thinking how to write instead of writing.
  • I’m rarely satisfied with my work. Which is good because I always strive to be better. Which is bad because I get lost in details.

Project in a month positively influences this problems:

  • Project must be small-scoped – can’t do much
  • Minimal architecting – only when needed
  • No worries if it’s not perfect – it can’t be perfect in a month

(Why did I write half of a post in bulleted lists? Maybe are efficiency and minimalism already creeping in.)

(And I published it without a title. Corrected in third iteration)


What’s wrong with persistence ignorance

TL;DR- ignorance is wrong.

Sounds good: write object oriented code focusing on domain problems and let somebody else (or future you) worry about persistence. After all, those two are unrelated problems in different layers.

False presumptions

Layering, responsibility separation, modularity etc. have costs and benefits. In programming we accept some costs if they give as adequate benefits. Modular programming, opposed to just hacking, takes more time to learn, plan and implement at first, but as soon as we need to change some functionality or debug a procedure we start to reap the benefits as all those tasks take less time. Repeat them often and benefits will surpass the costs.

Costs of persistence ignorance are on:

  • performance (layering, mapping, not using optimal SQL queries)
  • coding time (coding against interface is more time consuming, mappers and interfaces are extra code)
  • code size (mappers, interfaces)
  • duplicate code (marginally different structures for every layer).

When you get the benefits? If you change database provider (MySQL to Oracle) or if you change database technology (Oracle to XML). And when will that happen? Probably never. You optimized for the most improbable situation. It’s more likely you’ll change programming language or framework then the database.

Leaky abstractions

Joel Spolsky wrote in The law of leaky abstraction that you can ignore underlying structure or technology in most situations but not in all. For example, .NET string. Instead of manipulating arrays of chars, you can pretend that string is an object that you join, split, append and do many other convenient methods. But underneath, string is still an array of char and every time you change it, a new array is created. You can ignore that in most situations, but put

completeString += appendedString;

in a loop and ignorance will bite you.

Translated into OO/ORM/SQL process, ignoring the persistence technology will mostly work. If database is small enough, it will churn whatever you throw at it. With bigger databases, and every business application worth mentioning have one, only CRUD operation for single object are safe bet. If database calls get into loop, especially if database is over a not-so-fast connection, seconds turn into minutes.

Database is more then storage and SQL is language and tool for itself. Using it only for save and query functionality is not the optimal use. So, always be aware of the underlying system. You can automate some parts and ignore the others, but you can’t ignore it completely.


What’s wrong with Domain Driven Design

One approach linked to OOP is especially problematic: Domain Driven Design. It is very attractive at first, because it gives you the holy grail of code architecture – separation of concerns. It says that you start designing and programming from domain logic and ignore persistence and user interface until you work out your problem domain. Support for persistence and user interface is added later, almost as an external system, so that you can replace them without changing anything in domain logic.

Where’s the catch? If you really design your domain logic first, ignoring everything else, you’ll end up with program that doesn’t work in any of the environments hostile to OO (stateless, distributed, persistent, parallel, asynchronus, relational, transactional) and I can’t remember any domain worth mentioning that doesn’t need to work in this environments.

Of course, no approach will give you this functionality out of the box and domain driven is no different. What’s dangerous in domain driven is that once you start adding code required for persistence or transactions, your core design must change. And it changes so much that new concept doesn’t have any resemblance with original one. For example, unit of work is not needed in any domain. But you have to add it for persistence to work. And when you do, you must change every object to work with it and every function to register changes of state.

Generaly, building a part of a system ignoring other parts just doesn’t seem like a good idea.


OOP – It’s just not working

I failed at object oriented programming, that’s clear now. I learned basic concepts and then all patterns, read much philosophy surrounding the topic and listened to lectures, but ultimately, I failed. I can’t write good OO code. And now I even don’t want to.

At times, my understanding of OOP was growing and I felt I’m getting somewhere, but after a while it gets boring. I never reached the state where I knew exactly how to write OO code, and more importantly, agree with others on how it should be written. The process goes like this:

  1. Learn OO concept
  2. Try to code it
  3. Have a problem that can be solved by learning a new OO concept.
  4. Goto 1

It! Never! Ends!

I’m not trashing OO completely. There are many great concepts introduced in or popularized by OO paradigm but none of them are specific for OO. These are generally good ideas and can be used everywhere. Abstraction, modularity, hierarchy, encapsulation, polymorphism… all great concepts. But when you model everything in OO terms, results can be amusing.

So! Much! Code!

Main problem I find is that to work as advertised/taught/preached, OO programs need a very specific environment. To get the benefits of object orientation, one must avoid following environments:

  • stateless
  • asynchronous
  • parallel
  • persistent
  • relational
  • distributed
  • transactional

Coding OO programs for environments from this list requires much additional code, introduction of patterns and mostly cancels benefits of object orientation. Modern computing environments is done mostly in such environments and OOP never covered them.

Not! Working!