Entries categorized 'Programming'

Google helps put a stake in the IE6 coffin, finally

If you are a web developer, you know the pain that is Internet Explorer 6. You know how hard and tedious it is to add support for IE6 to your web application and maintain it once released.ie6trash.png

All of the recent browser improvements to Chrome, Safari and Firefox give developers the opportunity to create very rich browser-based applications leveraging HTML5 and JavaScript. The recent announcement from Apple that the new iPad will not support Adobe Flash say a lot, HTML5 is the future.

When the major browser developers standardize on these technologies, our jobs as web developers will begin to get a bit easier. I received an email from Google recently which reflects their stance:

Dear Google Apps admin,​

In order to continue to improve our products and deliver more sophisticated features and performance, we are harnessing some of the latest improvements in web browser technology. This includes faster JavaScript processing and new standards like HTML5. As a result, over the course of 2010, we will be phasing out support for Microsoft Internet Explorer 6.0 as well as other older browsers that are not supported by their own manufacturers.

We plan to begin phasing out support of these older browsers on the Google Docs suite and the Google Sites editor on March 1, 2010. After that point, certain functionality within these applications may have higher latency and may not work correctly in these older browsers. Later in 2010, we will start to phase out support for these browsers for Google Mail and Google Calendar.

Google Apps will continue to support Internet Explorer 7.0 and above, Firefox 3.0 and above, Google Chrome 4.0 and above, and Safari 3.0 and above.

Starting this week, users on these older browsers will see a message in Google Docs and the Google Sites editor explaining this change and asking them to upgrade their browser. We will also alert you again closer to March 1 to remind you of this change.

In 2009, the Google Apps team delivered more than 100 improvements to enhance your product experience. We are aiming to beat that in 2010 and continue to deliver the best and most innovative collaboration products for businesses.

Thank you for your continued support!

Sincerely,

The Google Apps team

This announcement is actually huge, in my opinion, because IE6 is the single browser that haunts web developers daily. Once IE6 is gone we can settle down and forget it once and for all. Google has a nice advantage here, so many people use Gmail, Google Docs and other Google Apps everyday that they will be force to upgrade to a modern version of IE or switch to a different browser altogether, great for us.

The news here seems to finger IE6 but it also notes removal of support for other older browsers too. Good times ahead.


I Am Not a Master but a Solutionist

I stumbled upon an interesting essay by Zed Shaw recently titled "The Master, The Expert, The Programmer" pointed out by Avdi Grimm. One part that stuck out in my mind was this excerpt:

What I notice is that my peers are progressing to more and more complicated and convoluted designs. They are impressed with the flashiest APIs, the biggest buzzwords, and the most intricate of useless features. They are more than happy to write endless unit tests to test their endless refactoring all the while claiming that they follow XP’s “the simplest thing that works” mantra. I’ve actually seen a guy take a single class that did nothing more than encapsulate the addition of two strings, and somehow “refactor” it to be four classes and two interfaces. How is this improving things? How can more somehow equal simpler? This should never be the case.

These are the actions of an expert. These experts are very smart, capable, and skilled, but they are too busy impressing everyone to realize that their actions are only making things worse for themselves. In the end all of their impressive designs are doing nothing but making more work for themselves and everyone around them. It’s as if their work is only designed for getting them their next job, rather than keeping them in their current one.

I agree and have always thought the same. I have seen people turn something simple into something complex that will be difficult to maintain. One of my previous enterprise clients produced solution after solution which was so complex that adding a field to a form took a day with all of its levels of indirection.

So many programmers are like sheep, they follow the herd because they think they should and feel if they don't they will be left behind. In my opinion, developers should stand back from the crowd and be an individual and do those things that work for them.

Personally, I will do the simplest thing I can do to solve a problem within the constraints of the problem domain. This is my best interest because I can better maintain code later and it is the best interest of the client because it costs them less and more likely someone else can support it later.

Solutionist

I currently am working on a project that is filled with tests, some created in TDD fashion, some created after the fact. It seems to me, from someone coming in from the outside, that these tests were created for tests-sake and done for the right reasons. The tests are spread out across the project and are not complete and don't cover all of the necessary business rules. When I look at this it seems like it was a waste of the clients money. If we can't rely 100% on what the tests are actually testing, then why do them at all?

I am also working on a project with very little tests, almost none. This project works very well and shows almost no ill-effects of not having a test suite. I will not get into a holy TDD war, it's not my point. I'm just pointing out how two diverse projects from a test perspective can provide value.

I look at the work I have done over the years, some with full test suites and some without and realize what was done was done with a certain business situation in mind. We don't live in a perfect world business is not perfect, projects aren't perfect and neither are solutions.

We are solutionists and we do the best job we can from the experience we have garnered and what the client can afford. I think this is an important point here, we can't really bang our fist on the table demanding TDD from a client who may not have the budget.

I think we should be creating the simplest solutions we can to fit the needs, and budget of the client. If simple is a one form application, then do it. If simple is a 20 form application with full test suite, then do it. Simple is what gets the job done.

Technorati Tags: ,,

Mindscape LightSpeed an O/R Mapper Done Right

Anyone who reads this blog knows I work with quite a bit of different technologies, some I love and some I just tolerate.  One of the technologies I love is Ruby on Rails, for many different reasons, but one huge reason is the way it allows the developer to interface with a database.   When I create a Ruby on Rails application with even a single migration, I have access to my database tables as objects in my application with very little work.

Now transition to the life of a .NET developer.  Someone given the task of creating a database application with the job of simply adding, updating and deleting records from a database is faced with many choices with very few offering the elegance of a tool like Ruby on Rails.

I was hired recently to create a new web application which required it to be written in ASPNET with C#.  This gave me the opportunity to look at all the key aspects of the application and the first to get stuck in my mind was data access.  Which tool to use on .NET?

I write both Ruby on Rails and ASP.NET applications and transitioning between the two is often difficult when faced with the plethora of ways to access data in .NET, most seem to be more complicated than necessary. 

Microsoft Data Access

Technologies created by Microsoft only seem to make it to market if they are complicated and cumbersome to use, these include:

ADO.NET – Using stored procedures for example.

LINQ to SQL – In my opinion, a real clumsy attempt to give a way to access almost anything by a query language implemented in C# or VB.NET.  You can see by example that no one should have to write these things all day:

var q =
   from c in db.Customers
   where c.City == "London"
   select c;
foreach (Customer c in q)
   Console.WriteLine(c.CompanyName);

Entity Framework – Oh please.  I have only given this technology a cursory look and just have to shake my head in disbelief that Microsoft would create such a mess of complexity, but they do complexity best.

Non-Microsoft Data Access

There is hope though for developers wanting something better.  Technologies like SubSonic and NHibernate offer very different solutions to Microsoft’s vision of how data access should be done.  Both of these are open source projects and have their strengths and weaknesses, and both have their own learning curve.  I have spent some time with SubSonic and it is good product with active development.  I can’t say I have done very much beyond the experimentation stage with NHibernate but I know many folks who love it.

I had been a bit oblivious to work being done with data access and object relational mapping (ORM) in the .NET space.  I came across one tool from Mindscape, a New Zealand based company, with an ORM tool called LightSpeed.  I was a little reluctant because of my assumed learning curve and could not have been more wrong.  This is a commercial product but Mindscape offers a free version that is full-powered but only allows for up to 8 database tables, which would be fine for smaller projects or to try it out.

After speaking with some other developers who have been using LightSpeed I decided it was the right tool for the job.

LightSpeed in Action

The project I had in mind was indeed a new project but I inherited an existing SQL Server 2005 database full of tables.  This application will consume many of the existing tables read-only but we create new tables to store our application-specific data.

This is not a tutorial on how to use LightSpeed but how I am using the tool.  I am sure there are many ways to configure the tool to use the data most efficiently.  I am sure the purists will complain about doing model-driven design, but I don’t care.   I was looking for a tool to get up and running with the least effort, we will tweak later.

LightSpeed comes with a really nice designer which allowed me to pick and choose various tables I wanted to use in my application.  Notice how the designer picks up the existing relationships from the database:

LightSpeedDiagram

Once the designer is saved it quickly creates some very clean C# to represent the schema in code.   A few entries in the web.config and everything is ready to write some code.  Mindscape has a nice Getting Started screencast which shows how easy it is to go from zero to code.  The screencast is just over 11 minutes long and is enough to get up and running.  

Setup Code

A bit of setup code in my application gives us access to our database and a place for our objects to interact with:

        private LightSpeedContext<UnitOfWork> _context;

 

        public LightSpeedContext<UnitOfWork> Context

        {

            get

            {

                if (_context == null)

                {

                    _context = new LightSpeedContext<UnitOfWork>

                                   {

                                       ConnectionString =

                                           "Data Source=.;Initial Catalog=terminal_link;User Id=dbuser;Password=xxxx;",

                                       PluralizeTableNames = LightSpeedContext.Default.PluralizeTableNames,

                                       IdentityMethod = LightSpeedContext.Default.IdentityMethod

                                   };

                }

 

                return _context;

            }

        }

 

Once we have a Context property setup this will be the basis for all database access.  Notice it is created only once.

Retrieving Entities

All the code is very simple but does a lot.  We need an entity here for a certain ID and we are using the LightSpeed method of query, you could just as easily use LINQ queries.  I choose to stay away from them and use the cleaner method of retrieving an entity object.

        public TltForeman GetForemanByWorkId(string workId)

        {

            using (UnitOfWork uow = Context.CreateUnitOfWork())

            {

                return uow.FindOne<TltForeman>(Entity.Attribute("ForemanId") == workId);

            }

        }

Creating Entities

Passing in an instance of our entity, adding to what is referred to as a UnitOfWork and just calling SaveChanges does the job.

        public void AddForeman(TltForeman foreman)

        {

            using (UnitOfWork uow = Context.CreateUnitOfWork())

            {

                uow.Add(foreman);

                uow.SaveChanges();

            }

        }

Deleting Entities

Deleting is as simple as adding, pass an instance of our entity and remove from the UnitOfWork and SaveChanges and the entity is gone.

        public void DeleteForeman(TltForeman foreman)

        {

            using (UnitOfWork uow = Context.CreateUnitOfWork())

            {

                uow.Remove(foreman);

                uow.SaveChanges();

            }

        }

Finally

This tool is really a pleasure to use.  I don’t know if I am partial to it because of my work with Ruby on Rails or just the beautiful simplicity, but it is worth a look.   Don’t get me wrong, it does not lack features but its features don’t get in your way.  I can tweak all I want, something the Rails community refers to as convention over configuration.

The amount of time to go from database to working application was cut probably almost in half.  No stored procedures were created in the making of this application.  This fact alone should be a good enough reason to move from traditional designs to using an ORM to avoid stored procedures and save some time.

Why should managing data from an application in .NET need to be such a task, which is one we repeat over and over.  Using LightSpeed has eased the pain to get an application done rapidly and is a welcomed tool to my toolbox when I need to get .NET work done.

 

 


Gone are the Days of Simple Developer Tools

originalfox I read with interest a post by Ted Neward titled "Agile is treating the symptoms, not the disease".  I will leave you to read the post in its entirety but point out Ted is paraphrasing a talk he attended with the speaker saying:

Keeping track of all the stuff Microsoft is releasing is hard work: LINQ, EF, Silverlight, ASP.NET MVC, Enterprise Library, Azure, Prism, Sparkle, MEF, WCF, WF, WPF, InfoCard, CardSpace, the list goes on and on, and frankly, nobody (and I mean nobody) can track it all.

This is so true.  Microsoft used to chase the small developer is not chasing the enterprise and in doing so has created all of these complex pieces.

I think I understand Ted's point.  Today's tools are overly complex, built up over the years on top of existing layers upon layers of functionality.  Even new tools and frameworks built from the ground up try to jam all the functionality of an older tool times 5 over.

Gone are the days were we used great tools like DBase IV, FoxPro and Clipper to create business applications.  It is very true these applications were created by 1-2 developers, not huge teams.

Do our tools today need to be so complex to justify a software development practice such as Agile or Lean to help us make efficient use of these tools?  The answer is probably.  We need these methodologies to keep ourselves honest to make our software work as we promised within all those moving parts in the frameworks.  Even radical tools such as Ruby on Rails requires much finagling with its core and the plethora of open source gems that a suite of tests is needed to make sure we are delivering what we promised.

It's true, this was not the case in the FoxPro days, we created some really valuable applications for businesses to solve their problems and they worked well.  We did not have fancy test suites (no automated ones at least) to make sure things didn't break when we added features.  We didn't need to because the software was not that complex.

Maybe it’s hard for some people to understand what may be interpreted as a negative trend in our tools and frameworks.  The reason may be because those folks have not been around software development long enough see it.  This isn’t to say they are inexperienced, but just have not experienced the simpler tools of yesterday.  As Ted eludes to, he has several people he cares about that are old enough to understand:

Others, including many people I care about (Rod Paddock, Markus Eggers, Ken Levy, Cathi Gero, for starters) made a healthy living off of building "line of business" applications in FoxPro, which Microsoft has now officially shut down.

Phil Haack had a good post as a rebuttal to Ted, which Ted kindly replied to.  I felt like I was watching a tennis match while reading the posts.  I am not trying to get involved in the debate other than to say I understand and agree software development has become complex.  I admit I am an old-timer in software development years and miss doing projects in FoxPro.  Maybe I am just nostalgic.

There do exists a few tools I am aware of which lets small teams create software with minimal fuss:

I think smaller, faster and simpler tools are a great idea, maybe these tools are worth a look.  Could we being seeing a niche developing?


Kicking Your Coding into High Gear

kicking I finished reading the great book by Chad Fowler, The Passionate Programmer. This is a fantastic read and got me thinking about various aspects of my professional life. One of the best pieces of advice in the book which too few developers actually follow is from Chapter 15: Practice, Practice, Practice.  The premise of the chapter is that developers should always be practicing their craft and honing it into a fine instrument.  We don’t become a professional simply because we have a job,  but by the attention we pay to our individual skills.

It is common for a developer to go out and buy a book on a new programming language they want to learn and go through the book’s examples, only to come away feeling a bit empty.  We as developers do not learn best this way, we learn by doing.  When professionals are asked what they recommend in order for people to become proficient in a new programming language, they say create “something”.   Go out and pick an idea and create that application.

This was how college courses teach programming; concepts and language constructs are shown and then a problem is given to be solved.  This is the perfect example that we learn best by doing.

What if you don’t have any ideas which seem reasonable to start?  The idea of just setting out to create “something” can be a barrier to entry in itself.

Thankfully, there are several great web sites with the sole purpose of exercising our minds and helping us become better programmers.  The web sites present the reader with problems to solve with a range of difficulty.

Ruby Quiz

Ruby Quiz has been around for a while and includes 156 puzzles with at least one but often multiple solutions for each problem.  Although it appears RubyQuiz has not published a new problem since February 2008, it is still a great source of problems to solve.  RubyQuiz is designed to provide solutions in Ruby but the problems are solvable with any language which might make a good exercise to see which language creates the most elegant or beautiful solution.

Some of my personal favorites are:

I like these because the provide some practical value and are interesting.  Thanks to Srdjan Pejic for pointing out that Ruby Quiz is still alive and continuing to be updated.  The current count is at 212 quizzes.

Code Kata

Chad recommends Code Kata which was done by Dave Thomas of the Pragmatic Programmers and is explained as:

Code Kata is an attempt to bring this element of practice to software development. A kata is an exercise in karate where you repeat a form many, many times, making little improvements in each. The intent behind code kata is similar. Each is a short exercise (perhaps 30 minutes to an hour long). Some involve programming, and can be coded in many different ways. Some are open ended, and involve thinking about the issues behind programming. These are unlikely to have a single correct answer. I add a new kata every week or so. Invest some time in your craft and try them.

The Code Kata series, consisting of twenty-one problems of varying complexity, addresses problems we might face in our daily lives as developers.

One interesting example and clever approach to presenting a problem is Kata Nine: Back to the Checkout.  This Kata requires the developer to create a checkout that might be used in a grocery store.  Dave gives the reader what the input data might look like:

Item   Unit      Special
       Price     Price
--------------------------
  A     50       3 for 130
  B     30       2 for 45
  C     20
  D     15

What the interface needs to be:

The interface to the checkout should look like:

   co = CheckOut.new(pricing_rules)
   co.scan(item)
   co.scan(item)
       :    :
   price = co.total

And a set of unit tests so the developer knows what the code should do:

class TestPrice < Test::Unit::TestCase

    def price(goods)
      co = CheckOut.new(RULES)
      goods.split(//).each { |item| co.scan(item) }
      co.total
    end

    def test_totals
      assert_equal(  0, price(""))
      assert_equal( 50, price("A"))
      assert_equal( 80, price("AB"))
      assert_equal(115, price("CDBA"))

      assert_equal(100, price("AA"))
      assert_equal(130, price("AAA"))
      assert_equal(180, price("AAAA"))
      assert_equal(230, price("AAAAA"))
      assert_equal(260, price("AAAAAA"))

      assert_equal(160, price("AAAB"))
      assert_equal(175, price("AAABB"))
      assert_equal(190, price("AAABBD"))
      assert_equal(190, price("DABABA"))
    end

    def test_incremental
      co = CheckOut.new(RULES)
      assert_equal(  0, co.total)
      co.scan("A");  assert_equal( 50, co.total)
      co.scan("B");  assert_equal( 80, co.total)
      co.scan("A");  assert_equal(130, co.total)
      co.scan("A");  assert_equal(160, co.total)
      co.scan("B");  assert_equal(175, co.total)
    end
  end

Each Kata is not only a different problem but each also teaches different aspects of real-world programming whether it be unit tests, decoupling or multiple approaches to a problem. 

Project Euler

Project Euler is yet another set of problems for developers to solve with code. The web site describes Project Euler as:

Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.

There are a total of 252 problems with a range of difficulty with all being mathematical or computer science in nature.  These types of problems exercise our math skills along with our abilities to create algorithms.  Each problem lists now many people solved each problem:

ProjectEuler

Each problem has a very brief description or requirement, Problem #7 – Find the 10001st prime:

EulerProblem7

As you can see, you won’t be mired in requirements but only a simple and brief description of the problem at hand.  These problems seem to take longer than the others as they are more involved but worth it.

Top Coder

Another way to flex your coding muscle is by competing against others while learning from others.  Top Coder has been around for a while and offer many types of competitions open to the public or customized for a company.

One of their contests is the annual TopCoder Open which is already over for 2009 but you can an idea of what is all about from the contest web site.

Rails Rumble

An additional coder competition is Rails Rumble which you probably guessed uses Ruby on Rails

The Rails Rumble is a 48 hour web application development competition. As a contestant, your team gets one weekend to design, develop, and deploy the best web property that you can, using the awesome power of Ruby and Rails.

Contestants, as they are called, enter from varying skill levels and can come as a team to compete by creating a web application over a two-day period.  This is a great way to learn from others who are more experienced as well as meet many great developers which could result in a long-term relationship.

Rails Rumble 2009 is in August so get going on entering.

Source Code

Although coding problems are great for sharpening the skills you have there are other ways to build skills.  I think the single best way to improve ones code is by looking at the code of other people.  There is virtually an unlimited supply of code out in the open source world just free for educating yourself.  Just go to GitHub and start searching and poking around what’s there, pull down some projects and see what others are doing.  You will learn a lot doing this very simple exercise.

Dan Pickett points out that a great way of improving ones coding skills would be to get involved in an open source project.  Fellow contributors make great reviewers who can help improve your code.  I could not agree more.

Finally

I think the best way to learn is by doing, and these are some good places to start.  I am sure there are plenty of other sources of challenge like this on the web, please pass them along in comments and I will update the post.

My personal preference is the coding problems like those in Ruby Quiz, Code Kata and Project Euler.  They give a wide selection of problems that can be solved right at home when the time is available.

I have been doing some of these problems in my spare time but being reminded how important the exercise is from The Passionate Programmer made me want to write this post.  This is an important book and every developer should read it to give ideas about your careers or reinforce the ideas you have already.


What Aspects of Agile Software Development are Working for Soloists?

I asked this question on Twitter and received some interesting and thoughtful responses. So, those of you who didn't can't the question on Twitter. If you consider yourself an Agile Development Methodology practitioner and work either alone or in a small team (1-2 people), which aspects of Agile work for you?

I am a freelancer and talk to teams about their approach to Agile. I always hear repeated talk about:

  • Peer programming
  • Customer on-site
  • Morning stand-up

As a solo developer working from home I see the huge benefits to Agile development but don't have a peer to code with, no need for a stand-up, and no appropriate to have a customer in my home office. I practice some of the obvious things I can do alone:

  • Test-Driven Development (TDD)
  • Refactoring
  • Short Iterations

I would like to hear folks who have this experience and what works and what doesn't. Does being in a small team, even solo, give you too much freedom to let iterations or sprint goal slip? Have you changed your approach to Agile to customize it to work in this situation?

I see the amount of soloists and small teams growing over the next few years. I think Agile methodologies to be very good at keeping us motivated and focused on our work but the majority of of Agile really deals with larger teams. So, maybe cutting out what doesn't work from the Agile Manifesto and tweaking what does for our unique position can benefit all of us.

So please let me know what is working and what is not.


Why I Use TextMate

textmate I have been using TextMate from MacroMates for the past couple years for Ruby and Rails development on the Mac, and very happy with it.  I occasionally do Ruby work on Windows and have settled on E Text Editor, which is basically a clone of TextMate, including its bundling capabilities.  The features of both of these text editors has been beyond my needs and offer some really nice, simple features.

There has been a bit of a holy war going on lately on the internet about developers moving away from TextMate and using Vim or Emacs.  Granted, there is no TextMate for Linux but you can have your open-source operating system and text editor too.   Don’t most Rails developers use TextMate anyway? 

I decided to give some other editors a try on Linux, in search of one that would work on Mac, Windows and Linux.  The only real options are Vim and Emacs, both having support for Ruby and Rails.

Vim

Vim has rail.vim.  This gives Vim some shortcuts to the usual Rails command for creating such things as models, views and controllers.  I set this up and gave it try but in the end, it is still Vim.  I am sorry to those folks who love Vim but all that I can say is Vim sucks.  Why would anyone want to subject themselves to using this editor.  I used vi, the precursor to vim back in the mid-80’s and it was almost the only thing we had on old Sperry systems.  It was not a pleasure then and it is not a pleasure now.

Emacs

Emacs has emacs-rails.  This is an improvement over Vim but not by a ton.  It also sucks but it sucks less.  I think I could get used to this editor if I needed to but hopefully I will never have to do such a thing.

TextMate

TextMate has a ton of built-in bundles for many different languages and has the Mac UI we all have come to admire.  It really works well for doing Ruby development with nice shortcuts built in through bundles.  Dr. Nic Williams has created an updated Rails bundle to help out with Rails 2.0 changes supported under both TextMate and E-TextEditor.

Twitter developer Alex Payne recently examined alternative editors as I did and came to the same conclusion as I have.   I guess this pretty much seals my fate for at least the near to mid-term as how I will be writing Ruby code, either on the Mac or Windows. 

So I wonder why folks would even consider moving from TextMate to Vim or Emacs for Rails development.  What am I missing?  I can’t see how you could possibly be any more productive.

There is a report of version 2 of TextMate coming but we don’t know how far off it might be but for now, it works just fine and no need to look elsewhere.

So the reasons I use TextMate are pretty simple really:

  • Great plug-in support, like ProjectPlus.
  • Great bundle support
  • Great theme support
  • Great community support
  • Tons of little niceties
  • Almost made for Rails development with the Dr. Nic bundle and the way projects get loaded from the command line.

It made no sense to me personally why I would step back in time and use an editor such as vim or emacs when I didn’t HAVE to.

Technorati Tags: ,,


Easy Dynamic Style Sheets in HMTL Pages using ASP.NET

One of my current projects consists of a lot of existing static HTML documents that I need to work with and integrate with ASP.NET.  The idea is to change as few of the static HTML files as possible as they are fine the way they are but allow new ASP.NET applications to add some dynamic dimensions to somewhat older systems.

The Problem

A particular task I faced was to be able to take a regular link statement from HTML like this:

<link rel="stylesheet" type="text/css" href="/shared/styles/style.css" />

And be able to dynamically replace the style.css file with some other custom style sheet.  The requirement is the document could not be converted to an ASPX page and needed to remain a .html file.

This is actually a very small problem in the grand scheme of things but is one example of dealing with legacy systems and trying to find the least disruptive and most cost-effective solution to a problem.

The Solution

There is probably a clever way to solve this problem using JavaScript but our solution needed to be solved using ASP.NET.  My normal approach to solving a problem of this nature is first assume it has been solved before and do a few Google searches trying to find the answers.   This time my searches returned no viable solutions using the tool (ASP.NET) that I am using on this project, so I needed to solve this the best way I could find.

The solution I built in ASP.NET allows for many different style sheets to be used, one per client, to help "skin" our web pages.  I have some logic which figures out which CSS file to use based on who the client is and load up that style sheet.  The solution to this problem leverages this by creating a "faceless" ASPX page to help out.

The page is very simple and is called Customstyle.aspx.  This page does something very simple in the Page_load:

protected void Page_Load(object sender, EventArgs e)
{
    Response.Redirect("/shared/styles/" + CurrentStyleSheet);
}

This page is then called from our original static page, making a very small change to the HTML file by changing the original LINK to this:

<link rel="stylesheet" type="text/css" href="Customstyle.aspx" />

When our HTML page is loaded in the browser the Customstyle.aspx page will return and inject the proper CSS file into our HTML, giving us the desired solution.

There may be several ways to solve this same problem but after many tries this seemed to be the simplest approach.  In all of my years of ASP.NET development, this is the first time I needed to use it this way.

Technorati Tags: ,,,

When Refactoring Code is a Waste of Time

WasteButton We hear this all the time, a developer going in and finding some code someone else wrote and they start hacking at it to make it look more like their coding style than the original and they label it "refactored"

Sometimes we need to look at someone else's code or even our own to resolve a bug and at times it is necessary or efficient to rewrite part of the code to better assist in solving the problem.  This brings client value, a bug has been fixed.

We may have code we wrote a long time ago and the code does not reflect our current style and attention to detail.  Changing this code so we may better support it later adds long-term value to the client, the code was updated by the author and is better maintainable and reflects their up-to-date knowledge an brings value to the client.

I have worked with some arrogant programmers before who think they know it all and can turn code they deem as unacceptable into acceptable code (aka their code), you know who you are.   I have been programming a long time and I certainly don't know it all, far from it.  I am always willing to learn better ways to do things but I don't have the arrogance to run into a fellow developers code and change it because I don't like the looks of it.

This is one thing really annoys me and makes it really hard to justify to the client who often times never finds out but is billed for anyway.  This as a huge waste of time, money and introduces potential bugs.  If the code works and is not a bottleneck in the system, just leave it alone.

Please don't do this....you know who you are.  I would like to hear from all the refactoring fan-boys out there that insist on this behavior and why they feel the need.

Technorati Tags:

Data Structures and Algorithms: Annotated Reference with Examples eBook Available

dsa I came across another free eBook which looks great for those interested in the details of algorithms, called Data Structures and Algorithms by Granville Barnett and Luca Del Tongo and is hosted on DotNetSlackers.  The book is a free PDF download.

As a long-time developer this is the type of information we learned in college and don't get a lot of coverage today.  I feel this is fundamental to good programming and really understanding how things in our line of work functions.  I am looking forward to reading this and providing some feedback here.

From the Granville's blog:

This is a little project that myself and Luca have been working on in our spare (spare) time in the last month or so. The book is no where near complete but we wanted to get it out there now and progress with it in view of the public eye rather than just sit on it and wait months until it was a lot more thorough.

As this is just a preview don't expect it to be all finely polished, we know what we are lacking in terms of explanations. No chapter in the preview is the final version of that respective chapter. It's also worth mentioning that this is not the final list of chapters.

Our intended target audience are those who know how to use their respective language of choice, other than that you should be OK to follow the book. We have intentionally tried to keep the book compact and to the point.

The book is language independent. We use a form of pseudocode for all algorithms as such these algorithms can be easily ported to most imperative languages like C++, C#, and Java.

I think this is certainly worth checking out.