The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Originally posted by firepages I have only just started playing with C# but please enlighten , what raw power are we talking about , I also try my best in C++ which is definately more powerful than PHP in many respects but not necc'ly the best bet for web-applications, hence .php and not .dll/so

please show why (as a web-application probramming language) it is so bad compared to C# preferably without note of 'everything is an object' the merits of which are subjective, nor PHP's current OOP which whilst more than usable will probably be updated around the same time as .NET gets its own server give or take a few months.

Hey, you asked for it! I’ve actually been waiting for an excuse to write a little piece in C# vs. “PHP – The language” for a while now. I give you:

Nice stuff C# has - Part #1Exception handling

In PHP, a function normally just returns “false” when it bombs. In C#, you don’t have to do this, instead, you throw an exception. Instead of:

Understand what happens? The “try” block is what gets executed first. Now, IF that code throws an exception (by using the throw statement mentioned above), the “catch” block executes, INSTEAD of spitting out the raw error to the user. Now, this is very smooth, since if you don’t handle this particular exception with a catch block, the program will unwind the call stack, and back up the code in levels until it finds a catch statement.

In plain English, this mean that you can have an ASP.NET page that calls one method, which in turn calls another method, which does some calculation and then calls another method and THAT one causes an exception, the program will back up through your code until it finds a catch statement that will take it. So you might have a catch-block at the top of your app, which catches the error and takes the message of it and assigns to a web forms label, or perhaps redirect to different pages depending on what error was produces.

This can produce extremely elegant and easy-to-implement error handling, especially in the case of ASP.NET applications where you can define an Applicaton_Error event in global.asax that picks up EVERY exception in the application that isn’t handled by a catch block:

Now, the Server.GetLastError().InnerException property is actually a reference to the exception that caused the latest error. This contains various properties, such as the Error Message, for instance, but what is really interesting here is the Stack Trace which gives us a detailed list of what methods were called in what order on what line, which gives us the exact path the program took before it bombed. Invaluable for debugging, I tell ya!

Zend Engine 2.0 will feature try, catch and throw statements, which will significantly improve the ability to develop fault-tolerant applications easily. In addition to user-level throwing of exceptions, users will also be able to configure the engine so that internal functions raise exceptions instead of returning error codes; this will simplify error recovery in various situations (e.g., recovering from any type of error when connecting, selecting and querying a database).

and even if it did not, PHP gives you full control over error reporting via the aptly named error_reporting functions , building a nice class based on that with some sort of stack to trace errors back does not seem that terrible a task which begs the question why no-one thought it was useful enough to implement ?

Then what exactly is the point of having 30 or more different languages that are all syntactically very different, but semantically completely the same?

I'm working on a .NET site for a Nokia phone with a friend, he does C# and I mainly do VB.NET.

We both can work on different section's of the site and still use each others code. (That also went to firepages)

I'm also doing an application for work, which is essentially a products gallery that can updated two ways, eitehr thru a control panel on the web site, or through the use of a desktop appliaction.

I have never developed a actual application before this, but it was an absolute breeze. I used Web Services, so I could use all the code available on the site, and if I needed to do anything else, I just wrote it in the same language I wrote the site with.

Zend Engine 2.0 will feature try, catch and throw statements, which will significantly improve the ability to develop fault-tolerant applications easily. In addition to user-level throwing of exceptions, users will also be able to configure the engine so that internal functions raise exceptions instead of returning error codes; this will simplify error recovery in various situations (e.g., recovering from any type of error when connecting, selecting and querying a database).

Yeah - I've heard that it will be release this summer or something like that. But unfortunately, like I've said before, most developers build their apps in the present, not the future, due to that pesky lack of time-travel devices in modern society.

and even if it did not, PHP gives you full control over error reporting via the aptly named error_reporting functions , building a nice class based on that with some sort of stack to trace errors back does not seem that terrible a task which begs the question why no-one thought it was useful enough to implement ?

I didn't mean to say PHP can't do error handling. I meant to say that C# does it MUCH better. Error_reporting simply doesn't come close to the flexibility of C#s exception handling, which is why it's being implemented in Zend 2.0. I'm sure you could write a very cool class in PHP to handle this, but your time is better spent solving the real problem instead of reinventing the wheel.

I think we need argument #2 please

It's coming up as soon as I take over America in Civ3.. And it's about OOP, of course!

Originally posted by M. Johansson Yeah - I've heard that it will be release this summer or something like that. But unfortunately, like I've said before, most developers build their apps in the present, not the future, due to that pesky lack of time-travel devices in modern society.

I guess that may be around the time that we can use .NET cross-platform...

[mindless aside]

I saw something the other day that said .NET was like java. I thought they were opposites. Java is write once, run many (write the code once, run on may platforms). .NET is write many, run once.

Microsoft has released a .NET CLI for BSD, yes, with shared source, but it's basically just a demo to show that .NET can in fact be deployed on other platforms just fine and how it's done. It should be a piece of cake for Apple to make a .NET Framework for Mac OS X from that, but I think the Mono Project will take care of that before that - they actually have a working version of ASP.NET for Linux and OSX already. It still has quite some way to go (current version 0.19), but the progress Ximian has made is very impressive in such a short timeframe.

Originally posted by M. Johansson .NET is well on it's way to platform independence at the moment.

Yes, and PHP is well on it's way to full OO support and exception handling.

I'm sorry, but you can't have alpha level features counting for the .NET platform, then say that we have to discount exception handling and various OO functionality because it's only in the CVS versions of PHP.

Personally, I own the fastest car in the world*

*Well, I don't actually own it yet. But I may do at some point, so why not just say I do now....

Originally posted by DJ P@CkMaN I think I missed this thread and I apologise for reviving it but isn't this - X - the same as - X

Well, yes and no, if you just do one level of error handling, there is little difference. The difference is when you do multiple levels of it - I described this in the text, but I might have beemn unclear.

Say you have a ASP.NET page - a new user registration form. The user fills it in, and sends it. Now, after validating it, the ASP.NET page calls the Users.AddUser() method, for instance. Now, the AddUser() method does some processing, such as checking if the user already exists, etc. And calls another method: DBTier.InsertUser() which starts to insert the user into the database. But OH NO - the database server just went down! The InsertUser() throws an exception. As the AddUser() method doesn't have and exception handler (because you simply don't need to), the error gets thrown all the way back up to the catch statement you (hopefully) have in your ASP.NET page. Now, here you grab the exceptions error message, and assign it to a label, for instance, and then email the error message and stack trace to yourself. This is a rather simple example, but I'm sure you can tell it's quite convinient when working with applications with many layers.

There is also some advanced functionality of this, such as the ability to define your own exceptions and such, but I've not got that far personally.

From what little I know (I have the .NET SDK installed but haven't had time to do anything with it yet) C# is the way to go when coding .NET as it provides the most power and flexibility whilst saving you from RSI* when typing (certainly in comparison to VB.NET).

Originally posted by Phil.Roberts I'm still debating whether to go with C#, Java or both.....

Right now Java is the most popular language in the world and where is the language going? nowhere, for the past 3 years now the language has been going nowhere that is why i dropped it. There hasnt been anything impressive with java since it creation. If you must choose one, it will help you with the other either way. C# is pretty much syntatic sugar to Java.

on top of that it is slow and it shows. that is not good in todays applications

Originally posted by siteguru From what little I know (I have the .NET SDK installed but haven't had time to do anything with it yet) C# is the way to go when coding .NET as it provides the most power and flexibility whilst saving you from RSI* when typing (certainly in comparison to VB.NET).

* RSI = Repetitive Strain Injury

c# does NOT offer more power than VB.NET, they both run off the same CLR, so they both access the same objects and are both compiled doen to the same metadata!

That's usually the on par with kind of arguments I get from PHP:ers in other situations. Thank god for sitepoint where there actually are substansial arguments - much thanks to HarryF, voostind and c/o.