Microsoft vs. Linux, ASP.NET vs. PHP

Linux

This is a very popular question that comes up, especially when you are first starting to choose your path in development. I believe you really can’t go wrong with which route you choose but it does help to know some basic guidelines when deciding whether to pursue your efforts in Microsoft based technologies or the open source community.

First, be very wary about where you get your information; each side tends to be extremely biased, and in most cases fairly ignorant of their competition. There are however good sources that have expert experience in both ASP.NET and various Microsoft based technology as well as PHP, Java, Python and other more open source style technologies.

Microsoft

The next thing you want to look at is the type of projects you will be most often working on. Where there are exceptions to this, generally .NET code will be chosen when working in the realm of medium to large scale projects. PHP and other open source is generally chosen for the two extremes of the spectrum; predominately used for small companies, websites that require some but fairly little code-interaction and database operation or the complete opposite: extremely large institutions/organizations where there are very exacting requirements and incorporate several programming languages for specific use. In the latter example, these are companies who hire one or several programmers in languages from all across the board and are generally high paying but hard to obtain positions.

.NET Programmer by Day, Open Source Junkie by Night

Personally, as a career I work in a 100% Microsoft based company. All .NET all the time. The closest thing we get to open source is XML. However, this is a great thing for the structure of the company, the types of projects we work on, and the rapid/agile development we do. Code changes quickly, is tested with fairly limited resources, and is done in an extremely friendly development environment (Visual Studio). SQL administration is a dream in SQL Server Management Studio and incorporates nicely into Visual Studio for small projects.

At night, after hours, the old hacker mentality tends to creep up and encourages me to play a little in PHP on a Linux box that’s taken a cramped residence on my small desk at home. This is just how I like it, somewhat slumming it if you will. This is not to say that PHP and open source is not just as professional as .NET, as I mentioned before, but it is somewhat cultural that PHP developers tend to be more rogue and ad hoc in their development education and application.

Make a Choice and Stick with it… then Switch a Couple Times

So there you have it, a brief but somewhat non-technical comparison between .NET and PHP. Eventually I will probably add to this a bit as time goes by to include additional vantage points, pro’s and con’s, and technical spec’s.

If you would like to view more technical information you can find copious amounts of information by searching “ASP.NET vs. PHP”.

One last piece of advice, whatever you decide go ahead and do it for a while until you can development in it comfortably. If you’re constantly looking up information on google on how to develop basic code you’re not quite there yet. You should be able to write line-style code in whichever language you use. So drop the WYSIWIG’s and write code by hand, I guarantee you will become a better developer.

Firebug! Why develop without it!

If you haven’t seen Firebug then you’re definately missing out. Firebug has been out for quite a while, it’s nothing new; but I think it never got the attention (especially in .NET developer circles) it deserved.

Once, at a convention I brought up that Firebug had javascript debugging capability for a long time while Visual Studio waited until 2008 to really offer it.

Let me make sure I’m not confusing anyone, Firebug is just an addon to FireFox and is not a development environment. It is however a great tool for developers working on multiple browsers to debug javascript and peak under the covers of their web resources and clientside processing.

Here are some nice screenshots I just made of how I use Firefox:

Screenshot of Resources Loading Clientside

You can list your resources that are loading (images, external files, etc.). By doing so, you can see load times as well as broken links or clientside errors (marked in red) while loading.

Debug Firebug

Screenshot of Javascript Debugging in Firefox

Javascript debugging has always been a bit of a pain. With Firebug you can use a familiar system of breakpoints and even an Immediate-style window to check variable values, etc.

Javascript Debugging in Firebug

My Basic ADO.NET Helper Functions

I use a couple of very simply functions that I build into a common class for a lot of my projects. I’ve always tended to build onto my base classes functions that help speed up development without adding too much weight to any project.

There may be much better ways of doing this and I would love for anyone reading to feel free and comment additional methods/information or drawbacks to the information displayed here.

To begin, go ahead and create a class file (for your common functions) if you don’t already have one.

Enumeration(s)

I am a big fan of enumerations, simply because of their strongly typed usage. I’ve added the following enumeration to help with the ADO Helper functions.

Enum SQLExecuteMode
    save rollback
End Enum

The ADO.NET Wrapper Object

This wrapper object takes the place of declaring the SqlCommand Object, SQL string, SQLConnection, and parameters.

Public Class objSQLDB
    Private _SQL As String
    Private _OverrideConnectionString As String
    Private _cmd As New SqlCommand

    Public Property SQL() As String
        Get
            Return _SQL
        End Get
        Set(ByVal value As String)
            _SQL = value
        End Set
    End Property

    Public Property OverrideConnectionString() As String
        Get
            Return _OverrideConnectionString
        End Get
        Set(ByVal value As String)
            _OverrideConnectionString = value
        End Set
    End Property

    Public Property SQLCommand() As SqlCommand
        Get
            Return _cmd
        End Get
        Set(ByVal value As SqlCommand)
            _cmd = value
        End Set
    End Property

    Public Function RetrieveDataTable() As DataTable
        'NOTE: Get proper ConnectionString
        Dim strConnectionString As String = My.Settings.CHMS_DB
        If String.IsNullOrEmpty(_OverrideConnectionString) = False Then strConnectionString = _OverrideConnectionString

        'NOTE: Create connection
        Dim MyConnection As New SqlConnection(strConnectionString)
        Dim cmd As SqlCommand = _cmd

        cmd.Connection = MyConnection
        cmd.CommandText = _SQL

        'NOTE: Fill DataTable with sql results
        Dim da As New SqlDataAdapter(cmd)
        Dim dt As New DataTable
        da.Fill(dt)

        'NOTE: Clear all objects not being returned from memory
        MyConnection = Nothing
        cmd = Nothing
        da = Nothing

        Return dt
    End Function

    Public Function ExecuteNonQuery(Optional ByVal executeMode As SQLExecuteMode = SQLExecuteMode.save) As Boolean
        'NOTE: Get proper ConnectionString
        Dim strConnectionString As String = My.Settings.CHMS_DB
        If String.IsNullOrEmpty(_OverrideConnectionString) = False Then strConnectionString = _OverrideConnectionString

        'NOTE: Create connection
        Dim MyConnection As New SqlConnection(strConnectionString)
        Dim cmd As SqlCommand = _cmd

        MyConnection.Open() 'Connection must be open prior to creation of transaction

        Dim myTransaction As SqlTransaction = MyConnection.BeginTransaction()

        cmd.Transaction = myTransaction
        cmd.Connection = MyConnection
        cmd.CommandText = _SQL

        'NOTE: Execute SQL
        Try
            cmd.ExecuteNonQuery()
            Select Case executeMode
                Case SQLExecuteMode.save
                    myTransaction.Commit()
                Case SQLExecuteMode.rollback
                    myTransaction.Rollback()
            End Select
        Catch ex As Exception
            myTransaction.Rollback()
            Throw New Exception("Error while attempting to write to database")
            Return False
        Finally
            MyConnection.Close()
            MyConnection = Nothing
            cmd = Nothing
        End Try

        Return True
    End Function

    Public Function ExecuteScalar() As Object
        'NOTE: Get proper ConnectionString
        Dim strConnectionString As String = My.Settings.CHMS_DB
        If String.IsNullOrEmpty(_OverrideConnectionString) = False Then strConnectionString = _OverrideConnectionString

        'NOTE: Create connection
        Dim MyConnection As New SqlConnection(strConnectionString)
        Dim cmd As SqlCommand = _cmd

        cmd.Connection = MyConnection
        cmd.CommandText = _SQL

        'NOTE: Retrieve Single Value
        Dim objSQLReturn As Object
        Try
            MyConnection.Open()
            objSQLReturn = cmd.ExecuteScalar()
            MyConnection.Close()
        Catch ex As Exception
            Throw New Exception("Error while attempting to retrieve value from database")
            Return False
        End Try

        'NOTE: Clear all objects not being returned from memory
        MyConnection = Nothing
        cmd = Nothing

        Return objSQLReturn
    End Function
End Class

How I Use It

I use this any time I am interacting with the database for such actions as retrieving datatables, executing stored procedures, insert/updating/deleting SQL data, whatever.

Retrieving a DataTable from a Stored Procedure

Here is a brief example of how I could retrieve a Datatable from a SPROC I’ve already created:

Public Function getEmployeeReport(ByVal lngCompanyID as Integer, _
    ByVal dtmFilterBeginDate As DateTime, _
    ByVal dtmFilterEndDate As DateTime, _
    ByVal lngUserID As Integer) As DataTable

    objSQLDB.SQL = "dbo.report_amt_employee"
    objSQLDB.SQLCommand.CommandType = CommandType.StoredProcedure
    objSQLDB.SQLCommand.Parameters.AddWithValue("@lngCompanyID", lngCompanyID)
    objSQLDB.SQLCommand.Parameters.AddWithValue("@dtmFilterBeginDate", dtmFilterBeginDate)
    objSQLDB.SQLCommand.Parameters.AddWithValue("@dtmFilterEndDate", dtmFilterEndDate)
    objSQLDB.SQLCommand.Parameters.AddWithValue("@lngUserID", lngUserID)

    Return objSQLDB.RetrieveDataTable
End Function

More than one way to skin a cat… and a webpage

This is a multi-series blog posts regarding one of many ways to take a graphic design and convert it into HTML. This is the current method that I tend to use when doing fairly basic website designs.

Please note, that there are several different ways to do this and their are advantages and disadvantages to each approach; not all of which are technical in nature, such as maintainability, cost of skilled labor when dealing with highly complex CSS methods versus more typical CSS/HTML use, SEO, etc. Many individuals/companies have turned towards developing very strong CSS based designs while others have remained in table-based layout. For the purpose of this post, we will be approaching slicing graphic designs using CSS but from a more “boxed” approach.

The term “boxed” that I am using, simply refers to the majority of the design being segregated out into box regions. I will try and demonstrate this with screenshots.

The design

Let’s begin by starting with our graphic design. The following is a very simply design I started for a friend of mine who sells motorcycle parts. This design was never finalized, so it will work perfectly for our demonstrative purposes and we can continue to build upon it in future posts.

Demo Website Homepage Screenshot

Ok don’t laugh too hard at my attempt at graphic design, I’m not a graphic designer and this is not a production site (but I gave it a shot right?).

Conceptualizing Regions

Now when I view this, I tend to break everything apart into boxed regions. First, major regions starting vertically. For this particular design, I view it as 5 regions which are as follows:

  • Header (logo, search box)
  • Navigation, (navigation, login link)
  • Intro Content (intro/promo text, supporting image)
  • Tabbed Content (what’s hot, browse catalog, search products)
  • Footer (footer links, text logo)

It is perfectly acceptable to do more or less specific regions. For example, I could have made the tab and the content in the tabs seperate regions, or make the header and navigation a region, Intro and Tabbed Content a section, and footer.

Let’s visually demonstrate the region’s we’ve chosen for this example:

Demo Website Homepage Overlay Screenshot

Now, keep in mind, these are not slices. These are for conceptualizing only. We don’t want to slice this in this manner for several reasons; we don’t want to mix images which should be optimized as .gif versus .jpg, we don’t want to use graphics when we can use text, etc.

HTML Conversion

Now that I pretty much know how i want to begin grouping everything, I am going to work top-down to begin converting this design into HTML. I want to stay within each region and work from left to right using a CSS to create a tableless design.

Here is the HTML for the regions that we’ve just seperated:

<div id="header"></div>
<div id="navigation"></div>
<div id="promocontent"></div>
<div id="tabbedcontent"></div>
<div id="footer"></div>

Ok, we’ll expand on this quite a bit in upcoming sections so stay tuned to find out more about conceptualizing, slicing, and building basic html from graphic design mockups.

Teaser

In the next section we will be covering how to build out each section (header, navigation, promocontent, tabbedcontent, and footer) based on the current design.

What the heck, I’ll start a blog

Nicholas Barger

There are a lot of developer websites on the internet; far too many to keep track of. So what is the purpose of adding yet another? Well, personally there are several reasons. I have learned from the effort of others, either by personal interaction or simply by the provision of their collective knowledge. Perhaps I can give back a little bit of my own knowledge in such a way that makes sense to at least some of the visitors that should happen to read these posts. Also, it is my desire that visitors to this website feel comfortable in discussing the articles, blogs posts, and other information provided and become active in contributing to the samples provided and make our knowledge base more complete.

Please feel free to contribute and help us all learn together.