Firstly, I know PHP is a programming language and ASP.NET is a framework so we're not comparing apples with apples here, but still people make the choice whether they are going to learn how to develop in PHP or ASP.NET so this comparison is valid!
This posts stems from my own curiosity. It's a question not a statement. I've been developing in ASP.NET for many years and I like it. I've dabbled a bit in PHP and there are some things I like and some I don't like, but maybe I haven't immersed myself in it enough to know what's great about it...
So here's what I think is great about ASP.NET. Can you tell me how things are from the PHP side?
(Microsoft's IDE for ASP.NET development)
Visual Studio is awesome. Why? For a start it autocompletes commands, objects, methods, properties and almost everything else as I type and it has an extra level of intelligence that almost can't be explained. If I do something like object1.Field = object2.Field
and both objects have the same property name then it gives that property as the first choice after I type the part object2.
. And as I start typing something it gives the last similar name as the first choice, which is useful when you are writing code and repetitively typing the same object names.
VS will tell me when there's an error - a red wavy underline tells you something's seriously wrong - and it will tell me if something doesn't make sense - a green wavy underline might show me something like code that's unreachable, or accessing a value where all possible code paths don't set a value.
It also has great navigability. What do I mean? Moving around your code is easy. Recently worked on areas are highlighted. You can jump to a line number easily. Ctrl+c
with no selection copies the current line, and pasting a whole line with CTRL+v
doesn't require you to pin-point an exact location - VS will put it above the current line if your cursor is in the middle of another line. Correct indenting happens automatically when it should.
I can do all sorts of things with code windows and toolbars... Dock them, split the screen, move them to other screens!
This is only just scratching the surface of VS's features, and all of this power comes at a price of as little as $zero (there's nothing wrong with the free version either).
Also a feature of Visual Studio and it's integrated web server is debugging. I can watch as each line executes and check values. I can set breakpoints and watches.
You don't have to compile all ASP.NET projects, but it is very useful to do so.
You can't compile a project if there are errors in the coding. Most markup errors will not show up in compilation but coding errors will result in a failed build.
Better to know at compile time than after copying changes to a test or live website, right?
Choice of development style
Just like PHP and Classic ASP you can code top-to-bottom style using ASP.NET "Web Pages". Although aimed at beginners and PHP converts, you have full access to the power of C# and the .NET framework. You don't need to compile, you can just copy files to your web folder and they will be compiled automatically as needed.
Prefer the more modern and trendy MVC? You can do that too.
Or what about every anti-Microsoft-er's favourite
: "Web Forms". Hated almost everywhere for its abstraction from everything (shouldn't we all be writing assembly code then?), inefficient Viewstate (you know you can turn it off right?) and lack of compliance with modern standards (Microsoft could have updated it...).
My opinion on "Web Forms"? It's a work of genius! But like most systems it's simple to make simple applications, but difficult to make difficult applications. You can do a lot wrong with it if you don't have experience with it... Just like any other form of development.
If you have to make something like a real complicated web form with lots of AJAX for hiding and showing things then "Web Forms" and UpdatePanels are hard to beat. But I'm sure you won't believe me. I've got one such horrendously complex form that has 2,400 lines of markup and another 7,850 lines of code-behind - I don't know how I could have done that in any other system (I'm bracing myself for the "why would you" comments now).
I know why some people don't like strongly typed objects but it makes things so much easier. I don't know how people can cope without it? All this checking for this and that, and then can it be converted to this, okay then convert it. It drives me crazy when I have to switch back to Classic ASP and do all that.
Linq to SQL
Recently I was wanting to go back to writing plain SQL queries so I could write the absolute most efficient data access for a performance critical project (only because it was going to be run on cheap shared hosting). I didn't last through more than a couple of pages before I realised that doing things this way seems ridiculous in 2016.
Linq to SQL (or Linq to x
), despite its faults, is the only way I want to query databases now.
If you don't know about it, it allows you to write database queries within your code that are similar to SQL. You can pretty much do most things in L2S as you can in SQL, and the syntax is similar (but admittedly some things need a bit of extra work). You can also keep adding to your queries before they actually go to the database server (eg. if you need to build a complex query based on conditions).
The great thing about L2S is that your database structure is known so your queries are strongly typed. You can't mistype a table or column name.
I know there's ORMs and the like out there which will easily generate simple queries for you without having to write your own SQL queries but, I don't know about you, but most of my SQL queries are not just simple "SELECT WHERE" type queries. I usually have all sorts of joins and conditions and counts and other stuff going on.
Now if only Microsoft would make Linq to SQL even more like SQL (close to identical would be nice) then I would be really happy.
It's in the framework
Almost everything you need is already baked into the framework. Image manipulation, email, database access, even authentication and authorisation if you like. It can
be rare to have
to go outside the framework for most tasks. I know choice is a great thing but sometimes not having to make a choice is better.
So how do these things compare to PHP? What do you like in PHP that makes development better than ASP.NET?