Fremus.co.za

Demistifying Life and Web Development

Archive for January, 2011

Building a CMS with ASP.NET MVC 3 Razor – Conceptualisation

I have been working with ASP.NET MVC 2.0 for the last couple of months, 6 or so and the thing that I love the most about ASP.NET MVC is the fine grained control you have over the bits of your website, and it all feels like you are still working on a website. Lets be honest here for a moment, developing web applications with webforms feels unnatural and unwieldy and you always have this sense of it not being a “real” web application but rather some leaky abstraction of Windows Forms. ASP.NET MVC changed this perception a bit, by first dumping the whole page-life cycle and then by removing the whole page behind architecture. Instead you now have a very clear separation of concerns, with html being kept in views and your code is defined inside controllers and models. Controllers are small pieces of code that give views their content and you can specify whether a view is strongly typed or not, in which case when you use the Model keyword you gain access to a particular model’s properties or methods. The general rule is that controllers should be skinny and models should be fat. Models are the business logic of the application and contain items such as your interfaces and classes. Enough about what ASP.NET MVC is for now.

ASP.NET MVC 2 uses the Webform rendering engine and ASP.NET MVC 3 uses the Razor rendering engine. You can read more about the Razor view engine on Scott Gu’s blog, but essentially it boils down to is the way in which dynamic content and html is rendered and how your view engine deals with it.

Today I started reading up on ASP.NET MVC 3 and Razor, starting here because I wanted to get a better understanding of how layouts work in Razor and also how I could leverage some of its cool functionality specifically for a CMS. Before I continue discussing how I could see myself building a CMS using Razor, I want to define what I would want from a CMS and what I would want it to do. Consider this my requirement statement, my way of defining the nature and functionality of the CMS.

I want a CMS that is flexible enough to handle multiple page layouts without having to create static pages. In other words I want to create a CMS that allows me to add pages from scratch without having any static views in place. I just want to be able to create pages using different templates. So if my only view is the home view, then every subsequent page that I add will essentially be part of a ViewResult within the HomeController, and if pages are nested the ViewResult should reflect that. A page can have a parent or child page, nth levels deep. The basic workflow for adding a page to a CMS could be:

  1. Select a page Template
  2. Select a layout
  3. Populate regions within layout with content
  4. Save the page

Apart from this basic functionality the CMS should provide a way to integrate “datasets” or strongly typed data items into a page, style the data items and provide cascading pages if required without the CMS having to know anything about the data item it is cascading. If you have a product and it has several entities associated to it then you might want to create separate pages based on those entities, but then it means you have to specify the page and page layouts for the cascading items. It also depends on what type of layout that data item has.

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

Brand awareness starts at the grass roots

Brand awareness can also apply to personal brand awareness and with this I mean that your particular personal brand will eventually reflect the brand you are working with and on together with others. Email, for instance, is a simple way to measure personal brand. If you abuse email, your personal brand will reflect that, or if you display certain tones within your emails, I am guessing it will somehow reflect it in your personal brand too. Another example that I thought of relates to some dev work I did earlier, where I knowingly tested a few emails to users within certain roles – just two users in this case, myself and a colleague. The thing is though I sent several emails and it got me thinking that maybe I should value my colleagues time and respect as much as I would a customer, because ultimately that reflects in your personal brand, doesn’t it? We live in a world where a brand’s vanity can quickly wear off – or even its appeal.

So instead of firing off test emails I simply changed my web/app config:

<system.net>
    <mailSettings>
      <smtp deliveryMethod="SpecifiedPickupDirectory" from="noreply@testdomain.org">
        <specifiedPickupDirectory pickupDirectoryLocation="c:\smtp\"/>
      </smtp>
    </mailSettings>
  </system.net>

And voila, all emails are stored in a directory where I can open them and see what they look like.

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

What would make you go to a “Tweetup”?

Today I was doing some thinking again, about my own personal demons in particular. One of these demons is that I tend to be extremely sceptical of people and 99 times out of a 100 I will have a pre-conceived notion about people, and the notion will manifest itself as my reality, and as we all know your perception is your reality. The manifestation will become a defensive mechanism and being defensive around people may seem to be internalised to yourself but more often than not it will be clear in your body language also. I asked the question on Twitter:

if i dont let my pre conceived notions about people go i guess they wont change in my eyes either. then you are always expecting the worse

To which someone replied:

Very true. But without being naive. That’s the key.

So there is no real perfect answer when you find yourself with a crowd of unfamiliar people – you have to somehow let go of the pre-conceptions on one side but on the other side of it you should never be so naive to think that people will generally accept you the way you are. Just because I am trying hard to fight my own personal demons, it doesnt mean someone else does too. They might think themselves quite perfect even if they build up some pre-conception about people. It is my personal experience that very few people make you feel at ease and totally accept you the way you are. Its a defensive mechanism I guess from their, but also being aware of yourself and the people you surround yourself with is not a bad thing, it just means you are selective and that the people you do end up being comfortable with the most might be long term friends. It also means you have good self awareness (EQ) and that you have some pride and dignity and you are not going to just throw yourself out there and let people take whatever liberties they wish. You do not have to sell yourself to be like the world wants you to be – be who you are first, screw the world.

So back to the question, would you go to a Tweetup? I suppose many have and to them it has been an awesome and enriching experience, but to those that haven’t, would you? I could probably skip a tweetup and not worry about it again, since it has no bearing on the few close friends I have and how they see me. It also has no real bearing on me, I’ll be me long after a Tweetup. On the other hand it could be nice to see what people do around you, maybe someone might be nice, and maybe you end up learning more about yourself. A favourite song of mine has the following lyrics:

Looking at life through a loaded gun
Take your best shot, aim it at the sun
Looking at life through a loaded gun
You’ll know you’ll find…

You’ll find yourself, you’ll find yourself alone
You’ll find yourself, you’ll find yourself alone
You’ll find yourself, you’ll find yourself alone
You’ll find yourself, you’ll find yourself

I cannot go through life looking at it with a loaded gun, because its self destructive. You cannot live in a defensive mindset, because as in rugby you cannot defend and defend and expect to win.

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

Types of indexes for SQL Server (2008)

One of the other things I felt the esteemed devs at the previous company had problems with was fundamentally understanding SQL Server from a technical and ground-level understanding. I don’t think they understood things like indexes very well, because in the database design they only ever used primary keys, and when they used foreign keys, they referred to doing things the ‘relational way’. SQL Server 2008 has certain types of indexes and understanding them, in my view, is central to understanding how your database should be designed. What is a btree?

In computer science, a B-tree is a tree data structure that keeps data sorted and allows searches, sequential access, insertions, and deletions in logarithmic amortized time. The B-tree is a generalization of a binary search tree in that a node can have more than two children. (Comer, p. 123) Unlike self-balancing binary search trees, the B-tree is optimized for systems that read and write large blocks of data. It is commonly used in databases and filesystems.

I also recall these ‘DBA’s’ categorically stating that they didn’t like views – without a reasonable argument, which they expected everyone just to accept. Its the same argument style they used when comparing Dell to HP – they expected everyone to accept their argument (or lack thereof) that HP was worse than Dell. Back to the point of why they didn’t like views, which was based solely on some over hyped personal opinion and not some real proof. I just did a quick Google for Views vs Stored Procedures and one of the first links I cam across was an article by Frans Bouma where he lists quite a few points on why stored procedures are bad, and why using dynamic SQL is a better approach. I also found an article by Jeff Attwood where he clearly states that stored procedures should not be used for simplistic needs. Within the previous environment I worked in the devs wrote stored procedures for everything, including basic scaffolding.

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

Taking frustration and making good use of it

I am still frustrated and angry with my previous employer, simply because they did not offer me anything new to learn at all. I don’t know why I still carry this frustration, but I do, so maybe I need to use this energy and write about the things that bothered me so much and propose a better way.

Their programming techniques were questionable to say the least, from having upper case method naming conventions right through to having no real clue about things, and claiming they did. The thing that was the most surprising was that through their cluelessness, they actually thought that what they were doing was right. What gives me the right to say I am right? Not much really, apart from the fact that I did study some and I feel that what I was taught was completely ignored by these ‘experts’. Some are claiming to be Senior Web Developers with 6 years experience – yet they have only worked with Microsoft Technologies, and they have only worked for one organisation their entire career, so who really measures their seniority, apart from them? Claiming to be a Senior Web Developer using VB.NET and not knowing a quarter of the language’s features does not entitle you to seniority either. The DBA’s also know little outside of SQL Server and when asked about MySQL they tend to be smart about it as if SQL Server is the only piece of RDBMS software written. I have written before that these people talked about “doing things the relational way” when they used SQL Server, and if that is not a red light to anyone who has done some computer science, then not much will be. The fact is they pretty much did self appointed ‘DBA-mastery’ when what they really did was write little more than messy T-SQL Scripts, which included generating HTML in some cases (shocking!). The T-SQL often used concatenation to generate results and was difficult to read, to say the least, and because they were able to write and execute these scripts, they thought they were awesome and wise. Yet data often leaked to clients that were not suppose to see it, which makes me wonder.

In my first attempt at dealing with the frustration I want to list the things a SQL Server DBA should now, which I know they did not. First and foremost they relied almost entirely on learning by Google, in other words whenever an error occurred, Google was their first source. They had no real system for breaking the errors down, which ultimately meant they did not have enough knowledge or expertise of SQL Server, yet they called themselves DBA’s. Asked what CLR stood for none knew either. I know normalization can be both good and bad – but throughout their database design(s) they did not do any normalization and I am willing to bet that if you asked them to normalize they would a) not be able to recite the normalization theory b) apply normalization, primarily because they tend to think that a certain way of feeling or thinking is going to result in a better ERD design. I saw in at least one instance where their ‘way of feeling’ failed, and where normalization would have helped a great deal. Other things that seemed strange to me was that they used the ‘sa’ user as login, as well as “views” simply being deemed “bad” with no real good reason.

So what are some of the better practices? I did a Google for some SQL Server best practices and came across this MSDN article and relating back to the point I made about the ‘sa’ user, on Page 18, of this document:

• Have distinct owners for databases; not all databases should be owned by sa.

Why is the sa login such a vulnerability though? I bet none of the guys at the previous job can answer that since they use sa as a login for everything.

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

What do I mean by “Getting a life”?

Well personally it means being a serious and totally committed developer. This morning I was writing out parts of a specification and I disciplined myself to cut it up into manageable parts and define as much as I can at once and go back to each bit and break it down a bit further. Once I did that I was able to think about the parts of the specification in isolation and break those parts down into further detail.

By getting a life I actually meant being more disciplined and being totally “there” as in being motivated and driven to achieve and to achieve well, otherwise nothing seems worthwhile. Yesterday I watched a video by John C Maxwell and in it he said that discipline is the bridge between our desires and our accomplishments and I think that is what I meant by “getting a life”. In the video he also mentioned that you cannot get ahead in life one step at a time, because one step does not really take you anywhere. You have to take two steps at a time, knowledge and action, knowledge and action. By getting a life I did not really mean going to clubs or doing less work, I actually meant being more committed in the work.

  • Share/Bookmark
posted by fr3dr1k in General and have No Comments
Get Adobe Flash playerPlugin by wpburn.com wordpress themes