SitePoint Sponsor

User Tag List

Page 2 of 5 FirstFirst 12345 LastLast
Results 26 to 50 of 117

Thread: php.net

  1. #26
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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 #1
    Exception 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:

    PHP Code:
    function GrowApples($apples) {
      if (
    $apples 1) {
        return 
    false//Relevant line
      
    } else {
        
    $applesInTree++;
      }

    you do this:

    Code:
    public void GrowApples(int apples) {
      if (apples < 1) {
        throw System.Exception(“Apples must be a positive integer!”);
      } else {
        applesInTree++;
      }
    }
    Then, when using the method, you might do this:

    Code:
    try {
      GrowApples(5);
    }
    catch {
      Console.WriteLine(“Exception caught and handled!”);
    }
    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:

    Code:
    protected void Application_Error(Object sender, EventArgs e)
    {
    	if (Global.MailErrors) 
    	{
    		//Get error Details 
    		string strMessage = "\n\nURL:\n " + Request.Path 
    			+ "\n\nMESSAGE:\n " + Server.GetLastError().InnerException.Message
    			+ "\n\nSTACK TRACE:\n" + Server.GetLastError().InnerException.StackTrace;
    	
    		MailMessage message = new MailMessage();
    		message.From = "server@mydomain.com";
    		message.To = "Admin@mydomain.com";
    		message.Subject = "Unhandled exception!";
    		message.Body = strMessage;
    				
    		SmtpMail.SmtpServer = "smtpserver.mydomain.com";
    		SmtpMail.Send(message);
    	}
    
    }
    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!
    Last edited by M. Johansson; Jan 21, 2003 at 11:45.
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  2. #27
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice stuff C# has - Part #1
    Exception handling
    I have a feeling exception handling is quite new to you. If it weren't, you would probably not be so lyric about it...

    (I'm not saying they aren't great - there's a reason Java 'borrowed' them from C++, and C# from Java, but they aren't the best thing since sliced bread either.)

    Vincent

  3. #28
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by voostind


    I have a feeling exception handling is quite new to you. If it weren't, you would probably not be so lyric about it...

    (I'm not saying they aren't great - there's a reason Java 'borrowed' them from C++, and C# from Java, but they aren't the best thing since sliced bread either.)

    Vincent
    Of course I'm new to them, I practically "transferred" from PHP a few months ago! The reason I included them as part 1 is that I just learned them.
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  4. #29
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    shame you bailed...

    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 ?

    I think we need argument #2 please

  5. #30
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


  6. #31
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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!
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  7. #32
    SitePoint Wizard Mincer's Avatar
    Join Date
    Mar 2001
    Location
    London | UK
    Posts
    1,140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    [/gets coat]

  8. #33
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Isn't the .NET CLI available for the Mac and BSD?

  9. #34
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.

    .NET is well on it's way to platform independence at the moment.
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  10. #35
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    I think I missed this thread and I apologise for reviving it but isn't this -
    Code:
    public void GrowApples(int apples) {
      if (apples < 1) {
        throw System.Exception(“Apples must be a positive integer!”);
      } else {
        applesInTree++;
      }
    }
    the same as
    PHP Code:
    function GrowApples($apples)
    {
       if ( 
    $apples )
       {
          return 
    'Apples must be a positive integer';
       }
       else
       {
          
    $apples++;
       }


  11. #36
    SitePoint Wizard Mincer's Avatar
    Join Date
    Mar 2001
    Location
    London | UK
    Posts
    1,140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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....

  12. #37
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  13. #38
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Mincer
    Yes, and PHP is well on it's way to full OO support and exception handling.
    I never said anything else.
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  14. #39
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by DJ P@CkMaN
    I think I missed this thread and I apologise for reviving it but isn't this - <snip>
    Actually its more akin to:

    PHP Code:
    function GrowApples($apples)
    {
       if ( 
    $apples ) {
          
    trigger_error('Apples must be a positive integer'E_USER_ERROR);
       } else {
          
    $apples++;
       }

    THE INSTRUCTIONS BELOW ARE OLD AND MAY BE INACCURATE.
    THIS INSTALL METHOD IS NOT RECOMMENDED, IT MAY RUN
    OVER YOUR DOG. <-- MediaWiki installation guide

  15. #40
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Well all I'm hearing is rave reports on .NET so I'm ordering the framework on CD from Microsoft tonight so I should get it in a week or so and find out what all the fuss is about

  16. #41
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm still debating whether to go with C#, Java or both.....
    THE INSTRUCTIONS BELOW ARE OLD AND MAY BE INACCURATE.
    THIS INSTALL METHOD IS NOT RECOMMENDED, IT MAY RUN
    OVER YOUR DOG. <-- MediaWiki installation guide

  17. #42
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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
    Ian Anderson
    www.siteguru.co.uk

  18. #43
    SitePoint Wizard Mincer's Avatar
    Join Date
    Mar 2001
    Location
    London | UK
    Posts
    1,140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by siteguru
    * RSI = Repetitive Strain Injury
    Not when you talk about M$ it isn't. RSI is repetative sodomy injury. From being continually rogered by Billy boy!


  19. #44
    .NET inside archigamer's Avatar
    Join Date
    Jan 2002
    Location
    Strongsville OH
    Posts
    1,534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    Web Finesse Studios
    Professional, business oriented web hosting and development.

  20. #45
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

  21. #46
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Mincer


    Not when you talk about M$ it isn't. RSI is repetative sodomy injury. From being continually rogered by Billy boy!

    How crude!
    THE INSTRUCTIONS BELOW ARE OLD AND MAY BE INACCURATE.
    THIS INSTALL METHOD IS NOT RECOMMENDED, IT MAY RUN
    OVER YOUR DOG. <-- MediaWiki installation guide

  22. #47
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Phil.Roberts
    How crude!
    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.
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  23. #48
    SitePoint Wizard Mincer's Avatar
    Join Date
    Mar 2001
    Location
    London | UK
    Posts
    1,140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Phil.Roberts


    How crude!
    How can you not laugh at my superb humour!





    /gets goat...

  24. #49
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    :closes door behind mincer:









  25. #50
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hey D! Is a "mincer" someone who talks "mince"?

    (For anyone else reading this - you might need to understand Glaswegian to know what this all means).

    As regards C# v VB.NET - I did place a caveat before my statement!
    Ian Anderson
    www.siteguru.co.uk


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •