The Artima Developer Community
Sponsored Link

PHP Buzz Forum
Goto for PHP: Heaven or hell?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Tobias Schlitt

Posts: 120
Nickname: dotxp
Registered: Sep, 2004

Tobias Schlitt is a geek, highly addicted to PHP.
Goto for PHP: Heaven or hell? Posted: Sep 23, 2004 5:09 AM
Reply to this message Reply

This post originated from an RSS feed registered with PHP Buzz by Tobias Schlitt.
Original Post: Goto for PHP: Heaven or hell?
Feed Title: Tobias Schlitt - Weblog
Feed URL: http://php-applications.de/lists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundapplications/blog/rss.php?category=2_PHP&version=0.91
Feed Description: a passion for php
Latest PHP Buzz Posts
Latest PHP Buzz Posts by Tobias Schlitt
Latest Posts From Tobias Schlitt - Weblog

Advertisement

Reading all those mails from the past weeks, I stumbled over several dealing with a patch for PHP provided by Sara Goleman, which provides "goto" statements for PHP. There seem to be a lot of different opinions on that topic, in my eyes mainly depending on the code camp the specific person comes from. I wanna pick up some of the statements I found against goto and comment on them.

Goto is evil

I remember doing Basic, ages ago, which did not know things like procedures and function (not even thinking of OOP). Doing goto (based on the line numbers) was the only way to go. Yeah, that were my first experiences with programming. The code looked horrible and was almost unmaintanable... (think of renumbering the lines, when you wanna insert code). Then we started with Pascal in school and goto's were the evil on earth...

Can you see the problem, why goto has been considered evil? In my eyes, it's not goto itself, but the absence of any other possibillity. Imagine we've had functions these times, I guess that goto would have been used in a much other way.

Goto conflicts with the concept of OOP

True, goto conflicts with the conflict object object orientation in some way. Even true, PHP just invented a new OO model. Even more true PHP does follow the trend of OOP with that. But does goto really conflict with that happenings?

Not in my eyes. What I always loved in PHP was the possibility to choose how you would like to solve a problem. OOP is nice, but it's overhead in a huge bunch of cases. Functions are nice, but even they are overhead in some place (think of a simple shellscript). Having the choice of which approach to follo ffb w with the next project is a freedom I enjoy. Even better is the possibility too combine. So, where is the bad side of adding another technique of coding and give people the choice? Does one really think, that people will fall into Spagetthi code again these days, when having the possibility?

Switch has the same concept

True in some ways, but using a switch instead of goto looks a) really ugly and b) allows you just a single jump in PHP. The sense of switch is to react on a given value in one of several defined ways. Gotos allow you to jump between multiple marks more often.

Everything you can do with goto can be modeled by other constructs

This is no true. Some cases (e.g. issues in parsing and some nice looking error handling techniques) can not be modeled exactly as goto can do. Even if, the constructs for that are mostly more complex, ugly and unmainanable as the goto solution would have been.


In general I think Sara's patch cannot be bad at all. Giving the to the user looks pretty senseful in my eyes and the security restrictions for goto sound sensible for me:

  • No jumping between functioncs
  • No jumping into/out-of the global scope
  • No jumping from any code in one file to code in another file (even if it's global scope on both ends)

Although I don't understand the last point.

Anyway: Thanks to Sara for the cool patch and hope that goto will find it's way into PHP5.

Read: Goto for PHP: Heaven or hell?

Topic: Searching the Creative Commons Previous Topic   Next Topic Topic: Appreciate-a-project-weekend

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use