Sunday, September 22, 2013

Pidora out. Raspbian in.

I tried to like Pidora. Really did. It's not that I dislike "systemd" - I don't. I just hate that it seems most of the other hobbyists are using Raspbian. It's so annoying to find someone with a great tip only to discover that they're referring to Raspbian, not a system-d setup. Meh.

So, we'll see how this one compares. I've been using the Pidora from the beginning and got all the stuffs working that I needed so far right up to setting up a fixed IP for it so I can connect it directly to the Macbook Pro for working in coffee shops.

Saturday, April 06, 2013

I can haz fonts?

I'm not a graphical designer, and as such don't pay much attention to layouts, design and fonts. But this is sort of cool. Cufon.

I was inspecting someone's HTML to steal how they'd done their layout to learn how they did their layout and saw the tag ho's feeling constrained by the standard set of fonts that are available it's a godsend.

There's a little write-up here, and here.

Friday, March 29, 2013

Resharper as a coding instructor

I've been using Resharper a lot more lately. It's evolved nicely; while still a little annoying and intrusive the productivity increase is dramatic. Many of the features are things Microsoft should have added into Visual Studio years ago (they've been in Eclipse for what, 10 years?).

One of the neat things is that it is constantly suggesting better ways of coding or of structuring your code. I find myself learning about attributes of C# that I'd either forgotten, or hadn't know about.

I have a list of transactions that I want to add to the budget month container. Traditionally we might have done something like the following.

foreach (var transactionItem in items)
{
 month.AddTransaction(transactionItem);
}

This simply iterates over the collection of items, and for each one it calls the .AddTransaction method on the month.

My more modern method might be more like this:

items.ForEach(i => month.AddTransaction(i));

Resharper, though had a suggestion. Why not simplify that line even further? I'm game - so I clicked the suggestion. After all, there is always undo. This is the line;

items.ForEach(month.AddTransaction);

Simple, concise, and clear. I will confess that I had to run the unit test it in the debugger and inspect month's transactions just to make sure that the items had actually made it in there. Yup. Sweet.

Wednesday, March 27, 2013

RavenDB with MVC 4

I've decided to use RavenDB for a project that I'm working on. I've been researching a number of database options for a site which could eventually have pretty rigorous traffic load. Though I really like MS SQL as a traditional relational DB I've seen it, when coupled with naive EF use, become a horrible drag on performance.

So far I'm pretty impressed. It is very nice not to have to setup and maintain a dedicated ORM just to translate from the real world of objects into a flattened and normalized set of tables. I've created a set of "POCO" database classes in my BI/Services project (though for a larger project I'd probably simply have a dedicated database project). For the classes that will be the document that is stored I've added a string property to receive the document ID. For those that I'll explicitly define the key I simply added a method to the DB class "GetKey()" - in the example below the key is "UserProfile/curtis.forrester".

public DBModels.UserProfile GetUserProfile(string username)
{
    using (IDocumentSession raven = Store.OpenSession())
    {
        UserProfile user = raven.Load<UserProfile>(UserProfile.GetKey(username));
        return user;
    }
}

public void StoreUserProfile(UserProfile profile)
{
    using (IDocumentSession raven = Store.OpenSession())
    {
        raven.Store(profile, profile.GetKey());
        raven.SaveChanges();
    }
}
This is all that is necessary to store and load a UserProfile document. Since the data is stored as JSON I also modified the class and had no issues at all. I added some properties, loaded the UserProfile, set the new properties and stored the document and the updated "record" now reflected the new version.

The flexibility that Raven provides to generate keys for new documents is fantastic. From fully letting the server handle it to providing a method for you to register a custom handler is great.

Like all databases some knowledge and experience will be required to make sure that performance is up to par. I did some initial testing where I stored a bunch of documents that had collections and then loaded them. I found that loading each individual document was much slower than using their bulk loading approach. I found that the sweet spot was to load between 25 and 50 documents. When I increased the number to 500 or 1000 it was as slow as loading each one-by-one.

Wednesday, March 20, 2013

SOLID vs GRASP

I have, like I'm sure you have, encountered the "experts" who ask the normal buzzword questions:

  • So, do you follow the "Gang of Four" patterns?
  • How about SOLID - do you use that in your job?
  • Have you used dependency injection techniques?
This reminds me a lot of how our culture was in the late '90s with people dressing in the robes of either Booch or Rumbaugh. Your school of thought and the modeling approach you used was like a religion. Fortunately UML fixed all of that (ya, remember UML?).

The SOLID question has gotten me thinking. We all know (or should know) what SOLID is all about. That doesn't mean that we agree. When this acronym was starting to become generally used about the same time most of our ".com" companies were collapsing I remember debating its merits with others I worked with. In general I was in agreement with the principles, and certainly with the spirit and goals of the rules.

Single responsibility principle - that a class should have one role or function. Absolutely. This keeps the overall design clean and it is generally easy to understand what stuff does and how they are relating to those they interact with.

Open/Closed principle - that a class is open for extension, but closed for modification. No way. More on this later.

Liskov substitution principle - that objects should be replaceable with their subtypes. On this I generally agree. But this is especially good when you use a factory, and follow the "I" of SOLID and have defined discrete, functional interfaces. In that case especially a consumer of your class doesn't care if it's the original parent instance or some later substituted child.

Interface segregation principle. Just give your customer what they want. If all they need is a small subset of what the class provides let them see your class through the eyes of a simple interface. The less any one part of a software system knows about any other the easier it is when refactoring must be performed. It is also easier to do TDD and write concise unit tests.

Dependency inversion principle. This generally good principle has led, in my opinion, to some of the most unreadable and hardest to debug code. However, when done correctly and cleanly this makes for very "agile" software design.Microsoft recommends using a service locator - and while at design time it's not always obvious which service you'll be using, that's just the point. It doesn't and shouldn't matter. Only that you'll be interacting with some service at run time that will provide, well, the services you'll need. Unit test are greatly simplified using frameworks like Moq. Back in my Java days we used Spring for injecting configuration.

So, what is my issue with "SOLID" and why have I mentioned GRASP in the title? Well there are two reasons. First I do not at all agree with the fundamental principle of the "Open" part. One of the original features of "OO" was that there was an exposed interface that provided a contract to the user. How the implementation did this was of no concern to the outside consumer. This meant that the class could be completely rewritten with no disturbance. That I might need to have the code reviewed again (a silly concept) just because the implementation has changed ignores TDD - if there are a series of complete unit tests that automatically verify that the class is abiding by its contract any and all changes should be permitted.

The interface, and the contract, of a class should never change - it can be extended if need be, though I personally feel that even this isn't a good idea. If a particular class needs to provide more and new functionality this is to me an indication of a need for a new subclass. Yet "SOLID" purists seem to feel that Bob Martin is a deity and these principles sacred. Sacred cows make the best hamburgers!

My second objection is that these principles, while great, only reveal a part of the overall field of good practice.

GRASP

Enter yet another acronym, but an important one. "General Responsibility Assignment Software Patterns". That one had to have been born in a pub over a few beers. These "spoke" to me when I started hearing them packaged together along with the concept of Domain Driven Design. These are patterns firmly planted in the real world. 

In my current role as an ASP.Net MVC developer the "Controller" is critical to handling all user interface interaction. Factory patterns have served me well for allowing a system entity to ask for a service or module that will provide the named function and allowing the factory to determine what to create and return.

Services, delegates, and loose coupling - these are standard motifs that we use every day that that provide robust models of software architecture.

It is not so much that I prefer "GRASP" over "SOLID" any more than I prefer Hibernate over Entity Framework. They both have their place and both their advantages. But purists that want to ask interview questions like "do you use SOLID in your current job" need to understand that there is a wider field of study that any one acronym simply does not encapsulate. 

Finally, a semantic point: we don't use SOLID in our job - we become it as developers. We don't use the patterns of GRASP - they become a part of us. When they are the fabric from which we are woven we become the types of developers that create well-designed and agile software.


Friday, March 01, 2013

TSA Doesn't have to Suck

My work took me to Columbus, OH this week for a two day trip. Actually, it took me about a world away from Columbus to a little town called McArtur where there is the only official light in the county. There is also one of the oldest companies still in existence in Ohio having been established in the late 1800's. Then manufactured dynamite for mining; they now manufacture much more powerful explosives. I had a unique opportunity to see their operations up close since I was installing some software that I had written to enable them to track product through manufacturing, packaging and onto a truck destined for European customers. In short, the gig was "a blast"!

When I left Atlanta Tuesday morning I had the usual unpleasant experience of walking through Atlanta's TSA gang. While the lady who was checking passports and boarding tickets was very pleasant it all ended there. As one approaches the scanners they're greeted with somber-faced agents who tend to command and yell rather than instruct. I get it - they deal with clueless travelers all day. They don't get it - we're clueless cause the rules change and not everyone travels that often.

Traditionally we've had to walk through metal detectors. They now have these body scanners that require you to walk in, face a certain way, and raise your hands above your head as if you were a criminal. Humiliating and demeaning that it is, what is worse is when (literally) three agents yell at you to raise your hands. You're powerless to even look at them for fear they'll ID you as a terrorist and pounce on you. I escaped security with my usual frustration and resentment.

When I left the plant I changed to street shoes, changed my pants, changed my shirt and washed my hands. I had been warned that I might set off the detectors at the airport. I did. The body scanner detected something and so the gentleman told me he needed to do a pat down. I have a good sense of humor and they all seemed friendly. When he patted my rear-end side I went "woo!" in fake enjoyment. They all laughed. He says, "Oh, great - right in front of my supervisor." It was fun. Then he swabbed my hands and headed to the machine. Says I, "Oh boy - if you knew where I'd been the last two days." Jokes he back, "Not sure I want to know."

And the machine started screaming - "Explosives! High Explosives! Grab the guy." And I reply, "Yup - I was afraid that would happen."

The next 15 minutes or so were one of the best experiences of both professional and simple human interaction. They, naturally, did their job and followed procedure. But they were very friendly and polite about it. They knew where I had been, having seen other employees and their family come through and set off the detectors. They did a full pat down, and searched all my stuff. They explained what they were doing every step of the way, and even the beefy security guys that showed up (appearing to be ex-military) were friendly. They were focused and professional - had I been a bad guy there is no way I'd have made it through. But they were also quite willing to laugh, smile, and answer my questions.

What is the difference between the TSA in Columbus, OH and Atlanta? There are some, for sure. One set seem to have a chip on their shoulder and thrive on the power they have while the others are simply Americans doing a very important job. One group could care less to leave you with some dignity while the other respects you as a fellow American deserving of respect.

TSA doesn't have to suck. TSA agents don't have to be nasty, grumpy and bossy. They can instruct you as to what they need you to do in a manner and tone that allows you to endure the delay with dignity and respect. In return, I believe that travelers will show them respect and will go through the security-experience with patience.

Monday, January 21, 2013

PyCharm and Google App Engine on Mac OS X

I really like PyCharm. I've started playing with Google's App Engine to evaluate it for hosting a project. I wanted to build the site in Python - ultimately with Django. I've had it setup and working just fine on my Windows 7 dev box at home, but I really like to be able to also work on my laptop at the local C8H10N4O2 establishment.

Naturally, the PyCharm page that walks through an intro to using PyCharm with GAE uses Windows as the setting. There is little about setting up PyCharm to point to GAE for Mac OS X - other than stating that it will automatically detect it. It didn't. Bummer.

After poking around a bit here's what I had to do:

  1. Make sure that symlinks are generated with GAE launcher. On installation it will ask if you wanted this. If you said no then, simply hit the "GoogleAppEngineLauncher" menu and choose "Make Symlinks...". It'll ask you to authenticate.
  2. In PyCharm, Preferences drop down about half way within the project settings to the Google App Engine item. Enable GAE and enter "/usr/local/google_appengine" for the path. The warning message should disappear as soon as you've entered this.
  3. Optionally enter your Google account email/password if you want to publish the application directly to Google. (I didn't since I'm primarily working on the project local when on the laptop.)
That's pretty much it. Now the code autocompletion will work within Python code. Sweet!

As a side note, I've found the GAE to work sufficiently well, though setting it isn't totally straightforward. And, I've found that when I attempt to use the user login stuff - since I've constrained my application to only the user accounts for my domain - always returns a nasty looking exception page.

Wednesday, January 16, 2013

Subaru BRZ - My experience so far

I ordered my BRZ without ever having actually seen or driven one. This was typical for buyers last year and will probably continue into this year (2013) due to the still-diminished supply. I have absolutely no regrets. The car has not disappointed. I had researched it, had read personal reviews from owners, and felt that it would be a great car. It is.

I have a manual transmission, Limited edition in the Dark Gray Metallic. I had them install the mirror with the Home Link and auto dimming. I bought it from Subaru of Kennesaw, who were absolutely fantastic (see the details below). I've had it since Nov, 2012.

Appearance

The car looks great. I get so many compliments by people - both those who know what it is, and those who don't. It's small, looks very sporty and just has very clean lines. It's a simple car with only a few "fancy" design elements to it. I've had high school girls (much to my embarrassment actually) beg to sit in it and take pictures of each other in it. I've had the 20-something guy at a Publix who was bringing my groceries drool over it - he knew all the stats. It feels good to own the car and to be seen in it. It doesn't feel too obscene from a price perspective, but it appears like it should.

Comfort

The BRZ is surprisingly comfortable for being a dedicated sports car. The seats have great support when dancing with G-Forces around corners and are sufficiently comfortable for the daily commute. They are a bit stiff and not nearly as comfortable as the seats in my Lexus IS from a vertical perspective, but are much more comfortable from a lateral perspective. 

I am 6'4" - tall for such a small car. The seat is not all the way back. There is about 1.5 - 2" more it could travel back. Everything in the car is within easy reach - shifting is natural. While I don't care for touch screen in a car (too distracting), it is within reach and sufficiently responsive (see below). Steering and operating the pedals are all natural and comfortable.

Forget putting anyone but the family pet in the back seats. If the passenger seat is moved forward two small kids could sit in the front and passenger-side back. I can't imagine any adult attempting such a feat. I've dropped the rear seats to open to the trunk, however, and have carried all sorts of stuff (including runs to Home Depot!).

Passengers have commented that the felt the seats were comfortable and felt great while I was being stupid around corners. This includes my 14 year old son and 74 year old 200 lb dad. It is a little difficult for me and larger people to get in and out since it is so low, but easier than with my Mit. 3000GT - which has much larger and heavier doors.

Handling

This is, by far, the signature feature of this car. The handling is exactly as it is billed - superb. The car corners better than any car I've driven. While many complained that the car shipped with crappy tires, I've found them to be just fine. With the traction control enabled it is somewhat difficult to get any drift; even with sport mode enabled the car still just sticks around corners. When it does drift the feeling is very predictable and handling very responsive.

The car can be steered with the accelerator, just as you'd expect. Under and over steer can be achieved easily. I've come into corners faster than I would on my motorcycle and there was that moment of "oh crap, I'm coming in too hot" and I've just hit the accelerator a bit and power steered right through it. (Weeeee!) And yes, no tickets yet - one doesn't really have to go fast in this car to have fun.

I may give into the temptation to take the car onto the track, especially when I'm nearing tire-change time.

One final note - and a very important one. My Lexus IS-250 was absolutely horrible in the rain. It bordered on precariously dangerous. I hated highway driving in the rain in that car. My Camry did great, especially with rain tires. However, this BRZ is by far the best rain-driving car I've owned. Even with the stock tires everyone bitches about. I can drive at any speed in any rain on any road with total confidence. I've hit puddles (small lakes, really) and just splashed through them. Driving in the rain is an absolute (and surprising) delight.

Performance

The BRZ has about 200 HP and 151 ft lb of torque. The focus of this car is fun and handling, and is not intended to be a "hot rod". This is true. In my opinion the car is slightly underpowered. It will get up and go - my son loves when I wind it out. The shift between 1st and second comes too quickly, but between 2nd and 3rd there is a nice kick - if the RPMs are above about 4500. At the 9 second 0-60 rate it doesn't set any speed records, but is fun. And that is the goal.

I would like to see the car have about 20 to even 40 more HP simply for passing - there have been times when I wanted to get around a person who was too slow and the car really doesn't have enough "umph" to guarantee that you will safely get past them before they notice and subconsciously (or deliberately) speed up.

The biggest design flaw of the Boxer engine is that 4k torque dip - it is very much a factor in any sport driving.  It's like it starts to die at about 3800 and really doesn't kick back in until about 4400 RPMs. This is the primary reason I've considered dropping in replacement exhaust and intake - and maybe computer tweaks. For normal daily commute driving it's not a problem at all - I generally shift at around 4K for gas milage reasons. But for sport driving - meh.

Efficiency - Gas Milage

Let's face it - one doesn't buy a sport car to get great gas milage. But it's delightful when your daily commute is supported by efficiency. The modern Corvettes can get 26+ for pokey driving. I'm currently averaging 27.3 overall. My current commute is suburb to suburb, so there are a number of lights requiring stop and go.

The decent milage is nice since Subaru/Toyota requires premium gas.

Sound System, Nav, Climate Control

The sound system is decent. The sound is ok. It's stock. You're not going to win any boom boom awards. I play hard rock, classical and talk and all are sufficiently good. It comes with the preview subscription to XM, which has a few decent channels.

The climate control works great. It has a dual mode (though in such a small car really only means that one will have a higher fan output than the other side). It warms the car up very quickly and cools it off very well. I've generally just left it at about 70 and forget about it.

I have the heated seats and set to the rapid heating mode will fry your behind in a matter of only a couple minutes. I hardly ever leave it on - it's just to get things warmed up initially in a cold morning.

The navigation/maps? Worthless basically. It locks out features when the car is moving and I've never been able to successfully enter an address. If you do happen to get a destination entered it does perform fairly well - the speaking is helpful and the display readable. It will show large highway signs when you're coming to a split. But generally I simply use my Google maps on the iPhone which will (usually) speak through the sound system.

Naturally, I did change the ugly Subaru stock startup navigation screen with a Bart Simpson one.

Dealership Experience

If this car was only available through Toyota as a Scion I would have probably never bought it. I absolutely hate Toyota dealerships. The only way I would have bought it would have been if I could have purchased it through my Lexus dealership, which I love.

I've also been in Subaru dealerships - there generally is none of the high pressure, slick sales pitch you find at a Toyota or Nissan place. But, you can also often wander into a Subaru dealership and not see signs of life. I bought my BRZ through Subaru of Kennesaw - they were absolutely great. No pressure, great information and just all around good people. They presented the options available, but never tried to manipulate me into a decision. I had forgotten my checkbook since they'd said I could just use my debit card for the downpayment - but they didn't know I was going to drop $10K. No problem. We completed the deal, and the finance manager - who lived near me in Cumming - just had me drop off a check at their sister dealership in Cumming the next day. It reminded me of old fashioned country business - based on character and trust.

In Closing

I love the car so far. The quality and feel is solid, handling is fun and the overall package has reignited my love of driving. Until I can afford a Ferrari, this will do very nicely :)

Updates


  • Feb 21, 2013 I took the car in last week for the first service, which is mostly just an oil change. The odometer reads just past 3K - I think they recommend it at 5K but don't recall. I didn't have the time to drive to Kennesaw for the service, which I intended due to my good experience with them. But my office is literally across the road from the Gwinnett Subaru dealership. In a word, they were also great to deal with. I got an appointment the day after I called and they even dropped me off and picked me up from my office. (I'd have walked, but playing "Frogger" on Satellite Blvd in the rain sounded too exciting to me.) Jill was my service rep and took good care of me - including calling multiple times to remind me my car was done and urge me to hurry since they were closing.