First cold since the new 'healthy lifestyle'...

I've wound up sleeping all weekend...which is unfortunate as I have a ton of work to do (and a ton of laundry). Always a quandary whether to try and work when ill or just sleep and try and get better for work. Sleep is a winner right now; along with a 5:30am start tomorrow to try and catch up at work. Lessons learnt: don't promise to work the weekend when you're feeling a cold coming on...oh and get the guy who wrote the stuff to write the docs for the stuff.

Visual Studio...respect my authrateh, I want to go dark!

I've been surreptitiously looking at people's VS color settings over the past few days and there's a definite trend towards 'the dark side', I've been very boring and the only change I really make is to using a non-proportional font(Verdana) and a teeny tiny text size. I would go to the dark side *if* I could get the rest of VS to go the same way...if Office can do surely we can (hopefully when vNext kicks off they'll have some nice UI enhancements). I just think a black text hole in the middle of a generic gray UI looks tacky.

Grrr...poor use of singletons and a very cool Generic Singleton pattern!

I posted earlier that I'm switching to blogengine.net, as part of this I've been fiddling around with the code (as is my way..I'll contribute back to the source when I've finished). One of my major pet hates is poor use of the singleton pattern, especially as there's a definitive article on the pattern in .NET and how to do it well. It's actually likely that this pattern is overkill in this case and a ReaderWriterLockSlim could be better (though it has it's own problems) . Anyway, on the assumption that a Singleton is the best choice here, let's look at the current code:

 

public static BlogSettings Instance

        {

            get

            { 

                if (blogSettingsSingleton == null)

                {

                    blogSettingsSingleton = new BlogSettings();

                }

                return blogSettingsSingleton;

            }

        }

 

If you look at the article I mentioned above you'll see that this is the version which is specifically called out as follows:

"the above is not thread-safe. Two different threads could both have evaluated the test if (instance==null) and found it to be true, then both create instances, which violates the singleton pattern. Note that in fact the instance may already have been created before the expression is evaluated, but the memory model doesn't guarantee that the new value of instance will be seen by other threads unless suitable memory barriers have been passed.'

The common 'best' singleton pattern (well, it's debatable...but generally the best...) is a lot more wordy (see version 5 in that article) so I was please to find this post on a Generic Singleton (actually this was posted a while ago on Codeproject)...really nice. In the Utils class I added this:

 

    /// <summary>

        /// Provides a Singleton implementation using Generics.

        /// </summary>

        /// <typeparam name="T">Type of singleton instance</typeparam>

        public sealed class Singleton<T> where T : new()

        {

            Singleton() { }

 

            public static T Instance

            {

                get

                {

                    return Nested.instance;

                }

            }

 

            class Nested

            {

                // Explicit static constructor to tell C# compiler

                // not to mark type as beforefieldinit

                static Nested() { }

 

                internal static readonly T instance = new T();

            }

        }

 

The code for returning the instance then becomes:

        public static BlogSettings Instance

        {

            get

            {

                return Utils.Singleton<BlogSettings>.Instance;

            }

        }

You have to also change the constructor for BlogSettings to public to allow this this to work which does let devs shoot themselves in the foot (by ignoring the singleton)  and you of course have to balance the benefit agains that risk...

Changes afoot...change to BlogEngine.Net

This site currently runs on SubText but with my recent coding rebirth I'm looking to start playing with this site's platform a lot more; with this in mind I've decided to switch to blogengine.net; it's a .NET 2.0 based engine which has a lot of nice toys to play with as well as a really nice extensions model. So, there you go...SubText has been great (and I share an office with Phil the guy who maintains the project) but it's time to move to something which is easier to fiddle with. The only constraint I have is preserving the current link structure...I'm investigating various methods of doing this including using Phil's WebFormRouteHandler. I messed up to move to www.mostlylucid.net from www.mostlylucid.co.uk and I'd really like to prevent that happening again.

The state of the art...spelunking in the .NET Source

One of the nice things about being on the ASP.NET team is that I finally get to scratch the various itches (on that topic, Poison Oak...very itchy!) that have been bugging me for a few years. I finally get to play around with the source and see what effect changing various bits and bobs has on how stuff works.  I really do recommend spending some time spelunking in the .NET Source code. You can actually get this source (in a very non-official and non-supported way) using .NET Mass Downloader. This is just such an awesome resource...want to see how a server control like the Repeater works...look at the source! Trying to figure out why Viewstate behaves in a weird way...well, you get the idea. Right now you can get the source for these .NET 3.5 assemblies...that is a LOT of source!

Mscorlib.DLL
System.DLL
System.Data.DLL
System.Drawing.DLL
System.Web.DLL
System.Web.Extensions.DLL
System.Windows.Forms.DLL
System.XML.DLL
WPF (UIAutomation.DLL, System.Windows.DLL, System.Printing.DLL, System.Speech.DLL, WindowsBase.DLL, WindowsFormsIntegration.DLL, Presentation.DLL, some others)
Microsoft.VisualBasic.DLL

I don't know the official word on this yet but I'd be surprised if we don't continue adding to this list in future. From my team you can of course get the ASP.NET MVC source  already in Codeplex and we'll be adding even more projects to this site in the very near future...in fact we now operate a 'why can't we release the source policy'...

New and shiny...old and busted?

I had a comment on this blog the other day which I really got to thinking about following a discussion on a private list about how we market technologies. This is one area I'm really not qualified to talk about in any kind of 'semi-official' way but it's one of the things which bubbles under the surface of my day to day job.

It's a constant irritation working at MS...frankly some people hate us, with a passion. A fair number of the people I've talked to at work are confused by this...day to day we really do work hard to improve the working lives of the people who buy our software. But that's the thing, at it's heart MS is a business, it makes money by selling software...in the end it doesn't matter how user focused we are, if it doesn't shift boxes of Product X then it doesn't make it. The comment I was referring to earlier is an example of that dichotomy...yes, people still use VBScript based 'classic ASP', just as a huge number of people still use VB6 based windows applications and more recently WinForms apps. You wouldn't really think it though by looking at our marketing output...why? Simple, it doesn't sell new Windows licenses or Visual Studio 2008 SKUs...Microsoft is a business remember!
I'm not being down on Microsoft here (I choose to work there and I truly love the company!), it's a reality for every business and for software businesses especially. Book authors, consultants, trainers, almost everyone feeds off of the leading edge of new releases. The 'new and shiny' is where all the momentum exists, it's interesting to talk about and fun to learn. The issue (if there is one) is that just because a technology has become 'legacy' doesn't mean it's irrelevant. Some of the greatest programming books I have are for technologies I haven't written a line of code in for years. Nevertheless I spend time every year or so reading through those old books; as the saying goes 'Everything old is new again'

 

On the topic of books, just noticed this on the CodingHorror blog:Programmers Don't Read Books -- But You Should. I constantly find the lack of reading by developers a source of disdain...Jeff mentions four five (innumerate fool) books which are the absolute bare minimum you should read:

 

Code Complete 2 Don't Make Me Think Peopleware Pragmatic Programmer Facts and Fallacies

Hopefully I don't have to add this any more for anyone who has ever read more than a couple of posts on this blog...but it's called 'mostlylucid' for a reason! Nothing here unless I explicitly say otherwise reflects any opinion except my own (and even then, lack of sleep and extreme moodiness has an impact). You can think what you like about me but none of these comments is in any way attributable back to my employer.

I'm an old fuddy duddy and I like it...how to be a great coder by a mediocre one...

I was reading the excellent interview with Donald Knuth on InformIt and it led me to reflect on my own thoughts on programming. I learnt development under the gun...I wrote websites for a pure and simple reason, to make money for my employers. The best techniques to use when creating this software were those which led to the best result for my clients. Oh, sure I experimented with Patterns, read just about every book on coding and general techniques over the past 10 or so years and I've worked with some of the most inspiring designers, coders, scientists and business leaders I could find. With each project I worked on I tried to learn from my mistakes...I HATE making mistakes and it's led me to push myself...and frankly led my career far more than any conscious planning has.  
I'm not saying that I'm some cutting edge development mind...I'm not, if anything I'm an extreme pragmatist, in my personal and professional life practical is far more important than trendy. I moved between a few different programming languages over the years, following the technology to where it made sense for what I was trying to achieve. When I started out I was writing small security testing utilities which mainly ran on NT 3.5 Servers (and Windows 95 boxes). I didn't need a powerful OO based language and the quickest way to write this stuff was using Vi or EMACS with C or Perl...so that's what I did. The work I produced was utilitarian, pared down and quick...and frankly it paid well for the couple of years I wrote that stuff. I then moved to the web...at the time the 'best' technology for writing the type of site that I worked on was VBScript based 'classic' ASP...it was quick, had a nice development tool (for the time) and I developed techniques for making this stuff maintainable, decent in terms of performance (at the time we had about 20 fairly popular sites running on a Pentium 233MHz server with 128Mb of RAM). I wrote caching engines, 'made up' design patters and learnt how to get SQL Server 6.5 to work with my code to get decent performance.
Frankly I got lucky, I had no family commitments to worry about and was able to take risks with my career...for a while I 'job hopped' to companies which I thought were doing interesting stuff...my next stop was the hottest design company in Scotland at the time...which imploded about a year after I left. At BlackId, I worked with a great boss and got a chance to find out how to work with external customers....in the process boosting my confidence in programming. I was doing stuff that I thought was pretty mundane but it worked, was quick and I was still interested in what I was doing (a HUGE thing for me, I have a terrible habit of 'drifting' if I lose interest in the task at hand). Soon after that I got the opportunity to head to a startup...Globalfarmers. This company was led by a real entrepreneur who luckily for me saw the passion I had for the web...so in one day I doubled my salary and got to lead a multi-million pound development project. At Globalfarmers much of the development was contracted out to another company and frankly the company was led by a bunch of farmers...they needed someone who *got* the web and could keep up with the development cycle...apparently they thought that was me!
At this new company the system being developed was huge...at the time we were expecting to pay about $2 million just for the software and the hardware to run it on. The system was J2EE based, used some third party forum software and an Object Oriented DB backend. A big problem was that the development process was truly 'waterfall' based, like a train we just couldn't divert the main process to be responsive to the world the company was in...wanted a weather information system...tough, wanted a news publishing platform...tough. Long story (kind of) short, I had to learn a technology which would run on our new Sun machines, I'd gone from MS based websites using SQL Server to well, nothing. Into this world came PHP and Allaire Homesite...the right technology for the right problem. I wrote a bunch of software (this is also why i still think PHP is awesome...running little bits of software on HUGE servers makes it seem well, pretty fast!). At this time I was also learning a great lesson in recruiting from a very smart HR person Niamh Donnellan, hire passion. I had a junior role going, my first minion! We interviewed some very experienced people with great qualifications...but none of them had that spark...seemed like they would take the job and make it something special. Until I met Jarlath, a young Irish guy straight out of college...relatively little experience but smart and full of passion for the technology. I can't emphasize enough how much this changed my mind on recruiting...qualifications and experience are great for senior roles but when you really don't know what a job will become, hire passion.
Anyway, this post became something more than I originally intended...hopefully it's not TOO boring. The point which I'm aiming at was I think what Knuth was talking about...the 'latest thing' is fantastic, it builds passion and inflames hearts and minds...learn it, know it, but when it comes down to it you have to actually build something. This, for me is pragmatism all the great people I've met over the years have known this...learn everything you can but retain focus...always ask, 'can I use this', will it make what you're trying to achieve easier or more pleasurable or are you blinded by the 'new and shiny'.

Here's my parting words...being a great coder is not a job, it's a lifestyle. You have chosen to be an artist, you integrate a million different colors to build a picture...but you should decide what those colors are...do they help make the picture or are you just painting by numbers. All of these techniques, OOP, Extreme Programming, Patterns based development, TDD, BDD, DDD they're colors in your palate...in the end it's your picture, you decide how you paint it  because really no-one else can. (This strained metaphor brought to you by way of Paul Graham's excellent essay (and not so great book) Hackers and Painters)

My god it's full of stars!

I posted this stuff before but this is a new one which is just stunning...I wish I was this talented!


Weird Fishes: Arpeggi from flight404 on Vimeo. .

Experimenting with Twitter

 

Let's see how it goes!

How I lost 30lbs...and plan to lose 60 more. The Geek Diet

Before I write this I should add a disclaimer...this works 'for me', and for my particular lifestyle / psychology...

After Christmas and being ill way too often just because I was chronically unfit and weighed almost 300lbs I made a decision...that I would lose 100lbs.

Now, I didn't set a limit for *when* I'd do it by but the trajectory I was on should point in that direction. I started by looking at why I'd gotten to the point I was at...why had I put on so much weight and let it get as bad as it was. Well, I wasn't happy with my life in general, really wasn't sleeping more than a couple of hours a night, was getting stressed at work to a degree which wasn't healthy and did very little physical activity. Oh, and my diet sucked...I was living on fast food and Pizza.
So, what to do...first I needed to get my sleep sorted out..so off to the doctor. Got some Prozac and Ambien...again not for everyone but this vastly improved my life...I was sleeping and dealt with stress far better. This led to clearer focus during the day and just generally feeling better about myself. Should add that the sleeping pills were only temporary, got me back in a sleeping rythm and I use them very occasionally now to jerk me back into the pattern if I start drifting off again...you need sleep, it impacts everything else if you don't get it. The extra sleep and antidepressant also began to impact the rest of my day...danger of getting a bit psychological here....but it certainly improved my confidence and just led me to a more healthy mindset when dealing with problems.

Now, on to the diet...

My major problem is plain and simple impulse eating...get hungry, by a triple bacon cheeseburger meal...not good. So, plan was: prevent getting hungry.
Starts with: Breakfast

I did a lot of research with different options but what works for me is:

300mls Crystal Geyser water
1 Banana
1 handful of unsweetened Berry Medley (red berries, no strawberries)
3 tbsp Soy Milk Powder
2 Scoops Metabolic Reset Shake
1 tbsp Green Tea Powder

So, that's all blended into a shake...the Green Tea adds some caffeine to get me going in the morning as well as having some effect on appetite suppression. The Metabolic Reset shake is pretty cool stuff, high protein (again, suppresses hunger), contains viscofiber, good for digestions as well as adding bulk...fills you up. The whole shake is also low-GI (important as I have diabetes and don't want a high glucose spike, this is absorbed slowly).

Adding to that I also take a multivitamin pack, fish oil and soy lecithin. The Soy Lecithin is due to a slightly odd component of my diet:

Piracetam - I use a bulk powder and add 1tsp of it to 500ml of water with breakfast (tastes bitter but you get used to it). The main reason I use this nootropic is that it keeps my energy up during the day (without caffeine). I have researched this pretty intensively, and I can say that the side effects seem very limited...I do feel it improves my concentration when fatigued...but I include it here for reasons of disclosure rather than a recommendation! Oh, and my experience is that without Lecithin, I get a headache at the end of the day from this stuff.

Lastly I take a Breakfast Blend juice ('cos I like it)...

Excercise...walking...simple, easy. I try to do 10000 steps a day (buy a pedometer). It works for me, I snack during the day on these, and have a normal (i.e., cooked at home) evening meal. Well, it works for me...I sleep better and generally feel better on this regimen...