Raymond needs to be slapped everyday, for the rest of his life.

Posted by Monty on February 8th, 2012

I normally don’t do politics. Politics is bad. Like eating babies bad. But, this is a piss boiler. The Beeb ran an article called “Family life on benefits“. It talks about poor old Raymond (Not his real name), and his family of 7 children (plus a wife), they get £582.40 a week – or to put in other terms – £30k a year (after tax). Lets have a look at his story in detail. The majority of this story goes back to the whole “Benefits cap of £26k a year, how will people survive”. Here’s how they will survive.

  • “Raymond, a former educational software writer, has been jobless since 2001…Ray says: ‘The market for my skills dried up 10 years ago – there’s a total lack of work in my area of expertise.” – Oh really? Funny that, because I started software development professionally roughly when your “skills dried up” – so that’s a load of cobblers.
  • “I go out once a week, on a Friday night. I meet up with my mates in the pub and have three or four pints.” – I’m sorry, what? You’re going out, getting drunk, and hammered on our money? You dont have a job – you don’t deserve to go to the pub, and kill your liver.£20 A week saved
  • “We get the Sky Movies package because we’re stuck in the house all week – otherwise we wouldn’t have any entertainment” – GO OUT AND GET A FUCKING JOB. Why should I pay for YOU to sit at home and watch movies all day? £15 a week saved.
  • “Most of this goes on our eldest son’s bus fares to college and back. For me, if it’s less than five miles, I’ll walk.” – Buy your son a bike, he gets exercise, prolongs his life. £30 a week saved.
  • “My wife and I have mobile phones, and so do all of the teenage children. You try telling teenagers they’re going to have to do without their mobiles and there’ll be hell to pay” – Its called learning how to be a parent and telling your 8 year old child that they don’t NEED a mobile phone. £32 a week saved.
  • “Weekly shopping includes 24 cans of larger, 200 cigarettes and a large pouch of tobacco” – I’m sorry but this is the piss boiler. 24 cans of larger a week? 3 and a half pints of alcohol a day? 200 cigs? WHAT THE FUCK? YOU EXPECT ME TO PAY FOR YOU TO GET DRUNK? £70 a week saved now and hundreds of thousands saved in future, from having to replace a liver, cancer and early death.
  • “On the cigarettes, my wife tried to give up, but she missed one appointment on the course and they threw her off it.” – Why did she miss it? She’s unemployed. She has nothing else to do.

How much is that? £167 a week, or in other terms, £8,600 a year.

What I think the solution is? Raymond is required to, by law, to turn up at a special council facility, every day, for a minimum of 10 hours. During those 10 hours, he will be slapped repeatedly around the face. He will get a 20 minute toilet break, then the slapping will continue.

Que? No hablas

Posted by Monty on October 6th, 2010

So, let me get this straight.

You cannot delete this object because you will go and recreate it because of its associations?

Have you thought that maybe…

.. And I know this is a VERY crazy thought…

That I want to GET RID OF THIS RECORD and its Associations?

nHibernate sucks. It sucked 4 years ago when I used it, and it sucks bigtime now too.


public void ActuallyDeleteEmail(int emailId)
 {
 ISQLQuery sqlQuery = Session.CreateSQLQuery(string.Format('DELETE FROM [TABLE] WHERE ID={0}', emailId.ToString()));
 sqlQuery.ExecuteUpdate();
 }

OH! MY! GOD!

YOU CAN ACTUALLY DELETE THE RECORD? WHO KNEW?

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;

}

Comments considered harmful

Posted by Monty on May 10th, 2010

I often have this discussion with less learned members of staff, with regards to commenting code. The main argument is “Comment code so I can see what is going on!” and “If you don’t comment the code, I dont understand”. In the first instance, I recommend refactoring the code and rewriting it, so you do not NEED the comments, and usually (99.99%) with the second argument for commenting is, If you do not understand the code, should you really be touching it?

There is the 3rd style of commenting I sometimes come across, and that is the Newbie Comment. Typically, the code has been lifted from a coding website, and someone has left the comments in there, because they either dont know how to use their text editor, or they dont understand the code they are coping and pasting. Both of which, to me at least, indicate that the person should not be writing code and should spend more time understanding the framework and how things work in general, like the following:

//create file object
 FileInfo fi = new FileInfo(filePath);
 //read the file into a stream reader
 StreamReader sr = fi.OpenText();
 //store the contents in a string
 string emailBody = sr.ReadToEnd();
 sr.Close();

The most common comments I see are totally useless, and simply repeat what the line below will do, for example i++; //increment i. How is that comment at all useful? Its not, it just tells you what the line is doing, which the line itself should tell you. Its duplication of code, you are repeating yourself, which is violation of the DRY principle:

Don’t Repeat Yourself

From the wonderful book of The Progmatic Programmer. The comment adds nothing to the overall readability of the code, so it shouldnt be there, it is simply extra clutter to make things more difficult to read and maintain.

Making code easier to maintain, read

Posted by Monty on May 7th, 2010

Often, when working with someone else’s code, it works, but it isnt easy to maintain and read. Basically its ugly, and sometimes its like an ugly bag of snakes. Take this example:

Note: This code has been changed to protect the guilty.

[HandleError]
 public ActionResult LogOn(string username, string password, bool rememberMe)
 {
 string failureText = _websiteService.Login(username, password, rememberMe);
 if (!string.IsNullOrEmpty(failureText))
 {
 TempData["LoginFailure"] = failureText;
 return RedirectToAction("CheckoutAddress");
 }
 else
 Response.Redirect(Url.Action("CheckoutAddress", "Orders"));

 return View();
 }

Now, to me, this rings alarm bells, for multiple reasons. First off, you have failureText which claims to login, but actually gets you if it failed or not. Next thing you have is the “If there is no failure text, then it has worked”. Thirdly, you have the defunct return view, even though it shouldnt really be there.

How should this code be structured I hear you cry? Well, something like this:

[HandleError]
public ActionResult LogOn(string username, string password, bool rememberMe)
{
 if (AreCredentialsValid(username, password) && IsUserAllowedToLogin(username))
 {
 SetAuthenticationCookie(username,password);
 return RedirectToAction("CheckoutAddress");
 }
 else
 {
 ShowInvalidCredentialsPanel();
 return RedirectToAction("CheckoutAddress");
 }
}

Much more easier to read, much easier to maintain and modify, and no having to look for magic strings and just assuming someone can login because there wasnt an error.


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