Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
http://bugs.php.net/bug.php?id=32100

quote:

Description:
------------
PHP 5 has specifically decided not to support 'finally'. Why?

This is one of numerous cases why finally is useful:

code:
mysql_query("LOCK TABLES mytable WRITE");
try {
  // ... do lots of queries here
} finally {
  mysql_query("UNLOCK TABLES");
}
You need to use UNLOCK TABLES otherwise your tables won't get unlocked when an exception is thrown. This is especially bad if you use persistent connections.

It is possible to emulate finally using try/catch but this introduces code redundancy and may create inconsistent code:

code:
mysql_query("LOCK TABLES mytable WRITE");
try {
  // ... do lots of queries here
  mysql_query("UNLOCK TABLES");
} catch(Exception $e) {
  mysql_query("UNLOCK TABLES");
  throw $e;
}

quote:

We've had long discussions and came to the only conclusion that we don't need that, for more search the mailing list archieves.

Besides the following is absolutley equivalent:
code:
mysql_query("LOCK TABLES mytable WRITE");
try {
  // ... do lots of queries here
} catch (Exception $e) {
  // do nothing here
}
 mysql_query("UNLOCK TABLES");
The only difference is the second example does rethrow the exception. Though this is still possible (however much more to type) it is wrong design. Since obviously you are using the exceptions as control flow.

And that design looks like Java where it unlike with PHP makes somewhat sense.

Adbot
ADBOT LOVES YOU

MononcQc
May 29, 2007

Sweet Jesus.

Don't they realize you can match on something else than all exceptions at once? PHP can have restricted exception matching by sub-classing exceptions and replacing the 'Exceptions $e' by 'YourOwnName $e', basically meaning you NEED a finally for these cases.

The absence of the finally block has annoyed me forever when I still programmed PHP on a daily basis.

NotShadowStar
Sep 20, 2000
There's really nothing you can say against that. It's like some idiot going on about Obama's birth place, or chemtrails, or creationists. They have absolutely no argument, just a bunch of loving crazy in their head with no premise. The problem is they can hoist their loving crazy on everyone.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

tef posted:

Amazingly, I am in agreement. Man, mIRC script, I haven't been concatting strings to make arrays in ages.

oh man, I wrote a couple RPG-style games in that poo poo.

$player1hp = [ $player. [ $+ [ $nick ] $+ ] .currenthp ]

When he finally put hashtables in I was loving ecstatic.

Vanadium
Jan 8, 2005

Thanks for linking that post with php criticisms again, I bookmarked it this time because I remember spending half an evening trying to find the link about the someInt < INT_MAX check

evensevenone
May 12, 2001
Glass is a solid.
Wait are we seriously comparing php to mirc script?

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

This made me :psyduck: IRL, like I had to grab my head and keep my brain from escaping.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

tef posted:

basically the answer is: it depends. php may be terrible, but knowing the flaws of a tool allows you to apply it well if needed. most of the time all you're doing is writing a database skin so what the gently caress does it really matter

I bet you could make a badass db skin in lisp :colbert:

tripwire
Nov 19, 2004

        ghost flow

Ahahaha people still use this language willingly

ironypolice
Oct 22, 2002

PHP is a better language than coldfusion.

Xenogenesis
Nov 8, 2005

ironypolice posted:

coldfusion.
WHOA slow down this thread can only get so low :(

Shavnir
Apr 5, 2005

A MAN'S DREAM CAN NEVER DIE
Ada is a better language than PHP.

NotShadowStar
Sep 20, 2000
So now wait a minute they came to the conclusion that

code:
mysql_query("LOCK TABLES mytable WRITE");
try {
  // ... do lots of queries here
} catch (Exception $e) {
  // do nothing here
}
 mysql_query("UNLOCK TABLES");
UNLOCK_TABLES will always happen. That's bullshit.

code:
mysql_query("LOCK TABLES mytable WRITE");
try {
  // ... do lots of queries here
} catch (Exception $e) {
  if ($e->getMessage() === "Security error") {
    throw ($e);
  }
}
mysql_query("UNLOCK TABLES");

// higher up
try {
  database_query();
} catch (Exception $e) {
  if ($e === "Security Error") {
    // Log and kill it as soon as possible 
    System->security("gently caress!", $e) && die("System halted for security, see system error log");
  }
}
Yeah a bit contrived but simple and to the point. Sorry about your locked tables until a database admin gets in and unlocks them. If there was a finally {} it would always, always, always unlock tables before rethrowing.

Goddamnit PHP.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

NotShadowStar posted:

Yeah a bit contrived but simple and to the point. Sorry about your locked tables until a database admin gets in and unlocks them. If there was a finally {} it would always, always, always unlock tables before rethrowing.

Goddamnit PHP.
The whole point of his example is "// do nothing here". The PHP developers believe ignoring errors is "absolutley equivalent" to the original code

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
PHP's as good a conversation subject as it is a programming language.

tef
May 30, 2004

-> some l-system crap ->

Mr. Wynand posted:

I bet you could make a badass db skin in lisp :colbert:

christ no, why does this poo poo even require programming?

Surface
May 5, 2007
<3 boomstick

Surface posted:


NotShadowStar
Sep 20, 2000

Janin posted:

The whole point of his example is "// do nothing here". The PHP developers believe ignoring errors is "absolutley equivalent" to the original code

IF YOU IGNORE EXCEPTIONS THEN WHY loving USE THEM. gently caress.

PHP makes me angry IRL.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
Without exceptions, it's too hard to have each page prefixed by random garbage

king_kilr
May 25, 2007

Hammerite posted:

The whole "omg PHP type-juggling" thing is a bit of a dead horse isn't it? Yeah it's not always terribly consistent, it's meant to allow you to Get poo poo Done quickly. It's not necessarily optimised for that, but it doesn't do too badly. It does give you ways to compare things carefully when you need to do so.

The main comparison-operator complaint I have about PHP is that if you want to check whether a variable exists and is null, you have to use array_key_exists($var, $GLOBALS). You can't use isset() (because it returns false if the variable is set but is null) and you can't use is_null() (because it returns true if the variable doesn't exist) (you still shouldn't use is_null even if it didn't do this, mind, because it will cause unset variable notices).

Yeah, I forgot "gently caress my life" == 0 really helps make websites faster :?:

uncleTomOfFinland
May 25, 2008

king_kilr posted:

Yeah, I forgot "gently caress my life" == 0 really helps make websites faster :?:

Well it does since it doesn't cause those pesky error messages. :v:

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

king_kilr posted:

Yeah, I forgot "gently caress my life" == 0 really helps make websites faster :?:

I interpreted this as: "Your post is wrong, because type-juggling does not cause websites to run more quickly". This is a misunderstanding of my post - my implication is that it makes some general-purpose scripts easier to program (where strict attention to the types of data is not required). That is, writing code can be faster.

There are many situations in which type-safety is required, in which case it is available.

Hammerite fucked around with this message at 16:40 on Dec 11, 2010

Cervix-A-Lot
Sep 29, 2006
Cheeeeesy
It's obvious that php sucks and should just be burned and ever used. Guess I'll use .net

ErIog
Jul 11, 2001

:nsacloud:

Hammerite posted:

I interpreted this as: "Your post is wrong, because type-juggling does not cause websites to run more quickly". This is a misunderstanding of my post - my implication is that it makes some general-purpose scripts easier to program (where strict attention to the types of data is not required). That is, writing code can be faster.

There are many situations in which type-safety is required, in which case it is available.

I don't think anyone is saying that type juggling shouldn't be an option. They're saying it shouldn't be the default behavior, and that "==" shouldn't be called an equality operator in the documentation of the language. I know you can't compare languages 1:1 all the time, but someone coming to PHP from any other language is bound to not understand the intricacies of "==" vs "===". They'll use "==" like they're used to without realizing that the thing that's going to behave like they're accustomed to is actually "===".

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

ErIog posted:

I don't think anyone is saying that type juggling shouldn't be an option. They're saying it shouldn't be the default behavior, and that "==" shouldn't be called an equality operator in the documentation of the language. I know you can't compare languages 1:1 all the time, but someone coming to PHP from any other language is bound to not understand the intricacies of "==" vs "===". They'll use "==" like they're used to without realizing that the thing that's going to behave like they're accustomed to is actually "===".

I agree with this post.

DirtyDiaperMask
Aug 11, 2003

by Ozmaugh

Easy Mac posted:

Sounds like php is terrible and should never be used. What is the ultimate language to use for the web.

Python :smug:

I think PHP is useful as an object lesson, it demonstrates that the success of a language has little to do with the language design and more with stuff like the size of its ecosystem and user base and simple path dependence.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

DirtyDiaperMask posted:

Python :smug:

I think PHP is useful as an object lesson, it demonstrates that the success of a language has little to do with the language design and more with stuff like the size of its ecosystem and user base and simple path dependence.

But at some point, PHP didn't have an ecosystem or a user base.

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.

Wheany posted:

But at some point, PHP didn't have an ecosystem or a user base.

At that time, wasn't the choice for web scripting pretty much between PHP, Perl 5.0, TCL, and C (yes, people wrote CGI programs in C) where PHP handled CGI and (to some extent) templating for you while the others made you do it all yourself? In that context, PHP was the sane choice.

Mr.Radar fucked around with this message at 03:16 on Dec 12, 2010

tef
May 30, 2004

-> some l-system crap ->

Hammerite posted:

There are many situations in which type-safety is required, in which case it is available.

If I ever need to parse phone numbers in octal to make a comparison, i'll use php :v:

tef
May 30, 2004

-> some l-system crap ->
The weird bit

I don't hear other people who write websites or code wishing for php's == vs === in other languages. And yet somehow 'it's useful'.

It is a false utility - you exchange a legion of bugs for a handful of keypresses.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

tef posted:

The weird bit

I don't hear other people who write websites or code wishing for php's == vs === in other languages. And yet somehow 'it's useful'.

It is a false utility - you exchange a legion of bugs for a handful of keypresses.

I think it's like Java developers claiming that anonymous inner classes are "useful".

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Jabor posted:

I think it's like Java developers claiming that anonymous inner classes are "useful".

It is ... uh ..... :eng99:

Now I feel bad :(

Vanadium
Jan 8, 2005

Anonymous inner classes are kind of useful, they are a perfect analogue to anonymous functions that capture scope, which everybody is a fan of.

Karanth
Dec 25, 2003
I need to finish Xenogears sometime, damn it.

Vanadium posted:

Anonymous inner classes are kind of useful, they are a perfect analogue to anonymous functions that capture scope, which everybody is a fan of.

This. They're lambdas expressed exactly how the vm would see them. The syntax is also perfectly in line with the rest of Java: extra verbose every time you use it for the sake of consistency with the one time in a hundred when you want to make use of one of the extra capabilities of the feature. :v:

Vanadium
Jan 8, 2005

Obligatory kneejerk "java's new Runnable() { public static void run() { } } is equivalent to haskell's " syntax complaint

NotShadowStar
Sep 20, 2000

Karanth posted:

This. They're lambdas expressed exactly how the vm would see them. The syntax is also perfectly in line with the rest of Java: extra verbose every time you use it for the sake of consistency with the one time in a hundred when you want to make use of one of the extra capabilities of the feature. :v:

Java 7
code:
int i4 = #(Number x)(x.intValue()).(new Float(3.0f)); //i4 - 3
Yep.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
NotShadowStar: Closures are most likely going to wait for Java 8, and thankfully there have been a number of syntax proposals which aren't that nasty looking.

Vanadium
Jan 8, 2005

It should be, like, [](Number x)(whatever)

Edit: I mean, it is important to maintain compatibility with C++, as "as C++ and Java have bunch of similarities, a copy and paste of the source code with a few modifications should be enough to convert and recompile it" (non-coder non-code quote, probably cheating)

Vanadium fucked around with this message at 19:14 on Dec 12, 2010

Chairman Steve
Mar 9, 2007
Whiter than sour cream

Vanadium posted:

Obligatory kneejerk "java's new Runnable() { public static void run() { } } is equivalent to haskell's " syntax complaint

I used to do this until I read this in the Javadoc of Runnable:

quote:

The Runnable interface should be implemented by any class whose instances are intended to be executed by a thread.

Unless you're giving it to a Thread object to run, come up with your own interface to implement. I know that, in reality, someone will probably never use your Runnable object inappropriately, but it seems like a violation of the interface contract to treat any Runnable object as a closure.

Not to mention, it potentially makes your code more confusing. Runnable's definition of behavior is so vague that, if you have an object that takes a Runnable object, it may not be immediately clear what the purpose of that received Runnable object should be. I know, people can read your Javadoc, but every little bit of ambiguity can add up...

Adbot
ADBOT LOVES YOU

MononcQc
May 29, 2007

tef posted:

The weird bit

I don't hear other people who write websites or code wishing for php's == vs === in other languages. And yet somehow 'it's useful'.

It is a false utility - you exchange a legion of bugs for a handful of keypresses.

In Rome...

Other languages usually have some kind of coping mechanism for converting HTTP headers into something different and usable. It is not very useful, which is why I'd guess most people don't need them the same way they might need higher order functions or closures, which are objectively much harder to replace when it comes to abstractions.

There's a spectrum between "I use this all the time" and "I wouldn't notice if it wasn't there". '==' isn't rated very high on that spectrum.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply