Fremus.co.za

Demistifying Life and Web Development

Being a designer does not make you a web designer

You know the types that studied some art or DTP related course at college, yes those! They assume that they automatically qualify as web designers by default because their so called artistic decree allows them to. Wake up please and smell the pot of sour paint – if you don’t know what HTML stands for as a start then you are NOT qualified to put web design in a sentence, let alone assume that you are.

I have worked with at least two DTP designers who assumed they were web designers by default and strangely all of them have the same attitude – a total disconnect from the semantics of the web having an interest in their Photoshop world only. I mean please, designing for the web and designing for DTP require different mindsets and different understanding. Firstly the web has design constraints that cannot be ignored, unlike DTP which seems to only be limited to the size of the document. I associate DTP with heavy weight graphics, deep and dark colours whereas designing for the web is lighter in terms of graphics.

I also find that some graphic designers will force a design onto the information and not let the information determine the flow of the interface. I prefer information to flow naturally, without design impedance.

Just a rant I wanted to express.

  • Share/Bookmark
posted by fr3dr1k in General and have No Comments

How do you manage your time?

A couple of truths have come to bare themselves to me over the last 6 months or so, and its time to face up and be all grown up about it. Firstly, a day really is only so long, there is no infinite time in a single day and working more after hours certainly doesn’t make the time extend beyond the usual. Thus it is crucial that you effectively plan tasks and deliver on them. I have started with a small activity at work, which seems to kind of work, by making a list of 10 objectives/work items and marking them [done] as I complete them. After that I then do another 10 and so on. The thing with this approach though is that I often find myself not giving myself room to review what I have done. Reviewing your work is as important as doing it, so where is the correct balance? I wonder.

We need structure in our day because without it we might panic and do things like madmen.

  • Share/Bookmark
posted by fr3dr1k in General and have No Comments

Better is relative

Linux is better than Windows, Ruby on Rails is better than ASP.NET MVC, PHP is better than ASP.NET, Google Docs is better than Microsoft Office. Yada yada. Its all relative to the individual – thats my guess, simply because better in your perspective is not better for me and vice versa. Even though I have vain ambitions to learn Ruby or Python, I currently know C# and saying to me that I can do things faster and quicker with the latter seems like a rather pointless argument. Theoretically speaking I should be able to learn either Ruby or Python quickly but my general feeling is that both are best suited for running on Linux/Unix systems and honestly it seems kinda pointless trying to do development in a Windows environment with either because you already have .NET available. I really don’t take PHP developers who develop on Windows seriously. Why? Because its a contradiction in my book.

  • Share/Bookmark
posted by fr3dr1k in General and have Comment (1)

The problem with commercial CRM’s

The tendency for open source CRM packages is to become commercial – this is a fact that nobody can deny. The reason is understandable because an open source product cannot financially stable if its completely “free”. CRM packages are complex pieces of software that do all kinds of weird and wonderful things such as managing your interactions with your customers and most importantly saving those interactions giving you a history. CRM packages are also useful because you can tie it in with a commercial product offering that creates one or product catalogues and allows you to interact with your customers by sending them detailed product information or by running promotions.

Before I dive into why commercial CRM packages are problematic I think I should define a CRM a bit further, not from a wiki definition but my own, because its my perception of a CRM that shapes my idea of what it is and what problem it solves. A CRM package really comes down to one thing, the value you place in your customers and the length you will go to in keeping your relationship professional. By professional I mean by not making an idiot out of yourself because you forgot about the topic of a previous conversation. In essence that is what I think a CRM is supposed to help with, help build rapport with customers – not do. The do part is up to you.

Windows based CRM solutions are a world of pain on several levels not the least of which is the fact that you will have to spend loads of $$$ in buying software that is needed apart from just the CRM. Microsoft Dynamics CRM requires SQL Server and Windows Server, and if you simply think in terms of licensing per user the costs quickly add up. Sure, the product itself might be awesome but if you think about it a CRM will require time and resources for setting it up and keeping it up and running. I can only imagine what the installation process for dynamics CRM will be and the time it will take. In fact you will also need training – which will not be free. All the other commercial CRM makers do this, especially those that run on a MS technology stack. Its a greedy money making business nothing else really.

Yesterday I asked our IS manager if Sage CRM can provide us with a demo or test environment for the CRM and guess what we have to pay for it, even if we have already bought a license for it. How am I suppose to develop against a product that gets shipped to us and gets installed in a production state? There is no room for testing against it, to do business specific things like workflows and integrate product data. Whats the point if you cannot take the existing CRM and mould it a little and customise it. Instead you get stuck with a huge bill to pay for training and installations.

  • Share/Bookmark
posted by fr3dr1k in General and have No Comments
Tags:

Dealing with Circular References in EF4/JSON

I like the many-to-many mapping EF4 provides you simply because it allows such great navigation between entities and its easy to shape the query from one side to other and vice verse. The only issue is that it causes issues with JSON serialization, because the serializer does not know how to handle circular references, it can only serialize one way. Initially I dealt with this issue by creating “view classes” but it seemed rather tedious and pointless, so instead I started using the enumerable Select() method. It provides a very easy way to construct “anonymous objects”. So in my controller I would have a JSON Result and I would do something like this:

Json(courses.Courses.Select(t => new { CourseTitle = t.CourseTitle, CourseCode = t.CourseCode, CourseId = t.Id }));

Pretty damn neat, considering that Courses is a EF4 entity and I dont have to go and change or adapt it to play nicely with the JSON serializer.

  • Share/Bookmark
posted by fr3dr1k in C#,Web Development and have No Comments
Tags: ,

Why devs must support their own machines

One of my recent annoyances comes from IT support providing a developer, like me, with a laptop pre-installed with all the corporate mumbo jumbo. And in my case they do the installation using ghost images or ghost installations, so the OS is not really configured for the hardware of your particular machine, which in some cases results in messages appearing on-screen relating to graphics drivers crashing. Thats my opinion anyway. IT support also generally also install whatever anti-virus whether its any good or not, which in most cases slows the machine down. I have also had software installed on my machine that affects localhost on IIS for some reason, which I cannot use for development when I am connected to the network, but when I disconnect I can. I have no idea which piece of software is causing this, and I can think of one particular piece of software that could be causing this. Personally I would prefer installing Windows 7 from the start at some point, with the appropriate and correct device drivers.

In my opinion devs should be allowed to take total ownership of their dev machine which includes OS maintenance and installation. In this way they are totally accountable for any problems that may occur and you will find that most devs need to know what the OS can do and what not, so its best for them to take ownership. My current machine has 8GB of RAM and has a core i7 processor but it does not feel that quick in some cases, but maybe thats just me.

  • Share/Bookmark
posted by fr3dr1k in General and have No Comments

HOWTO: Check all items, and get all checked items

I often find myself re-using code, in the bad way (copying and pasting) without really remembering how it was done, and this is particularly true for JavaScript. I could easily say that I do most of my JavaScript with jQuery, so here is a function that enables all checkboxes with a given name:

var general = {
    selectAllEntities: function (chkBoxName, checked) {
        $('input[name=' + chkBoxName + ']').each(function () {
            $(this).attr("checked", checked);
        });
    },
    getAllCheckedEntities: function (chkBoxName) {
        var entityValues = [];
        $('input[name=' + chkBoxName + ']').each(function () {
            if ($(this).attr("checked")) {
                entityValues.push($(this).val());
            }
        });
        return entityValues;
    }
};

jQuery makes it easier with its $ selector, so if I had to write this without jQuery the code might be significantly longer.

  • Share/Bookmark
posted by fr3dr1k in jQuery and have No Comments
Tags:

Paging for ASP.NET MVC

I bought Steve Sanderson’s book Pro ASP.NET MVC about 6 months ago and I must admit its a real winner for the single reason that the code and explanations are clear and to the point, and he actually gives you code you can use easily. In chapter 4 he builds a paging helper class which is really cool and works well when you bind the model to your view but the way he implements it could be made better by creating a class that accepts a generic type and I also want to use this method for Ajax/jQuery. The code in his book for the PagingInfo class looks like this:

public class PagingInfo
{
	public int TotalItems { get; set; }
	public int ItemsPerPage { get; set; }
	public int CurrentPage { get; set; }
	public int TotalPages
	{
		get
		{
			return (int)Math.Ceiling(decimal)TotalItems / ItemsPerPage;
		};
	}
}

In the controller in his book he then creates a class called, ProductsListViewModel, which has two properties, IList Products and PagingInfo PagingInfo:

public class ProductsListViewModel
{
	public IList
 Products { get; set; }
	public PagingInfo PagingInfo { get; set; }
}

On a side note I must say I agree in part with Jeffrey Richter in his book C# via CLR that properties are a weird mix of a method and not a method and sometimes it does feel as if what you are doing in a property might work in a method also. But I digress. In his controller he has a action result that binds the ProductsListViewModel to the view:

public ViewResult List([DefaultValue(1)] int page)
{
	var productsToShow = productsRepository.Products;
	var viewModel = new ProductsListViewModel
	{
		Products = productsToShow.Skip((page - 1) * PageSize).Take(PageSize).ToList();
		PagingInfo = new PagingInfo {
			CurrentPage = page,
			ItemsPerPage = PageSize,
			TotalItems = productsToShow.Count()
		}
	}
	return View(viewModel);
}

Before I continue there are a few things to note about the controller method and the first is that I have not shown the productsRepository and its implementation and the second thing to note is that PageSize is a public variable declared in the controller class.

The code works great, and I have used it now in several places and I really like it because it feels as if the PagingInfo class provides an abstraction that the entity you are paging does not know about. This makes it feel light and easy to implement. I do however think it might be useful to create a class that accepts a generic type instead. So what I have done is create a class called EntityViewModel, and it looks a bit like this:

public class EntityViewModel
{
	private List listOfEntities;
	private PagingInfo pagingInfo;

	public List ListOfEntities
	{
		get { return listOfEntities; }
		set { this.listOfEntities = value; }
	}
	public PagingInfo PagingInfo
	{
		get { return pagingInfo; }
		set { this.pagingInfo = value; }
	}
}

This will mean that when I create a controller method I can do this instead:

public ViewResult List([DefaultValue(1)] int page)
{
	var productsToShow = productsRepository.Products;
	var viewModel = new EntityViewModel
	{
		ListOfEntities = productsToShow.Skip((page - 1) * PageSize).Take(PageSize).ToList();
		PagingInfo = new PagingInfo {
			CurrentPage = page,
			ItemsPerPage = PageSize,
			TotalItems = productsToShow.Count()
		}
	}
	return View(viewModel);
}

Which to me seems a bit more flexible. It doesnt end there though because I want to consume the controller method using jQuery and jQuery templates and for that I need to change the controller method slightly:

public JsonResult List([DefaultValue(1)] int page)
{
	var productsToShow = productsRepository.Products;
	var viewModel = new EntityViewModel
	{
		ListOfEntities = productsToShow.Skip((page - 1) * PageSize).Take(PageSize).ToList();
		PagingInfo = new PagingInfo {
			CurrentPage = page,
			ItemsPerPage = PageSize,
			TotalItems = productsToShow.Count()
		}
	}
	return Json(viewModel);
}

Now I can get a JSON result, AND it has paging which is totally awesome!

  • Share/Bookmark
posted by fr3dr1k in ASP.NET MVC,jQuery and have No Comments

When Stored Procedures are a bad thing…

Stored procedures are remains one of a DBA’s main weaponry, there is no doubt in that, but in my opinion there are a few cases where stored procedures are a bad thing.

The first reason is that they lock you down into vendor-specific syntax which ultimately means that your system can only run on a vendor-specific RDBMS. This is fine if you are never planning on creating a shippable product, but if you do intend to create a shippable product the data layer in your product should not be dependent on a specific RDBMS. I am sure there are nuances that separate SQL Server Stored Procedure syntax from Oracle syntax, which means that if you intend to make a product work on say both SQL Server and Oracle you might have to rewrite parts of your stored procedures to be compatible with the specific vendor.

The second reason stored procedures are bad is because DBA’s try to control too much, they tend to sometimes dabble too much and exert too much control, which leads to application inflexibility. I have seen instances where the DBA returned HTML from a stored procedure, which is a total WTF moment. What happens if your data needs to be consumed in a non-web environment, like Windows Forms or WPF? What do you do with the HTML? The point is that the RDBMS is responsible for data integrity and data integrity alone, and not for returning HTML (its the role of the client consuming the data). I always had the impression that some DBAs would even run the web server using SQL Server. I have also seen DBAs place domain specific code in stored procedures. In other words they let the SQL handle business rules, which is inflexible again and it muddies the water in terms of what the code using the data must do.

The third reason stored procedures are bad is that they can become really cumbersome to maintain, in which case it makes better sense to rather have your programming language deal with data access and not have your business rules in stored procedures.

The fourth reason stored procedures are bad is because there is a preconceived notion or idea that they are more secure, which again is a load of crap. The only thing that makes it seem more secure is because the roles for a database have not been properly assigned and that you are trying to be “more secure” by adding T-SQL to apply user-specific rules. I have seen this approach fail where data gets leaked to users that are not suppose to see it because the code in the stored procedure was dodgy, not because the security was inherently bad. You can lockdown roles and their permissions in your database to a reasonable extent.

The fifth reason stored procedures are a bad thing is because they don’t really outperform ADO.NET code.

  • Share/Bookmark
posted by fr3dr1k in SQL Server 2005,SQL Server 2008 and have No Comments

What are extension methods?

I was looking for questions that a Senior .NET developer could expect and one of the questions I would ask is to explain what extension methods are. If I am not mistaken ASP.NET MVC 2.0 uses extension methods to create HTML Helpers, which would make perfect sense since ASP.NET MVC might not have all the functionality baked in, that you may require.

Extension methods essentially provide a developer with a mechanism to extend the base functionality of a particular class. So lets say you want ToString() for a class to return a date in a particular format, then you could write an extension method that transforms the ToString() representation of that object into the DateTime format you desire. Creating an extension method requires that you create a static class with a static method, like:

    static class Extensions
    {
        public static string ToString(this Concept concept, DateTime startDate)
        {
            return startDate.ToString("dddd MMMM yyyy");
        }
    }

Where concept is an arbitrary class I created. If I create an instance of Concept and call ToString() I get the overload:

            Concept concept = new Concept();
            Console.WriteLine(concept.ToString(new DateTime()));
  • Share/Bookmark
posted by fr3dr1k in C# and have No Comments
Tags: ,
Get Adobe Flash playerPlugin by wpburn.com wordpress themes