Clarity and side effects

time to read 1 min | 139 words

I just found myself writing this line of code:

Entity = Entity;

I also started writing a couple of lines of comments, explaining what is going on there. The idea is that setting the property update another field which I needed to update.

I’m not against code with side effects. Just look at NHibernate.Generics for proof, it’s a project devoted almost solely for making it easier to create side effects. The idea being that you can write this:

blog.Posts.Add( new Post() );

And anything else would just happen automagically. I think that it’s a very good way to abstract away concepts, so you can concentrate on the model and not on the implementation. On the other hand, side effects for the coolness/terseness should be avoided.