loads of useful information, examples and tutorials pertaining to web development utilizing asp.net, c#, vb, css, xhtml, javascript, sql, xml, ajax and everything else...

 



Advertise Here
C-Sharpener.com - Programming is Easy!  Learn Asp.Net & C# in just days, Guaranteed!

IQueryableSearch is now up on CodePlex

by naspinski 6/26/2009 2:19:00 PM

another open-source project released into the wild

My IQueryableSearch class has been infinitely useful to me and saved me a ton of time. I have also gotten some good feedback on how useful it is. For those of you that don't know what it does (probably most of you) it is simply a universal search for Linq IQueryable collections; a way to search a bunch of fields/properties on a bunch of objects with one simple interface, like google for your own objects.

With that said, I decided to put it up on CodePlex to better track source code and releases; as just posting them as zips on my blog is a pain when the code is being updated. I am also hoping maybe some of you might want to critique/fix/add to my code to make it better - any interest is appreciated. As always, I hope it helps.

To make it easier it is now available in a dll which you can simply put into your bin, add a:
using Naspinski.IQueryableSearch;

And you are ready to start using it.

On a somewhat related note, I am getting close to releasing another large open-source project I have been working on for quite some time that should prove to save huge amounts of time for ASP.net programmer - stay tuned!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

c# | linq | my projects | steal some code

MCPD 3.5 Certified

by naspinski 6/18/2009 9:03:00 AM

took the 70-567 upgrade test today

The test was suprisingly easy compared to the tests required to get the MCPD 2.0. As long as you have been using 3.5 features such as Linq, some WCF, etc. you should be fine in taking it. A lot of the questions weren't even 3.5 specific, many were simple 2.0 stuff that should be trivial if you already have the MCPD.

There were a couple tricky ones that confused me a bit. Whitout getting into too much detail, I will say that there are questions with more than one correct answer, though one may not be as 'ideal' as another, so here you would have to pick the 'most correct' answer. Also, there was a definite typo that threw me off... remember Microsoft: 'asymmetric encryption' is one-way, I think you got mixed up there.

Oh yeah, I passed :)

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

asp.net

Asp.Net vs php : speed comparison

by naspinski 6/14/2009 1:42:00 PM

why is the myth that php is faster than Asp.Net so prevalent? Asp.Net is faster than php, here are the facts

So many times I have heard php pushers claim that php is so much faster than Asp.Net and that Asp.Net is clunky and slow. The most annoying part is that everything I have read (that is not factless opinion), and I mean everything, says that this is wrong; but for some reason, this myth is widely accepted. It has become a religious argument that ignores the facts.

Instead of arguing this point over and over, I decided to put it here so I can simply refer people to it to set them straight. Keep in mind that I wrote strictly php for over 4 years, it is a great and powerful language that I have nothing against. Not to mention you should not choose your development language by speed, but by what works for you (more on that later). This post is not there to pick sides (though I am now Asp.Net biased of course), just to show the facts.

compiled vs interpreted languages

First of all, at the very base of the argument it has to be realized that the two languages are very different. Asp.Net is an optimized and compiled language, meaning code you enter is reduced to a set of machine-specific instructions before being saved as an executable file. Even if you do not explicitly compile your code before you deploy it, it compiles the first time it is run, then after that it runs as compiled code. Php on the other hand is an interpreted language, meaning it is saved as the code your write and run directly from that code. It is widely accepted and proved many times over that Compiled programs generally run faster than interpreted ones because interpreted programs must be reduced to machine instructions at runtime. Here is a quote from Wikipedia that shows just how much faster they can be: "A program translated by a compiler tends to be much faster than an interpreter executing the same program: even a 10:1 ratio is not uncommon. The mixed solution's efficiency is typically somewhere in between."

the numbers

Now that the theory of why it is faster is out of the way, let's get to some cold hard numbers, so we can put this debate to rest.

The following charts and benchmarks are taken from WrenSoft and quite simply show the difference. Please follow the link if you want an in-depth description of the test.

This first graph shows the time taken to generate and display results for a search a small website.


As you can see, the average time for the php site: 0.1500 seconds, the time for Asp.Net: 0.0150 seconds... that is a HUGE difference, the php search takes 10 times as long! The next one does the same with a larger site, and the results are not much different.


Php took an average of 1.0097 seconds while the Asp.Net run took 0.0810 seconds; php took more than 12 times as long to run, the numbers are there.

Now those tests were run with basically the same code translated into different languages, so there isn't much ammunition in the 'it was coded poorly' argument. But, there is still the [valid] argument that the above tests were run on a Windows machine, and since .Net is native to Windows, it was an unfair trial, so now we will look into the statistics running on Linux, so php will have the 'home-field' advantage; not to mention, c# will be running on Mono.

These benchmarks are taken from shootout.alioth.debian.org who has numerous benchmarks for all sorts of languages and is a fantastic resource. For these tests, I am choosing to compare both vs the baseline of 'Clean' so it is easier to compare; here are the results:






As you can see, even on Linux, .Net is faster across the board; often many times faster. The only other tests I can think would be interesting to run is to compare scalability and such; I would be very interested if anyone has benchmarks for such things.

can we finally focus on what matters?

Go ahead and google asp.net vs php speed and you will see that almost all of the posts scream that php is faster, but you will not find any links or evidence backing this up. The whole point of this for me is not even really to show that that Asp.Net is faster, I already knew that; it is to possibly help curb the ridiculous assertions that it is faster. It has basically turned into a religious argument, not a fact based one and that is just silly to me. As in many other things, it seems as if enough people yell something long and hard enough, it becomes 'truth' - it simply is not.

Developing in php is fine, a huge number of amazing applications and websites are written in it by much more skilled coders than myself. That said, you shouldn't choose your language on speed, as development preference is much more important; use php if you feel it is a superior language, but don't push bad information. Most importantly focus on what matters: code in what language you can do your best work in, you don't need to justify it to anyone else, prove that it is faster/better or convert anyone else to using you language - you have better things to do.

But... Asp.Net is faster than php. Period.

Shout it kick it on DotNetKicks.com

Currently rated 4.3 by 16 people

  • Currently 4.25/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

asp.net | c#

Using html label tags with asp.net

by naspinski 6/12/2009 12:16:00 PM

I am amazed to see how many asp.net programmer do not use this

The label tag is extremely useful and easy to use, it boggles my mind why more Asp.Net devs do not use it. Remember, I am talking about the html label tag, not the asp.net asp:label which produces a span.

what does it do?

Many of you probably know what it does, but many may not. Quite simply, it makes bunch of text clickable for the related form element. For example, here I am not using a label:
Click Me:

As you can see, you need to click on the textbox itself to get focus on it, clicking on 'Click Me' does nothing. Below, I am using a label tag around the title:

how do I use it?

The syntax is simple! For regular html, this is all you need to do:

<h5><label for="txt">Click Me:</label></h5>
<input id="txt" type="text" />


For asp.net markup, it's a little more, but still incredibly simple:

<h5><label for="<%= txt.ClientID %>"></label></h5>
<asp:TextBox ID="txt" runat="server" />


Notice that some inline magic had to be done to account for the sometimes crazy nested control names that asp.net can dish out. This works for any kind of form element, it's great. Some asp.net controls like CheckBox, RadioButton, etc. employ it with the 'Text' property, but controls like DropDownList, TextBox, etc. do not.

so why aren't you using it?

Make your users lives just a little easier and go wrap all of you form element titles in label tags, it's stupid not to.

EDIT: As Frederik pointed out below, you can use the asp:label if you set the AssociatedControlID which will work just as well. I just prefer to use the html label tag as it is less markup; thanks Frederik!

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

asp.net | html

Extensions for simplifying DropDownList interaction

by naspinski 6/10/2009 12:03:00 PM

Extensions for setting the selected value and removing an item from DropDownLists

I love extensions, they make my life so much easier. Simple things that I can do in a coupole lines of code, I now do in even fewer thanks to my almighty extensions. Here are a couple of super simple ones for easy interaction with DropDownLists

setting the selected value

Sometimes it is a pain to set the selected value of a DropDownList, if it is there, it works fine, but if not, it is a pain in the butt. Here is what I use to set mine:
DropDownList1.Set("some_value");

It's just that easy, and if it's not in the ddl, it will work just as well. Here is the extension code:
public static void Set(this DropDownList ddl,
 string findByVal)
{ // attempts to set a DDL to the 'findByVal'
  try
  { 
    ddl.SelectedIndex = ddl.Items
     .IndexOf(ddl.Items.FindByValue(findByVal)); 
  }
    catch { };
}

removing an item

Once again, we all know the code for this, but an extension makes it easier, and also hanldes it if the item is not there:
DropDownList1.RemoveItem("Any");

And the code:
public static void RemoveItem(this DropDownList ddl, 
 string item)
{
  try { ddl.Items.Remove(ddl.Items.FindByText(item)); }
  catch { }
}

Normally I discourage a blank catch{} but in this case, the only error you would be encountering is if the item is not there, so unless you are worried bout that, you should be fine.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

asp.net | c# | steal some code