All posts by jrwren

msysgit installer is broken on vista

OK, it isn’t exactly broken, it just doesn’t know about vista’s virtual path features. This means you can run the exe as a non-admin user and it does not get installed properly.

The work around is to not run the installer as a regular use and wait for UAC to invoke itself. It never will. Instead, save the .exe file and right click on it and choose "Run as administrator…"

Now the program will actually get installed to C:\Program Files or C:\Program Files (x86) instead of the virtual are c:\Programs\data\user\blah\wahterver\it\is\vista\has\some\crazy\features.

Why am I using GIT? Well, unfortunately because I have to. Cloning was easy enough but just typing git help or git help clone and I immediately miss the polish of bazaar. The "I have to" is in reference to the no longer ignorable myriad of projects now hosted at github. IMNSHO all of these should have opted to be hosted a launchpad. But as we have seen in the past in technology, the best solutions don’t always win. Sometimes the solution with the loudest voice wins. (VHS>Beta?) (DAT>DCC?) (Blueray>HDDVD?)

Lack of Value of Code Metrics

I was just reading blogs and stumbled across this gem:

http://codebetter.com/blogs/patricksmacchia/archive/2008/08/26/nhibernate-2-0-changes-overview.aspx

Patrick ran NDepends (an awesome static analysis tool) on the 2.0 release of NHibernate.

Patrick went on to suggest that the NHibernate code base was spaghetti because its internal namespaces are cross dependant. Having looked at the NHibernate code base, I disagree. In fact as a base for learning more about programming by reading others source code, I have found NHibernate to be an excellent source of learning.

I tried to post this as a comment, but I couldn’t (maybe my Opera browser, or lack of JS?).

“IMHO, the NHibernate team should fix this problem asap”

I can fix it easily, just flatten out the namespaces. Put EVERYTHING into the NHibernate namespace and this wouldn’t be a problem.

Is this the right thing to do?  NO!  But it does fix your metric.  So I assert that your metric is wrong.

Who care if namespaces are cross dependent?  I don’t. Namespaces are for logical groupings of behaviors. If your behaviors are cross dependent, so will your namespaces.

This metric may be useful in a typical 3 tiered layered business application. NHibernate is not that. It is one ORM library. ONE. I do not find your metric useful.

 

Given any metric that you are using (P/E ratio for stocks anyone?) please be aware of what that metric actually means and consider its value in that specific case. Yes, you must reconsider each metric on a case by case basis.

New Server and My Worthless Linux Account Management

I got a new server for my home, more to come on that later. Right now I want to talk about my worthless account management practices. You see, a long time ago (4 years) in a land far far away (2 counties), I was a system administrator. I knew all the best practices. I could plan a server migration with zero downtime or if some DT was required  could minimize it. I could keep my servers up with 3-4 9’s (99.99?%).

I think I’ll compare my situation to that of the super clean janitor who invites you into their home only to reveal that they live in squalor. My home server works, but it is a mess. So it is wholly appropriate that when it came time to replace my aging server with 3-4 years of Linux cruft (initially installed with Breezy Badger and then upgraded) that I throw caution to the wind and just install Linux and see what kind of problems I run into.

Well, the first problem I run into is that my baby cannot watch her Baby Signing Time DVD rips from the server — I know ripping DVDs is a violation of the DMCA, but Jeff Atwood says it is OK, so if you are an MPAA lawyer, please see Jeff, he is a top-10 blogger and must have way more money than I do — the XBMC wouldn’t work. Well DUH!  The only account on the new system is mine. I hadn’t created any XBMC account for the samba share, nor had I set its samba password.

Since I’m sure many other people might reinstall and not upgrade, but would like to not have to reconfigure everything, this is my little migration guide. I’ll assume that you have a backup or your old hard disk lying around and that you are capable of getting at the needed files in some way. In my case, my old root file system is mounted /mnt, so when you see /mnt paths in these commands, just remember that is my old disk.

Jay’s Stupid Guide to Account Migration

First, it is important to keep in mind that Ubuntu, Debian and AFAIK every Linux distribution these days creates necessary system user accounts for you on demand. e.g. I didn’t have a bind account and group on my system until I installed the bind9 package. This means the the uid/username map will most certainly be different between your old system and your new system. I’m OK with this. I want a new system. I just want some old user accounts.

Visual Inspection

$ cat /etc/passwd

….

jrwren:x:1000:1000:Jay R. Wren,,,:/home/jrwren:/bin/bash

janice:x:1001:1001::/home/janice:/bin/bash

sbak:x:1003:1003::/home/sbak:/bin/bash

….

Cool, so there is my account, and there are a few others. One for my wife, one for a great friend, and I left out a few more. But there aren’t too many, so if I had to manually do this, I could do that. If I really had to copy and paste lines in passwd and shadow I could. But I won’t.

Let Them Login

Use your eyes and know your regex. In my case the uids for all of the accounts I wanted moved were 1001-1007, so I confirmed that my regex was correct and then just appended via pipe using tee.

$ grep x:100[1234567] /mnt/etc/passwd | sudo tee -a /etc/passwd

I could now run the “id” command for these new users and it would work!  Neato.

But I’d like them to be able to login with their old password in case they were at some place without their ssh public key, so I set out to do the same thing with shadow. Shadow is keyed by username, not uid, so we just have to map back to that.

$ grep x:100[1234567] /mnt/etc/passwd | awk -F: ‘{print $1}’ | sudo grep -f – /mnt/etc/shadow | sudo tee -a /etc/shadow

Cool, now people can login.

Power In Numbers and Groups

If we look at the stat(3) of a file from the old system as owned by one of these migrated users now, then the uid maps to the correct name but the group is incorrect. We need to do the same thing for groups.

$ grep x:100[1234567] /mnt/etc/passwd | awk -F: ‘{print “x:”$4}’ | grep -f – /mnt/etc/group | sudo tee -a /etc/group

So we map a little differently and we construct our fgrep regex using awk, but its mostly similar to the shadow case.

Samba

Regular user accounts are all neat and good, but the whole point was XBMC which connects via samba share. This is where my sysadmin knowledge is starting to show its age. The last time I migrated samba accounts the accounts were in an smbpasswd file and could be moved very much like the shadow case above. These days samba stores this information in a trivial database known as a tdb. http://www.samba.org/samba/docs/man/Samba-HOWTO-Collection/msdfs.html (No idea why an html file named msdfs actually contains tdb information instead of DFS information.)

I had to search the docs and google a bit before I found this post: http://fixunix.com/samba/246816-samba-where-samba-store-users-passwords.html  which lead me to the pdbedit command. Samba has changed since I last used it. http://us3.samba.org/samba/docs/man/Samba-HOWTO-Collection/passdb.html

Unfortunately, I didn’t have tdb password entries for all these user accounts, actually I had ‘em only for two. No big deal since the easiest path is to go through the old smbpasswd file format to get here.

First thing, I found that pdbedit doesn’t like read only file systems, so copy your pdb local (did I mention my old disk is mounted read only at /mnt?)

$ cp /mnt/var/lib/samba/passwd.tdb oldpasswd.tdb

Now we need that old smbpasswd file format

$ sudo pdbedit -Lw -b tdbsam:oldpasswd.tdb  > smbpasswd

Then I want to filter it for only the accounts I care about.

$ grep x:100[1234567] /mnt/etc/passwd | awk -F: ‘{print $1}’| grep -f – smbpasswd > smbpasswd.stripped

Then (thanks to abartlet #samba on freenode for guiding me) merge these into the new systems passwd.tdb

$ sudo pdbedit -i smbpasswd:smbpasswd.stripped

Now you should have functioning samba passwords.

If someone reading this is thinking, oh this is WAY easier in windows, could you please link me to the step by step process like this? I’ve always wanted to use it and I could never get it done.

C# Features As Requested By Others: Please No Duck Type By Default in C#

I replied to a blog post by Tosos over here:

The reply was long enough that I thought it warranted posting here too. I expand on why “var” is not dangerous and can go away. I also describe why it isn’t duck or dynamic or anything but strong and static. If you know F# this is nothing new to you.

Here it is:

I love these.

@Mike Borozdin:
Consider F#’s definition of methods(functions). It is just as strongly typed as C#, yet the compiler is left to infer the return type.

In the example above the return type is not weak, it is not vague or dynamic or relying on duck typing. The return type is the anonymous type defined by the select clause of the linq statement. All of the static type checking and strength of warnings and errors of the compiler will still occur.

I’d like to see similar syntax, but drop the var, it is needless noise.

e.g.

public GetFirstPageOfFiles(string dir)
{
  return Directory.GetFiles(dir).Take(10);
}

The signature of the method GetFiles takes a string and returns a string so we (and the compiler) KNOWS that GetFirstPageOfFiles returns a string.

But have we simplified the language as much as we can? F# wouldn’t make me specify the type of the argument to the method. It would infer it.

public GetFirstPageOfFiles(dir)
{
  return Directory.GetFiles(dir).Take(10);
}

Again, the argument to GetFiles is string so the compiler knows how to turn the method signature of

public GetFirstPageOfFiles(dir)

into

public string GetFirstPageOfFiles(string dir)

Where the compiler can’t infer, it should give an error and require the explicit use of the type.

This exactly the behavior of var now.

As for #3, I would NOT want this to be the default behavior. The default behavior should be strong-static types. As strong and as static as possible. That said, some compiler support for the equivalent of duct typing via reflection would be rather nice. AFAIK what you are asking for is already available through a 3rd party library from David Meyer at http://www.deftflux.net/blog/page/Duck-Typing-Project.aspx

With respect to default behavior being duck, Phil Haack is wrong, everyone is wrong. If you want that, use Iron Ruby or Iron Python.

I wrote about my uncertainty about the GetEnumerator duck here: http://jrwren.wrenfam.com/blog/2007/07/21/c-has-duck-typing/  It may have been necessary. If it wasn’t necessary, I’d call it a mistake. Maybe it was an accident. I don’t know.

Could I be more against duck typing? Yes, I could be against it entirely. I could completely misunderstand it. Unfortunately I’ve written in duck languages. I’ve probably written more code in PHP, Python and Perl than I have in C#. (I wrote A LOT of Perl and PHP.)

My simply request is to require the manual selection of behavior of duck, like Boo. Yes, I say “like boo” a lot, but much could be learned from boo. Boo had extension methods before C#. Boo has duck in a strong, static typed language. Of course, boo is not a special case. It is best to learn as much as possible from neighbors so that you can make your own decisions about things. My request is probably going to be granted. Charlie Calvert wrote about the dynamic keyword and dynamic blocks as a possible solution to this.

Business Logic is a Bad Word

I do not write business applications. Oh sure, I write applications for a business. This business makes money. The applications which I write helps them make more money. However, these applications are in the domain of product engineering. They are not in the domain of running the business. They do not deal with cash flow, inventory, accounts receivable or payable. There is no letter opener of death involved with any of my application users.

My applications have no Business Logic. The business processes could change at this company and my applications don’t know anything about it. We solve engineering problems. That said, separation of UI and Business Logic is still a strong concern. It isn’t Business Logic. It is Application Logic.

Why mention this? I feel like there are programmers out there who say to themselves, “I do not write business applications, therefore this silly separation of business logic does not apply to me.” These programmers are wrong. Separation of application logic from UI code is valid not matter what the application. Separation of Concerns extends to every type of software. I cannot imagine a type of software from which separation of concerns does not benefit. I’ll go so far as to say that if you think you have a case: that you are wrong. If you think you can justify it to me, I will simply redesign to a case which does fit.

Do you write math apps?  Separate your Math Logic from your UI.

Do you write engineering apps? Separate your Engineering Logic from you UI.

Do you write medical apps? Separate your Medical Logic from your UI.

Do you write biology apps? Separate your Biology Logic from your UI.

Do you write Anthropology apps? Separate your Anthropology Logic from your UI.

Do you write Sociology apps? Separate your Sociology Logic from your UI.

Do you write Psychology apps? Separate your Psychology Logic from your UI.

Do you write Legal apps? Separate your Legal Logic from your UI.

Do you see a pattern here? Separate your seeing of patterns from your UI.  Good.

C# vNext feature request 2

I previously had a list of things I wanted. Yes, I am like a 2-year old. I want. I want. I want.

mdavey posted a link to a channel 9 video which made me rethink my request. Oh I still want all of the original list and… I want more. I want more. I want more.

  • List Literals – it is silly that I even have to request this
  • Dictionary Literals – see list literals for comments
  • Extensible Literals – the .NET BCL already has this really great type conversion system. You ask for a type converter for a specific type and whether or not it can be converted between two types. One of these types is often a string. You can write your own converters and register them with this system of type converters. It is very elegant and beautiful. The compiler should use this to let me express my own literals. Type initializers are nice, but this would be nicer.
  • Variable Generic Type Parameter ArityChris Marinos had a use case for this and had to implement a solution in a much less elegant way because he was missing this feature. Its a request in Java too. Cliff Biffle says that Mongoose has them, but I can’t find whatever became of the smalltalk inspired language.
  • Restricted Types – The same post on Variable Generic Type Parameter Arity, Cliff reminded me of my favorite Modula-3 feature. He points out that Dylan has it. I like Modula-3’s approach to this using Subtypes. This paper by Cardelli, Donahue, Jordan, Kalsow and Nelson does a great job of explaining Modula-3’s simple but powerful type system. Not all of the subtypes in M3 make sense in a .NET world. We already have a well defined type system and some of the constructs would not mix. One concept that I think would mix well is range subtypes. Imagine that you know a value is always going to be between zero and 100. You can define a subtype of int and use that type throughout your program. The compiler actually checks that variables of this type are never out of this predefined  range. Type Conversion is automatic from int subtype to int type, but not the other way. It is awesome if for nothing other than eliminating IndexOutOfRangeException on array indexers.

 

Yes, I do want my cake and to eat it too.

MVP For Me

A week ago, on Tuesday, July 1st, I received a strange email. I should have known it was going to be a strange day. I was wearing my Ohio Linux Fest 2006 t-shirt. I had just listened to Java Posse podcast and was listening to Mac Break Weekly. Since I don’t write java code and I don’t own a mac, I should have know I was playing with fate.

This email might have been a joke. It was short and to the point, exactly the opposite I would expect for an email of this subject matter. It should have been some crazy HTML formatted table of disgustingness which I would have initially dismissed as spam. It should have had embedded images and fancy fonts. It had none of these things.

The email subject said very simply and plainly, “Congratulations! you have received the Microsoft MVP Award”. Surely someone was playing a trick on me. It was probably one of my old Linux buddies making fun of me for using so much Microsoft software these days.

I opened the message to read, “Congratulations! We are pleased to present you with the 2008 Microsoft® MVP Award! The MVP Award is our way to say thank you for promoting the spirit of community and improving people’s lives and the industry’s success every day. We appreciate your extraordinary efforts in Visual C# technical communities during the past year….”

It looks legit. I don’t know what I did to deserve such an award, but I’m grateful for it. I plan on continuing doing whatever it I’ve been doing.

Who knew that an perl loving, linux loving, python loving, linux kernel hacking, mono loving, C# loving, boo loving, F# loving, wife loving baby loving insane hacker could be a C# MVP. I sure didn’t.

Thanks to anyone who put in a good word about me.

Critically Analyze What You Read And Hear

Thanks to Jon Paul Davies for quoting the Pragmatic Programmer.

“Critically Analyse What You Read and Hear. Don’t be swayed by vendors, media hype, or dogma. Analyse information in terms of you and your project.”

-The Pragmatic Programmer by Andrew Hunt & David Thomas

I’ve been living my life that way for so long I’ve given up even trying to be gracious about accepting someone’s words. I’m known to just flat out say “I don’t believe that.” When I hear something from someone which doesn’t match points at which I have arrived from previous critical analysis.

Jon Paul also has a really cool domain name. It makes me want to register jay-w.com for myself, but there is already a jayw.com and wouldn’t you know it??? This Jay Walters fella is a Software Developer too!

Enterprise Library 4.0 released and unusable

EntLib4 was released recently. My bug is not closed. I can’t use it. :(

It is just a library. I don’t want your guidance. Just give me the source. Let me change it, build it and use as I see fit. Last time I checked, that is what developers do.

You may be asking, why would I even want to look at EntLib?

EntLib is better than nothing. If you happen to work at one of those horrible organizations that can’t use anything that isn’t from Redmond, then EntLib is what you should be using. That is, EntLib is what you should be using after you try to find a better organization in which to work :) As a contractor, I want to be aware of it and know what things I can expect to run into when working with a client’s code.

My preferred library is castle for IoC and data access and even logging with Castle.Core.Logging being a thin wrapper to either log4net or NLog. Some area’s where EntLib does do things which I might find useful is Exception Handling and Instrumentation.