Saturday, May 27, 2006

New Blog

I really don't like blogger so I have decided to setup a blog on my own server (what else are web servers good for?). The new URL is:

http://blogs.solidhouse.com/david.woods/

As such all new posts will be found at the URL above

Friday, May 19, 2006

Vista takes 15GB?

I just ran the vista upgrade advisor (tells you if you have the requirements to run vista). and was shocked to get this error:

We're sorry, but your PC cannot currently install and run the core experiences of Windows Vista.

However, you may be able prepare your computer for Windows Vista by upgrading your PC hardware.

You will need to take the following actions to run Windows Vista.

Additional hard drive storage
15GB free space required (Your computer currently has 3.53 GB)
You will either need to:
a) upgrade your hard drive to increase its capacity, or
b) create additional free space on your existing drive by removing unwanted files.
If you decide to upgrade your hard drive, we recommend 40GB capacity at minimum for premium editions of Windows Vista. Contact your PC retailer to see if an upgrade is available.


Why in the world in an OS 15GB? How many DVD's is it comming on? Or better yet how many CD's for the non DVD people.

Wednesday, May 17, 2006

Backups are important

I think backups are usually the most poorely done thing in any organization. Even if you have a backup solution it is very rarely checked to ensure that it is working.

1. How often are backups verified / tested. If possible I recommend taking a system and restoring your backup to it and see if everyone can still work.

2. How old are your tapes? They don't last forever you know. I don't know the average life but I am guessing at 1-2 years depending on rotation.

3. Do you have a rotation (i.e. a tape for every day of the week)? If yesterday is corrupt then going back 2 days is not terrible

4. Are your backups stored offsite? If not, set your building on fire as an exercise and see how well you can recover.

5. Do you have a backup server? Replacement hardware can take time to install and configure. I recommend having a spare server on site that you can restore to (or better yet clone your data to it periodically and have a spare with all the data).

Backups are not just about computers.

Do you have a backup internet connection?

Do you have a backup air conditioner? (one of my clients had all their servers go down last night as the air conditioner crapped out).

Do you have backup power? Even if it is only 15 minutes that could be all the time you need to save your work

Do you have a backup backup opperator. If only one person knows how to backup / restore then just hope they don't get sick.

Do you have your servers off the floor? Floods and computers don't mix. I had a client whos air conditioners drain pipe (to drain away the condensation) break and flooded the server room. Thankfully the servers and power connections were off the floor.

If you are not confident that you could wipe all the computers in your organization and be back at work 100% in a quick period of time (1-2 days depending on size of organization) then its time to re examine your backup solution(s).

Tuesday, May 16, 2006

Starting an application as another user

Monday, May 15, 2006

My Toolbox

-FxCop. Great tool for keeping code consitant
-Nunit. Unit testing tool
-CopyAsHTML (great for blogging / documentation)
-DataSet Quick Watch (http://www.codeproject.com/csharp/DSWatch/DSWatchSetup.zip)
Great tool for seeing a dataset in a datagrid while debugging
-Firefox
FFox plugins
-IE Tab (opens a page that is only ie compatible within firefox)
-Sage (nice little newsreader)
-Web Developer (if you do work with the web get this... period)
-Adblocker

What we are doing wrong

I recently had a rant about us as developers not having a clue what we are doing. I want to try and narow this down into a few areas that I think need improvement.

1. Testing. We don't take a step back and look at different scenarios. Whenever I develop something it is to do a task and that is what I test. I never test a method to see how it react when different data then the scenario is added.

2. UI. I never make an application useable. Its not because I hate the user but that my emphasis is on functionality. We almost need to look at the interface as requiring the most functionality and designing a good clean interface that is user friendly. I need to start designing programs thinking that the end user is going to be my grandma or something like that.

3. Data. My applications are filled with garbage data. I need to find a better way to put realistic data into my applications. One thing to be carefull of is copying production data into development as this may violate privacy laws depending on where you live (seriously).

4. Load & Concurrency. I barely ever test my applications in high load situations nor do I test what would happen if two methods got run at the same time. I ran some tests on one application and was supprised at the number of deadlocks I got in the database (then again it might have been my testing tool)

5. Design. I really think most of us don't know how to design an application. We all have different views and opinions (or are lacking in this department). I think we need to start looking at all the different ways of doing things and start to reach a concensus.

6. Client Interaction. I find that the client is not involved enough and is upset when they don't get what they asked for. This is one reason I really like agile for having the client heavily involved in the development project.

7. Unit Testing. I have found this to be such a usefull tool / practice. Since I started using it I have found that the quality of my releases has been higher in that there are few if any regression bugs and I feel more confident making changes to existing code. I really think that if you have not tried having unit tests of some kind in an application that you should.

Friday, May 12, 2006

Why ,NET applications use so much memory

You may notice that even a small application seems to consume a lot of memory on your system. I am strating to think that this is because the runtime reserves two 16mb segments for the small and large object heaps. I assume that you don't often see it as 32mb segments in task manager as a lot of it will be unused and paged to disk. Its just a theory though :)

Wednesday, May 10, 2006

Permission generation script

Here is a hany security script that will generate the grant execute / select /delete permissions on all objects in your database if you have the need to do so:



Declare @RevokeSQL varchar(1000)
Declare @GrantSQL varchar(1000)
declare @EveryoneRoleName varchar(30)

set @EveryoneRoleName='Public'

set nocount on

select P.ID, U.Name as UserName, o.name as ObjectName,
case P.ProtectType
when 204 then 'GRANT_W_GRANT'
when 205 then 'GRANT'
when 206 then 'REVOKE'
end as ProtectType,
case p.action
when 26 then 'REFERENCES'
when 178 then 'CREATE FUNCTION'
when 193 then 'SELECT'
when 195 then 'INSERT'
when 196 then 'DELETE'
when 197 then 'UPDATE'
when 198 then 'CREATE TABLE'
when 203 then 'CREATE DATABASE'
when 207 then 'CREATE VIEW'
when 222 then 'CREATE PROCEDURE'
when 224 then 'EXECUTE'
when 228 then 'BACKUP DATABASE'
when 233 then 'CREATE DEFAULT'
when 235 then 'BACKUP LOG'
when 236 then 'CREATE RULE'
end as PermissionGranted
into #Temp
from sysprotects P
inner join sysusers U on P.UID = U.UID
inner join sysobjects O on P.ID=O.ID where
P.uid=0 and o.Type<>'S' and
(O.Name not like 'sync%'
and O.Name not like 'sys%'
and O.Name not like 'dt_%')
-- just added the funky syntax for o.name filters
order by UserName, ObjectName

DECLARE cur CURSOR
READ_ONLY
FOR Select UserName, PermissionGranted, ObjectName from #Temp

DECLARE @name varchar(40)
DECLARE @ProtectType varchar(100)
DECLARE @ObjectName varchar(100)
OPEN cur

FETCH NEXT FROM cur INTO @name, @ProtectType, @ObjectName
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
--create has a slightly different syntax, so we have to branch
--here
if @ProtectType like 'Create%'
begin
set @GrantSQL ='Grant ' + @ProtectType + ' to ' + @EveryoneRoleName
print @GrantSQL
-- exec(@GrantSQL)
-- set @RevokeSQL ='Revoke ' + @ProtectType + ' on [' + @ObjectName + '] from ' + @Name
-- print @RevokeSQL
--exec(@RevokeSQL)
end
else
begin
set @GrantSQL ='Grant ' + @ProtectType + ' on [' + @ObjectName + '] to ' + @EveryoneRoleName
print @GrantSQL
-- exec(@GrantSQL)

end
END
FETCH NEXT FROM cur INTO @name, @ProtectType, @ObjectName
END

CLOSE cur
DEALLOCATE cur

--clean up the working table
drop table #Temp

set nocount off

SQL: Dynamic SQL Avoidance

I have several stored procs that take a flag that tells them wether to show expired records or not and usually looks something like this:


DECLARE @ShowExpired tinyint
SET @ShowExpired = 1

declare @sql varchar(1000)
set @sql = 'SELECT * FROM TABLE'
IF @ShowExpired = 1
set @sql = @sql + ' WHERE eff_end_dt is NULL"
execute (@sql)



While this works fine if I loose the advantages of stored procs and if I rename a table and recreate the procedure (I periodically recreate all procedures to test this) then I will not see any error.

Instead I came up with this:


DECLARE @ShowExpired tinyint
SET @ShowExpired = 1

select * from Table
where ((@ShowExpired=1) or (@ShowExpired=0 and eff_end_dt is null))

basically all the is happening if @ShowExpired=1 then everything gets returned. But if @ShowExpired=0 then only records that have a null end date are returned.

Tuesday, May 09, 2006

SQL Coding standards

Interesting Article

http://blogs.msdn.com/oldnewthing/archive/2006/05/09/593605.aspx

Monday, May 08, 2006

Refactoring an enterprise application

I am in the process of refactoring a fair sized com application that is consumed by many other applications. When the system was designed all data between the com system and the clients was via a dataset interface. This has caused lots of issues with naming, required fields, etc. so here is my plan to refactor it out while still preserving client compatability

1. As I do work create objects that are representitive of the entities being passed in
2. Create transformer objects that change the method from a dataset to an object and back again (testing this thoroughly of course)
3. Change the Data layer to use these new objects.
4. Migrate this up to the business layer (this is the layer that is exposed to the clients)
5. Take the incomming dataset and apply the transformer to create the objects
6. Expose the newobjects as overloaded methods that new clients can now consume
7. Depricate the old dataset methods and eventually remove them

I think it will work. I will let you know if it does in about... 2 years :)

Saturday, May 06, 2006

Daves 9 rules of business

Here are a few of my rules for business. Some of these don't apply to programmers but they are observations I wanted to share.

1. Business certificates can make a lot of money.
-For one they are usually gifts to people and either the receiver will not have a use for the item
or else they will loose it. I have no stats to back this up the number of unused gift certs out there must be high.
-The only issue is the cost of implemeting a gift cert program. If the costs are minimal then go for it

2. If a customer is unhappy do whatever you can to make them happy

3. If a customer wants to leave and you can not make them happy then do everything you can to get rid of them. If you drag your heals on releasing them from something then they will complain louder and louder to not only you but their friends and clients giving you a bad name.

4. If a customer is constantly unhappy or trying to devalue your service, get rid of them. Clients that are a pain cost more money and take away time from keeping your good customers and developing new ones. Also the stress applied to you and your staff from negative clients is a real downer. My rule of thumb is if you do not pick up the phone due to the number on the call display get rid of them.

5. Charge what it is worth. I have cut my prices for friends and companies that are tight on cash and have always resented it. If they want a quality project then they should pay for it. This is why the term is called cutting your own throat and it is sooo acurate.

6. The first person to a market with a new idea will always succeed. If you come in second with an idea then no one will know about you. This is why mcdonalds, IBM, coca-cola are so well know and have the best sales even though their markets are ripe with competition. I have no idea why this phenomenon occurs only that everywhere I look it seems to be true. Basically what I am saying is that if you are copying someone else you can never expect to usurp them.

7. If you are working more than 8 hours a day to make ends meet you are not charging enough. Eventually you will burn out and get behind. Start charging more. If you only get one contract at double the price of 2 you will work fewer hours and soon be able to bring on more staff.

8. Good management knows what is going on. If you have employees keep in touch with what is going on. Even more so get to know them. Have them out for a beer after work. If an employee likes there manager they will be happier, not complain about money, and have greater job satisfaction. This is a key to employee retainment.

9. Don't lie to your client to make them happy. If you tell your customer a project will be done in a week and takes a month they will be upset. If you tell them it will take two months and you have it done in a month then they will be happy they got it so early. If you tell them it will take four months and it is done in one then they will feel that you charged them for four months of work but only did one. Lies seem to compound themselves until finally you have to come clean with your client. If you tell them bad news as soon as you can they will probably be a little upset but at least aware. If you tell them their project failed because of something you discovered 6 months ago you are going to loose a client.

10.

Wednesday, May 03, 2006

ASP.NET validators and other browsers

I developed a little app last night that used the builtin ASP.NET validators. Now that I am running firefox as my default browser I have discovered that the validators client script does not work in anything other than IE. The reason for this is that the BaseValidator class (all validation controls derive from this class) have methods the emit javascript to do the validation. This script also contains an array of validator controls and summaries that looks like this:

var Page_ValidationSummaries = new Array(document.all["ValidationSummary1"]);
var Page_Validators = new Array(document.all["RequiredFieldValidator1"], document.all["RequiredFieldValidator2"], document.all["RequiredFieldValidator3"], document.all["RequiredFieldValidator4"], document.all["RegularExpressionValidator1"], document.all["RequiredFieldValidator5"]);

And therin lies the problem. Only IE uses document.all every other browser I know off does not recognize document.all. Instead what should have been used is document.getElementById to get the controls.

There are two ways I see to fix this. The first is to just download a replacement validator suite like this free one. I have not tried it (so I appreciate some feedback if you do). Instead I am going to do things the hard way and fix the javascript issues by creating a class that emits compatable javascript for all browsers. I do it the hard way so that I can better understand what is going on internally and seems to help me build better solutions.

Update. It is now 9pm and I am frustrated. I have made a ton of progress towards this goal but am having issues with the runtime not wanting to run my override (I assume this is because it thinks firefox can only do html 3.2 not 4.0 like the all mighty IE). I am going to leave this for a while and get some beer therapy and maybe try more tommorow. I will post the code once I get a solution figured out.

Paradigm Shift

I like to post on technical things but the state of the industry has really been getting to me so I thought I would right a post about it.

In summary: Most of us have no clue what we are doing.

I say this because of my experiences in the past year. I can teach anyone to code. Its really not that hard to do the basics but to make a large application is where people stumble (myself included). The reasons for this is that there is no set way to do things. Everyone has their own way and this is harmfull. What if every engineer had their own way to do foundation. We would need tons of unique tools for that foundation, tons of training for the people pouring the foundation, and tons of money as every process is unique. I think that this is what happening in our industry.

Over the past while of reading books like Refactoring and Patters Of Enterprise Application Architecture by Martin Fowler, talking with developers, watching webcasts. I see a whole new way to develop and I have been programming professionaly for the last 5 years.

As I start using some of these amazing techniques I can't be saddend to know that most developers out there have no clue about these. I have shown the model view presenter pattern to a fiew developers and they are blown away. I personally can not stop using it (I built a simple contact submittion form last night using it just because I like it so much). Interface driven development is the best thing I have started using lately and is a great way to allow decoupling of contract and implementation. Honestly I feel like I am seeing how to program for the first time since I did basic on my apple II.

This is a new and rapidly changing field. Historically look at being a gunsmith. It starts that everyone has their own way to manufacture a firearm from raw materials and it is pretty much how everyone else is doing it but its slow (i.e. coding in a basic language) . Then some technology comes out like a metal lathe (i.e. .NET) and now we can build things in our own custom way but faster. We have hit the point in the industry that any developer can build something small quite quickly and reliably but when we need to work togeather or build a large application most of us are in the dark.

What we need to do is follow the guns and use the concept of interchangeable parts and starting to look at how to make our projects work better with other developers and other projects. Unfortunately I don't know how to do this other than having us educate each other and share more in the community of doing things in better ways.