This is NOT the way you write code

Posted by Monty on August 24th, 2010

Seriously. If I see ANYONE under my employment writing code like this, without a VERY GOOD REASON, I will look at getting rid of you for gross negligance, and possibly criminal acts, under the geneva convention.

    public static DataTable GetAll(String where)
    {

        // get a configured DbCommand object
        DbCommand comm = GenericDataAccess.CreateCommand();

        //define command type
        comm.CommandType = CommandType.StoredProcedure;

        // set the stored procedure name
        comm.CommandText = "GetAll";

        //Create new parameter
        DbParameter param = comm.CreateParameter();
        param.ParameterName = "@tableName";
        param.Value = _tableName;
        param.DbType = DbType.String;
        //Add param to command object
        comm.Parameters.Add(param);

        //Create new parameter
        param = comm.CreateParameter();
        param.ParameterName = "@where";
        param.Value = where;
        param.DbType = DbType.String;
        //Add param to command object
        comm.Parameters.Add(param);

        DataTable dt = new DataTable();
        dt = GenericDataAccess.ExecuteSelectCommand(comm);

        return dt;

    }

If your WHAT THE FUCK meter isnt going off already, wait till you see GetAll:

ALTER PROCEDURE [dbo].[GetAll]
	@tableName VARCHAR(50),
	@allRecords BIT = NULL,
	@where NVARCHAR(1024) = NULL
AS
BEGIN
	SET NOCOUNT ON;

	DECLARE @sql VARCHAR(200)

	IF @where IS NULL
	BEGIN
		-- Insert statements for procedure here
		IF @allRecords = 1
		BEGIN
			SET @sql = 'SELECT * FROM ' + @tableName
		END
		ELSE
		BEGIN
			SET @sql = 'SELECT * FROM ' + @tableName + ' WHERE disable = 0'
		END
	END
	ELSE
	BEGIN
		SET @sql = 'SELECT * FROM ' + @tableName + ' ' + @where
	END

	EXEC (@sql)
END

Seriously. DEAR GOD. HOW THE HELL DID YOU GET A JOB?

public static DataTable GetAll(String where)
{

// get a configured DbCommand object
DbCommand comm = GenericDataAccess.CreateCommand();

//define command type
comm.CommandType = CommandType.StoredProcedure;

// set the stored procedure name
comm.CommandText = "GetAll";

//Create new parameter
DbParameter param = comm.CreateParameter();
param.ParameterName = "@tableName";
param.Value = _tableName;
param.DbType = DbType.String;
//Add param to command object
comm.Parameters.Add(param);

//Create new parameter
param = comm.CreateParameter();
param.ParameterName = "@where";
param.Value = where;
param.DbType = DbType.String;
//Add param to command object
comm.Parameters.Add(param);

DataTable dt = new DataTable();
dt = GenericDataAccess.ExecuteSelectCommand(comm);

return dt;

}

Cognitive Bias, or Why you should get someone else to test your code

Posted by Monty on August 8th, 2010

This happens to be a frequent topic for discussion, where people either believe they shouldnt have to get someone else to test their code, or why they should get someone else, who isnt biased, to test their code.

I am a very strong believer in getting someone else to check my work. I am the one who written it, I know what its supposed to do, and I am biased in weather checking if it will work, or not. It is always better to get a second pair of eyes to check over something that you have written / implemented, just to make sure its working correctly. Im not the only one who likes to do this. Pharmacists HAVE to get someone else to check to see if they have dispensed the right prescription drug. Radiologists have to get a 2nd opinion to see if there is a fracture on a bone. In Air Traffic Control, there are computer systems, to make sure that two planes do not try to occupy the same space at the same time.

Take this phenomenon called Controlled Flight Into Terrain (CFIT). Its very interesting, and a bit gruesome. You take a perfectly good plane, fully working and fueled up, and you put a pilot into it, and he might fly it into the ground (or a mountain, or the sea, or an obstacle), in a controlled manor. According to Boeing, its one of the leading cause of airplane accidents and loss of life. This can be caused by a number of things, pilot disorentation, loss of situational awareness, minor problems manifesting themselfs.

Basically, the soft squishy human can be wrong. Two humans are less likely to be wrong than one, 3 more than 2, etc.

Get someone else to test your code. Seriously.


Copyright © 2007-2010 Muntedhar Alhakim. All rights reserved.