As a fan of FxCop I was interested to find out what this had to offer and so ran it on some new code that Bruce and I have been working on for a Madgex ILP project
Running StyleCop
I ran it against one (already FxCop'd) file, and came up with the following deviations from the rules (displayed in a new "Source analysis" window): SA1101: The call to m_source must begin with the 'this.' prefix to indicate that the item is a member of the class. SA1200: All using directives must be placed inside of the namespace SA1308: Variable names must not start with 'm_' SA1502: The constructor must not be place on a single line. The opening and closing curly brackets must each be placed on their own line. SA1600: The class must have a documentation header. SA1600: The constructor must have a documentation header. SA1600: The field must have a documentation header. SA1600: The property must have a documentation header. SA1633: The file has no header, the header Xml is invalid, or the header is not located at the top of the file.
SA1101 and SA1308 go hand in hand to my mind. We use m_ to indicate that the item is a class level field, and is the underlying element for a property. Using "this." instead also shows that this is what is happening. So, I don't have a problem with this at all.
SA1200 is a weird one, this differs from the templates and almost all sample code I've seen on MSDN etc. There have been quite a few blog posts about this.
SA1502 is only ususally done within our code when inheriting the constructor from the base class or this class, i.e. either public NewClass(string name) : base(name) {} or public NewClass(string name, string description) { this.myName = name; this.myDescription = description; } public NewClass(string name) : this(name, null) {}
Changing {} to be { } makes little difference and may improve readability.
All the variations of SA1600 are fine - documentation is useful, and using the summary sections is as good a way as any. I did get some subsequent warnings when I only used a one word description SA1630: The documentation text within the summary tag does not contain any white space between words, indicating that it most likely does not follow a proper grammatical structure required for documentation text. or a very short description SA1632: The documentation text within the summary tag must be at least 10 characters in length. Documentation failing to meet this guidelines most likely does not follow a proper grammatical structure required for documentation text.
SA1633 is tricky, there is some documentation explaining the rules that a file header must adhere to, which indicates that the minimum file header must be: //<copyright file="Widget.cs" company="Sprocket Enterprises"> // Copyright (c) Sprocket Enterprises. All rights reserved. // </copyright> This is probably the rule I dislike the most. I don't have a problem with file headers, but I don't think that the style of those headers should be enforced. Also, not all code actually is done via a Company - it could be personal code, in which case author would be more appropriate.
Changing the settings
There is a settings editor which is included in the Program Files folder, which can be started from the command line as: C:\Program Files\Microsoft Source Analysis Tool for C#>SourceAnalysisSettingsEditor Settings.SourceAnalysis where Settings.SourceAnalysis is the predefined file created/installed as part of the installation process.
This editor allows settings to be altered/changed to provide additional or more appropriate checks. Rules can be switched off - so I can prevent SA1633 from being reported to me. Company information and copyright text can be added so that the Header checking verifies against known and predefined information.
The settings editor can also be accessed from with the Visual Studio IDE by right-clicking on the project and selecting the menu option "Source Analysis Settings". This then created project level settings which is useful when wanting to change the settings on a project by project basis. To my mind, I'd rather set it on a machine level, and use the same settings across all of my projects - my use of a tool like this would be to ensure consistent styling, and changing the settings on a per project level stops this. There is an element of merging that can be acheived, by selecting the "Settings File" tab in the editor but how this works in practice I haven't, as yet, had chance to investigate.
Searching for 'special' characters in a database using TSQL
One of my colleagues asked me for some quick SQL help earlier. Some data in the database he was looking at had ended up with a 'special character' on the end of it in a specific table. This didn't affect all rows, just some, but he needed helping identify those rows.
For the sake of arguments, lets imagine that the table was called Item, and the affected column was named Name, and there was also an Id column named ItemId. He knew one of the affected Items, and so we examined the data to determine what character it was at the end. To do this we did
SELECT ASCII(SUBSTRING(Name,10,1)) FROM Item WHERE ItemId = 100
This informed us that the character was actually ASCII value 160. Knowing this, I then used the PATINDEX function and produced a query like:
SELECT * FROM Item WHERE PATINDEX('%' + CHAR(160) + '%',Name) > 0
which seemed to return the row that he'd already identified along with new ones. This is probably not the most performant method, but this was needed to check something in a debugging/support environment and not code that would be run on a regular basis.
I was using the FXCopAddin for VS2005 but I couldn't get it to work for VS2008. The FXCopAddin didn't seem to have been updated for quite some time, and so I didn't have high hopes of it becoming compatible anytime soon. I really liked the integration that the AddIn gave me, the fact that my warnings were shown in the standard VS error window etc, so I wanted to find a similar, alternative solution.
I started with working out the command line version of what I was trying to do - "C:\Program Files\Microsoft FxCop 1.36\FxCopCmd.exe" /c /f:"C:\Working\MyTestApp.exe" /r:"C:\Program Files\Microsoft FxCop 1.36\Rules" /consolexsl:"C:\Program Files\Microsoft FxCop 1.36\Xml\VSConsoleOutput.xsl"
Which is, basically, call FXCop (version 1.36) using the Rules dlls specified in "C:\Program Files\Microsoft FxCop 1.36\Rules", and use the XSL file in "C:\Program Files\Microsoft FxCop 1.36\Xml\VSConsoleOutput.xsl" to formulate the output.
Moving on from this, I put this working command line into the Post-build event command line as: "C:\Program Files\Microsoft FxCop 1.36\FxCopCmd.exe" /c /f:"$(TargetPath)" /r:"C:\Program Files\Microsoft FxCop 1.36\Rules" /consolexsl:"C:\Program Files\Microsoft FxCop 1.36\Xml\VSConsoleOutput.xsl"
Where $(TargetPath) gets equated to the generated dll/exe etc in the build process.
Behind the scenes, this gets recorded in the .csproj file as: <PropertyGroup> <PostBuildEvent>"C:\Program Files\Microsoft FxCop 1.36\FxCopCmd.exe" /c /f:"$(TargetPath)" /r:"C:\Program Files\Microsoft FxCop 1.36\Rules" /consolexsl:"C:\Program Files\Microsoft FxCop 1.36\Xml\VSConsoleOutput.xsl"</PostBuildEvent> </PropertyGroup>
And bingo, the errors get reported into the warnings window. From here they are clickable etc.
No sooner had Mike Gunderloyfinished posting The Daily Grind, a daily round-up of all that was new and good in the (mostly) .NET arena but also touching on other software development related material, than Chris Alcock took over with The Morning Brew. He produced the 100th installment last week, so Well done Chris. This is one of my must read blogs, and I always find it is full of helpful, useful and informative links - including one to this blog
So, to summarise the previous posts and to reference the ones I haven't gone into more detail on, here's the list of talks from top to bottom (I hope!):
Alex Haw talking about Spatial Control - and methods for losing it (a very fast talk - would like to see it again but slowed down to a more sedate pace)
Simon Daniel talking about Moixa Energy's rechargable USBCELL batteries - it was part product pitch and part background information - 15 billion batteries are thrown away each year. He had an interesting quote "People won't buy things just because they're green but will buy them because they are better". The UK currently recycles only 1.5% of batteries - that is a lot of landfill.
Gavin Starks talking about the AMEE product. Consumed by services like carbonaccount and dopplr, Sounds good, might have to try and think of something to use the APIs at some point - maybe the next Madgex Hackday if I can think of a tenuous link to job boards
Vincenzo Dimaria from Central Saint Martins talking about "Design made in Sicily: a change of perspective" all about tomatoes
Edward Scotcher who mainly told stories about communication, one about the Fashoda Incident (about which I knew nothing) and others about the more current political situations in Kenya and Zimbabwe. One of his comments was "Are we bold enough to contribute without wanting fame and fortune?" His slides are available here.
Bryony Worthington from Sandbag who talked about emissions trading, and the permit system and how it isn't a good method for curbing emissions. This was the most political (small p, not big p), socio-economic talk and was a contrast to some of the more fluffy, or product based talks
James Smith talked about "Can software save the world?" - more specifically two projects he's been involved with from a technical perspective - The Carbon Diet and Do the Green thing (a site which I stumbled across a couple of months ago).
Jeremy Gould and Mitch Sava talked about using "Government Barcamp and Resolution (of the online kind)" which was about how the government is evolving to make use of technology - like e-Petitions, the no 10 twitter
David Wilcox presented a video from Steve Moore all about 2gether08 which is a festival "to explore how digital technologies can bring us major social benefits".
And that was that, a long day, really interesting, lots to take on board and think about.
Some notes I made about slides - the quality of which varied throughout the day:
put any text on the top of the slides so everyone can see it - some slides had key text at the bottom left-hand corner of the slides, which I couldn't see clearly. So a statistic that was supposed to be 95% of something-or-other actually read 5% to me - quite a different message
always put up a slide with contact details - name, email address, web site - possibly both at the start and end of the talk. Some of the names of the speakers were mentioned so infrequently, and quickly, that I didn't get them noted down properly and have had to do some guessing.
This was of real personal interest as many months ago Jeremypownced me a link to Ben Saunders web site to follow the progress of his attempt on the speed record of a solo trek to the North Pole. I've always had a fascination in arctic exploration and adventures so this was immediately added to my RSS feed. Unfortunately, he had equipment failure and some dreadful conditions and so "After 8 days on the ice and at a position of N.83.57.686 W. 074.12.566 Ben Saunders' expedition to become the fastest man to walk solo and unsupported to the North Pole is over following the critical failure of his ski equipment."
His talk was excellent, polished and high standard as you would expect from someone who does a lot of fund raising and probably quite a few after dinner talks. He also had the only picture of a polar bear during the whole day! It wasn't just pretty pictures though, he showed us imagery of the ice thaw over the last few years, and also some photos of what the surface looked like after being broken apart so much. This photo: gives just a small indication of the height of some of the obstacles.
His next trip will be to the South Pole when he will attempt the first return journey to the south pole on foot "SOUTH will be the first return journey to the South Pole on foot, and the longest unsupported (human-powered) polar journey in history". He is due to leave in Autumn, so no doubt I'll be following his process again.
One of the two product based talks last Saturday at geekyoto was DIY Kyoto. The key product is Wattson a well designed item which glows with a different colour according to how much electricity you're using, and also shows the electricity usage in either watts or price (you can set your own price). It is based in London, and made in London too.
There is also an associate tool, Holmes which provides a web-based view of your data - Wattson stores 28 days internally and Holmes that to be visualised.
I had a brief chat with Greta Corke (pictured) during a break and it sounded like a more fun (and prettier) version than some of the other similar functioning units. There's a video from Designers Block 2006 here.
Then yesterday afternoon, I was doing some bug fixing on some ugly, ugly code and wondered what my "arousal level" would be as per Christian's maps. I thought it would probably be in the zone of high arousal implying stress, and wondered if mapping the code emotionally would be a good way of working out which areas to concentrate on when re-factoring and reworking. I'm not sure how practical it would be to operate as rarely does one sit down and read code.
Two students from Central Saint Martins did half-length presentations, and the second of these was Bruno Taylor on play.
One of his statements was along the lines that "71% of adults used to play outside when they were young, only 21% of children do now". He also showed some photographs of areas that had been "vandalised" by young people playing on objects that looked like they should have been designed for play, in an area with no real play facilities.
He'd installed a swing into a bus stop to enable play in that environment which looks like a fun idea.
Adrian Hon and Naomi Alderman talking about the idea of a secular sabbath. Naomi is from a jewish background, and in the world of the Orthodox jews what can be done on the Sabbath is quite restricted. This includes turning electrical devices on or off during the period - so a water reboiler tends to be used to cope with the need for a cup of tea, and timer switches are used for lighting.
The list of things that can be done, as seen in the slide above, are all rather pleasant sounding. One of the key points was that "behavioural changes don't need to be sacrificial" but that the concept of a day of rest has pretty much vanished - you can go shopping, read emails, work, etc pretty much 24 hours a day, 7 days a week.
So, how about every now and again having an off-line day - no internet, no mobile phone, no landline phone - spend the day with friends, eating good food, enjoying good conversation? Give the car a rest, and walk around - slow down, de-stress.
Sounds like a pleasant change to me, I might just have to book one in.
My laptop went in for repair last week, and whilst it was there having its power cable replaced (internal burning) and screen replaced (deal pixels) I upgrade its hard-drive to be a nice and healthy 120GB. I didn't copy any data across, and after a few hours of re-installs I'm pretty much there, with much thanks to having listed my most used applications on iusethis.
That leaves the firefox extensions though, so I thought I'd list my most used ones here as a record for myself:
HTML Validator [it's great when your web page gets that green tick!], Link Checker [easy to scan the whole page for invalid links, useful if you run a directory website like me], and Web Developer are some of my faves.
The first speaker at Saturday's Geekyoto was Christian Nold who was mainly talking about emotional mapping. He mentioned some work he's done with communities and groups to map emotional responses to areas. This photo is part of the San Francisco emotion map. Participants are given handheld machines which monitor sweat levels (similar mechanism to lie detectors) to determine the emotional state of the person who additionally annotates their thoughts.
An interesting first talk, and some beautiful maps amongst his slides:
On Saturday I attended the geekyoto conference. The subject was "Fixing The Broken World" and we had 15 different speakers during the day covering topics from politics, products, mapping through to playing. A really enjoyable and thought provoking day.
I'll post some more thoughts and reflections as the week progresses, but in the meantime here are some photos.
TSQL - How to get the date element of a datetime object
In SQL Server 2000 and 2005 there is no concept of a DATE data type, only a DATETIME. So, how do you get the DATE element only, i.e. with a 00:00 time element. One of my colleagues needed to do this, so after a bit of google searching he discovered the following.
-- Get today's date without the time element SELECT CONVERT(DATETIME,FLOOR(CONVERT(FLOAT,GETDATE())))
I would probably have done it via a CONVERT/CAST operation, converting to a VARCHAR and then back to a DATETIME, but this is a much more efficient method.
In SQL Server 2008 there is a DATE data type so this will no longer be an issue.