Jun 23 2008

C# 3.0 and Implicitly Typed Local Variables

Category: Programminglomaxx @ 5:13 pm

 

In Jeff Atwoods Department of Declaration Redundancy post he talks about the benefits of the ability to implcitly set the type of local variables in C#. Whilst I don’t have a problem with being able to condense

BufferedReader br = new BufferedReader (new FileReader(name));

into

var br = new BufferedReader (new FileReader(name));

Personally, if you wanted to condense that code, I would be far happier for it to be condensed on the right hand side of the assignment rather than the left. For example:

BufferedReader br = new (new FileReader(name));

It’s still clear what the type of br is and you still get the benefits of reducing duplication. The other reason I like this is that it also leaves var to be used where it probably has the most benefit – when defining anonymous types. For example:

var obj = {Prop1: "a", Prop2: 112};

I think what it boils down to is that var is being used to solve two problems. If the scope of var was left to anonymous types and the problem of duplcation in object declarations was solved implicitly through improved syntax it would provide a clearer direction on how each feature should be used. So often in the past features have been introduced with no clear scope as to the problem they are trying to solve and eventually they get used to solve problems they were never intended to solve.

I also feel that the following is just going too far:

var url = "http://tinyurl.com/5pfvvy";
var maxentries = 5;
var pi = 3.14159;
var n = new int[] {1, 2, 3};

The main problem I have with this code is that whilst it’s easy to see that url is a string, you can’t tell the type of pi or maxentries. The assumption would be that maxentries is of type int, but there’s no way to be certain without calling GetType. It’s even less obvious with pi. Is it a decimal, double or float?

At the end of the day, I guess it all comes down to personal preference but you should always research and carfully consider the use of newly introduced features into any product you use.


Jun 20 2008

Firefox 3

Category: Programminglomaxx @ 9:35 am

When it comes to browsers I’m looking for 3 things:

  1. Quick Initial Load
    When you use the browser as much as I do (according to google web history my total google searches are 13640) you don’t want your browser window to be up and running milliseconds after you click the icon or type "i’ into launchy. You don’t want to be waiting 2-3 seconds for your browser to load.
     
  2. Stability
    Again, when you’re using the browser as much as I do, you’re inevitably going to have browser windows open for extended periods of time. You’ll be browsing hundreds of pages a day which accumulates a lot of history and with tabs available in all modern browsers, you’ll be chewing through plenty of those a day. With these extended browser sessions, you want your browser to have rock solid stability.
     
  3. Pages to look (and work) as they were intended
    I don’t want to have to have a backup browser that I can use just in case something doesn’t look right in my main browser. I only want one browser and if my main browser can’t display 99% of the pages as they were intended then it’s not going to be my main browser for long.

With these things in mind, I’ve been using Firefox 3 for the last few days since it’s official release and I have to say, I’m impressed. I’ve used FF2 and Safari in the past, but on my windows machine, I’ve always found myself coming back to IE7.

My gripes with FF2 were that it was that it didn’t meet my first two browser requirements. It was slow to initially load, there were random crashes and the memory leaks would kill me. IE7 wasn’t necesserily a perfect experience, but overall I found it to be a much more stable experience than what FF2 offered.

Safari just didn’t get a look in because it failed on all three counts. Slow to load, crashed often and pages nearly always looked wonky.

So after a couple of days of FF3 usage, things are looking promising. I have had some pretty long browser sessions with plenty of browsing and haven’t had a single crash. Memory seems to behave itself and I haven’t noticed any pages looking odd.

I’ve still got IE7 on my machine as I need to develop against it in Visual Studio, but when I get a bit more time I’m going to look into getting rid of it and developing against FF3 and just use IE7 to test that everything works across multiple browsers, but in the meantime, I’m happy to say that unless there’s some complete meltdown in stability in the near future, I’ll be sticking to FF3 as my main browswer.


Jun 18 2008

7 Things That Will Make You a Better ASP.NET Web Developer

Category: Programminglomaxx @ 11:54 am

Programming in ASP.NET is an excellent framework for building web applications and there is a lot that can be accomplished by using the myriad of online tutorials and starter kits. However to really harness the power of ASP.NET it’s important to get an understanding of how certain ASP.NET specific things work. Here are are list of things that I think are particularly important in helping you improve your ASP.NET development skills and are skills that I use day to day. These skills in particular are ones that I have spent time learning and studying as an ASP.NET developer and found that the time invested in learning them has helped to vastly improve my applications development.

  1. Understand The Page Life Cycle
    If you’re developing ASP.NET pages and think the only event fired when a page is created is the Page_Load event, then it’s probably time you reviewed the ASP.NET page life cycle. Of particular importance is knowing what events are fired during the life cycle, what the purpose of each event is and what occurs during each event. MSDN has a good summary on the page life cycle but I would also suggest taking the time to make a custom application, wire up the events, fire off a few postbacks and understand exactly what is happening in each event.
     
  2. Learn about the Provider Model
    Whilst providers aren’t specific to ASP.NET, they’re used quite a lot throughout ASP.NET applications. The common providers you’ll hear about are role, membership and sitemap providers. In particular, have a go at writing your own custom providers so you get a deeper understanding on the benefits of providers and
    where you should be using them in your applications.
     
  3. Sessions, Cache and Viewstate
    By default, asp.net is a stateless medium. Sessions, caches and viewstate all work together to help give state to asp.net. As a developer, you’re eventually going to have to not only understand the differences between these technologies, but where to apply each technology.
    For example, session state has InProc, StateServer and SqlServer don’t all handle non-serializable objects the same way and viewstate can often be turned off to save bandwidth but you need to understand how it works before you turn it off.
     
  4. Regulate your Expressions
    Regular Expressions in the .net framework are truly amazing. They make string and pattern matching a snap and they are useful for more than just validating input. One of the best ways of learning Regular Expressions is to see what others have done and one of the best resources is the Regular Expression Library
     
  5. User and Server Controls
    One very cool feature of asp.net is the ability to make user and server controls, however to get full benefit out of your controls you need to not only understand how to develop them, but understand the different situations in which creating a server control is better than a user control and vice versa. Both user and server controls bring an extra level of re-usability to your code so you should definately look at how you can use them.
     
  6. Know your configs
    There’s a whole lot more to the web.config than just appSettings and security. Some other useful things you can do with the web.config is set up custom config sections and reference other config files from within your web.config. Also, if you’ve built some custom web and user controls, you can register those in your web.config as well.
     
  7. There’s more to AJAX than just update panels
    Many ASP.NET developers I talk to like to use update panels and claim to have used "AJAX" to improve their site performance. Whilst it’s true that AJAX drives the update panels, if the extent of your AJAX programming involves dropping a couple of update panels on an aspx page it might be time for you to learn how AJAX really works, because when things start going wrong with your update panels, or you want to do something a little more complex, only a solid understanding on the fundamentals of AJAX will help you solve the problems.

    Take the time to learn about Web Methods. Learn about how the page life cycle is affected by an AJAX call. Learn how to interact with session, cache and viewstate when using AJAX. All these things will help you create better ASP.NET web applications.
     

 


Jun 05 2008

ASP.NET Ajax In Visual Studio

Category: Programminglomaxx @ 9:11 am

Well, Peter Vogel is at it again in his latest article for Visual Studio magazine. This time he suggests that ASP.NET Ajax (on a side note, surely sitcking with ATLAS for the name wasn’t really that bad?) isn’t ready for the prime time. I thought that initially this would be an article about some of the performance issues related to ASP.NET Ajax, or some of the shortcomings of using ASP.NET Ajax but he then goes on hammer how intellisense and JavaScript debugging don’t quite work as well as perhaps they should in Visual Studio.

I’m not quite sure if I’m more annoyed at the title of the article and the way it fails to deliver on what is implied, or the fact that Peter picks on two feature in Visual Studio 2008 that, whilst they do have limitations, they’re still a long way ahead of what was previously available – NOTHING.

It’s a good thing that Microsoft have put this into their latest release and I look forward to them continually improving this feature set as I’m sure they will.

As for ASP.NET Ajax itself, it’s more than ready for the prime time when used appropriately.  Microsoft has done a great job in reducing the friction between creating WebMethods and consuming them on the client side which for me is one of the best features of ASP.NET Ajax. Being able to put a [WebMethod] attribute at the top of a static method and being able to call it from the server side is something that people who worked with the original AjaxPro.net makes the ASP.NET Ajax far more enjoyable.

Performance in ASP.NET Ajax is also excellent as Omar Al Zabir has blogged is also more than acceptable.

Petere also raises issues with the $Find() method:

However, this code will also break if:

  • The name of the containing control (the FormView) is changed.
  • The containing control, with all of its child controls, is moved inside some other containing control.
  • Microsoft changes the format used when generating the ID or name attributes of HTML controls inside a naming container.

I’m sorry but it sounds like Peter is clutching at straws. I’d expect $Find to break in any of the scenarios above, so I’m not sure you can be annoyed at a method for producing expected behaviour. At the end of the day, $Find is a far more convenient method for getting objects back from the DOM than document.GetElementById.

I have to say, this article is well below the standard I’d expect from VS Magazine and doesn’t really offer any insights into the suitability of ASP.NET Ajax for the prime time.


Jun 02 2008

Search Tools

Category: Programminglomaxx @ 11:17 am

When it comes to searching, there are lots of different tools available to help you find what you want NOW. Personally I like to use a couple of different search tools depending on what exactly I’m looking for.

Web Searching

This is a no brainer, but google wins hands down. Wether I’m searching for images, code samples, lyrics whatever, google wins. But it’s toolbar integration with IE means I don’t have to go back to their website to search. But everyone knows google web searching is good, but what I like most is being able to integrate it with google web history because it means I can access any of my searched sites from any computer in the world and it dominates the built in history for both IE and FireFox.

Desktop Searching

By default, people will use either Windows Search or Google Desktop Search. Personally I don’t have a problem with either of them, but I’ve found that Copernic Desktop Search is the winner for my desktop searching needs. The key feature for me is the ease with which I can customize it to search for custom document files, which is especially handy for me when I’m trying to search for code files with .cs or .aspx file extensions. It’s also lighning quick and has great integration as well as the ability to save searches means it’s a much more useful tool for me than the Google or Windows products.