Fremus.co.za

Demistifying Life and Web Development

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

What do I want from 2011

I guess in retrospect 2011 only differs from 2010 by one day – Mondays don’t change to Tuesdays and Fridays don’t come on Thursday. I also dare to say that the reason we do the whole new year thing is so that we can give ourselves a reason or the motivation to start from scratch, to try and rebuild where we failed previously and to give ourselves a reason (of hope) to feel that the new year will bring improvement and renewal. Obviously we may well be fooling ourselves because rightfully speaking we are just repeating the same cycle we have been doing all our lives and if you cannot change your attitude right now, today, then the 1st of January 2011 may not be any different. With that being said though, my wish for 2011 is that I change my attitude in various ways and that my focus is on delivering results and when I say this I specifically mean focussing my energy and attention on those that really love and care for me, and forgetting those that don’t. Its simple really, you cannot change people’s opinion of you by trying to be in count with them or by trying to persuade them to think otherwise of you – its just a waste of time and energy. Instead we must focus on building out the relationships we have with friends and family because if you don’t and you continually strive to seek recognition and attention from those that do not want to give it to you, you will end up regretting lost time. Time that could so easily have been better spent with those that tolerate your mistakes and faults – and who still love you. I believe you can achieve this partially by being disciplined in your work and by focussing all your energy on your work. By focussing on your work you achieve total single-mindedness and you tend to not worry much about what people may or may not think. I want to be ruthless next year in terms of the quality and commitment I put into my work – I need and want to be focussed and drive to achieve what only I know I can, and not worry about what others think or say. I also want to focus on building and nurturing relationships with people by being more tolerant and by changing my attitude. Attitude is a priceless commodity.

I see 2011 as a ASP.NET MVC year for me and a Ruby on Rails year, maybe Django and Python too. I am thinking of getting myself a Macbook Pro next year maybe and I might consider an iPhone. Not because I am leaving the .NET world but simply because I need to learn new things.

2011 will be a year where I love technology because work in itself is a place or state of mind where you can find bliss. I also see 2011 as a year where family and friends will be important to me.

Happy new year!

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

Recent conversations on CMS’s

A recent conversation with a colleague around the nature of content management systems got me thinking about the nature of these systems and some of the trends going around. The first thing that seems to be a systematic “issue” is that a lot of systems are legacy systems and do not really seem to always consider current development practices, but rather focus on adding more and more features in the existing system. Often this approach leads to bloated systems that require more effort to maintain. Lets be honest about development practices – they change quite rapidly. I think we are no longer living in the days of classical analysis and design – but rather in a world where rapid (read agile) development seems the way to go. Rapid, agile, to me means that you spec a system one bit at a time and the focus is on getting those bits working. Thus if development practices change and the practice of developing a particular CMS used an older development practice then surely its no longer reflecting relevant thinking. It can also be said that relevant thinking is relative to the problem a particular CMS is solving, but the point I am making is that a key fact in defining a good CMS is in its ability to adjust the needs of today and not yesterday. Its also true that you cannot truly get to today possibilities without knowing what you did yesterday.

Do CMS’s only solve the matter of making sure websites are displayed or rendered consistently? Surely a CMS’s is more than that and should ideally expose one or more API’s – in fact I believe if your CMS does not expose some sort of core API it will not get the traction it needs, and you cannot really improve the code in your system without others using it. Other factors that contribute to the nature of a CMS include SaaS (Software as a Service) and PaaS (Platform as a Service) models, and the question that comes to the fore, in my mind, is whether a CMS embraces the nature of a service or platform-oriented environment.

I also gave the idea of designing a content management system in terms of presentation management some thought and initially I conceptualised that the presentation management part of it can be defined in a class hierarchy. The presentation management core will have a Page class and it might have a many-to-many relationship with a PageElement class. Thus a single page might have many page elements. A page element is a block element such as a paragraph, header or video. I still have to think a little bit further but my thinking was around being able to create pages and being able to add page elements to that page. Each element would be of a type and a type could be a paragraph, header or video, but it can also be another page element. The HtmlTextWriterTag class contains a whole list of enums and potentially it can be used in a dynamic sort of way. This still needs some thinking though.

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

Product Navigation Design

As I mentioned in my previous blogpost I am busy working on a website at the moment and a part of the website display dynamic product-related content. I believe that the product navigation is not perfect yet and I think it might be a good idea to take a look at some examples and draw a few conclusions from it. The first example I looked at this morning was Hi Fi Corporation (I was looking at some LCD tv’s) and immediately I started looking at the way the product navigation was done, and here are some of my thoughts:

Products are divided into categories and each category is displayed in two areas, the horizontal menu at the top and a vertical-collapsible menu to the right. Each category links to its own individual page, e.g. prods/audio for Audio products. When you click through to a category page the category bar remains to the left, with another “product filter” bar that appears below it.

On the category page for audio, here, there is a product comparison box and a paging component. Notice that the pages aren’t individual pages but javascripty/ajaxy items. Each product however has its own dedicated permalink. Isn’t it equally important to link to pages? Or is that not that important due to the nature of the data?

If you go to another website, Take 2 (my favourite online retailer for DVD’s and books), you will notice that if you click through to electronics (which is a category much like the Hi Fi Corporation example) you get to a page with sub categories to the left, which when clicked on (e.g. Mp3 Players) produces a paged result page. The difference from the Hi Fi Corporation example is that the pages are not ajaxy and you could probably access an individual page with a link – whereas the Hi Fi Corporation example you couldn’t. I’m not saying its a bad thing, just stating the difference. How would you design a product pager? Make it URL accessible? If you take a look at this Amazon.com page you will see that the paging is ajaxy. The Amazon.com page I just linked to is also bound by category, software architecture, as was the Take 2 and Hi Fi Corporation example. Would it be wrong to surmise that categories are permalinks and the products/items on them are page-able and that the individual pages are not permalinks? I can understand why a page within a category would not make sense as a permalink – simply because the data might change and move around. If 20 new books on software architecture were added today that would affect the pages. You could also argue that a page could give you the top 10 new items which might make sense in a MVC architecture where you could apply action filters.

What would the ideal product navigation design be? Well the ideal product navigation design would take the functional aspects into consideration and produce an effective solution.

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

A Quick Look at some website design / functionality

I have been working on a new website recently and its far from perfect – in fact I see it being refactored several times before I think it will reach an optimum phase or place. That being said business people don’t buy-in or the see the value in refactoring, so its something only the developer is aware or should be aware of. I digress.

Parts of the design I have been working on seems to have been using scrollable areas a lot and personally I see that as a fatal design flaw for two major reasons:

  • You are forcing design onto the natural flow of information on a web page. Surely the design should work with the flow and nature of a website and not against it. Content is the most important asset on your website and should ideally have a natural flow to it. Personally if you are using too many scrollable areas, you should re-look your design.
  • Not many websites use scrollable areas. Its ok to be different, not indifferent.

In case you are wondering what I mean by scrollable areas, it refers to applying the height property to an area and setting the overflow: auto. The effect is that you have a scrollable area. I cannot find many sites that use this technique actually.

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