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"

tef posted:

'we don't write cgi-scripts any more'
speak for yourself :colbert:

Adbot
ADBOT LOVES YOU

NotShadowStar
Sep 20, 2000
Hell yeah, php.png going into the archives.

The Reaganomicon
Oct 14, 2010

by Lowtax

tef posted:



Reminds me of Javascript's if([0]&&[0]==false)

tef
May 30, 2004

-> some l-system crap ->

Janin posted:

speak for yourself :colbert:

goondolences, bro

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



The Reaganomicon posted:

Reminds me of Javascript's if([0]&&[0]==false)

What would you expect the logical and of two arrays to be?

king_kilr
May 25, 2007

Munkeymon posted:

What would you expect the logical and of two arrays to be?

I'd expect an array, in a boolean context, to evaluate as bool(array.length). Javascript has this lovely thing where one item arrays are equivalent to array[0].

The Reaganomicon
Oct 14, 2010

by Lowtax

Munkeymon posted:

What would you expect the logical and of two arrays to be?

I would expect it to be consistent. a&&b is true iff both a and b are true. [0]&&[0] is false, thus [0] must be false. But if([0]) is true.

:iiam:

As an aside, I understand where this comes from, but holy poo poo Boole is spinnin' in he grave.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA
interncode

code:
			exec('from ...models.task import %s' % task_type)
			exec('task = %s.objects.get(id=id)' % task_type)
			getattr(task, method_name)()
First I was like :confused:, then I was like :monocle: and then I was like :cry:

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

tef posted:

I gave half a talk on php last night to a local techie startup group - the first half was a php apologist - my talk wasn't so flattering: 'php: a great way to write cgi scripts' and 'we don't write cgi-scripts any more'

anyway Otto came up with this slide and I figured I'd post it here :3:



I was really hoping that this matrix was asymmetric, because that would have just been icing on the cake.

nielsm
Jun 1, 2009



From 2 pages ago, but I had to comment on this.

Xenogenesis posted:

OT: I present beautiful handwritten SQL for a small Rails app:
code:
      query = %Q{
        SELECT DISTINCT ON (s.user_id, s.chart_id) s.*
          FROM scores AS s
          JOIN charts AS c
            ON (c.id = s.chart_id)
            #{chart ?
            "WHERE c.id = ?" :
            "WHERE c.key_id = ?
              AND c.game_id = ?"
            }
        AND s.id IN (
          SELECT s2.id
          FROM scores AS s2
          LEFT JOIN scores AS s3
            ON (s2.chart_id = s3.chart_id
                AND s2.user_id = s3.user_id
                AND s2.judgement < s3.judgement)
          WHERE s2.chart_id = s.chart_id
            AND s3.judgement IS NULL
          ORDER BY s2.judgement, s2.score DESC
          #{"LIMIT ?" unless limit.nil?})
        ORDER BY s.user_id, s.chart_id, s.judgement, s.score DESC
      }

Seriously.

What is that subquery supposed to be doing at all? The join in it being a no-op doesn't exactly help.

Join on (blah and foo < s3.judgement).
Where s3.judgement is null.

:suicide:

NotShadowStar
Sep 20, 2000
Holy balls I noticed that 0 == "" and 0 == null in PHP. Also "string" == 0 in PHP.

This is literally the worst thing created. At least Perl has some hosed up logic behind it's typeless crazytown. img-php.png indeed.

MononcQc
May 29, 2007

NotShadowStar posted:

Holy balls I noticed that 0 == "" and 0 == null in PHP. Also "string" == 0 in PHP.

This is literally the worst thing created. At least Perl has some hosed up logic behind it's typeless crazytown. img-php.png indeed.

There is some logic behind it. 0 and "" are basically seen as 'empty', and 'null' can also be empty when doing the type juggling thing. You can use '===' for strict comparisons, is_null() for null values, length of the string, etc.

As for "string" == 0, this is because when you use loose comparison, it will try to read strings as numbers. As an example "43.2" == 43.2. When it hits a word it can't handle, it gives '0', as in 'not a string'. Generally speaking, this is used so you can write
php:
<?
if ($any_data_structure)
  return "data structure contains something";
else
  return "data structure is empty";
?>
And it will work with empty arrays, empty strings, the number 0, etc. It actually simplifies semantics on that point. Then on the other hand, you have empty(), which could be used the same way by restricting the juggling to a single function.

This is pretty terrible in a lot of cases, but that kind of type juggling crap is what makes PHP very quick to use for web stuff. You can take a string parameter from $_POST or $_GET and compare it to a number or whatever and still get what you want. Note that you can also cast "324" as an int and it will do the type conversion for you.

I would hate going back to PHP for my job, but for quick projects where you don't give a poo poo (which is a lot of web dev stuff on low budget), it's a perfect chainsaw language.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



The Reaganomicon posted:

I would expect it to be consistent. a&&b is true iff both a and b are true. [0]&&[0] is false, thus [0] must be false. But if([0]) is true.

:iiam:

As an aside, I understand where this comes from, but holy poo poo Boole is spinnin' in he grave.

Ah poo poo - I didn't think about it and just checked that [0] == false, which I actually find much more confusing than if([0]) being true. I guess I need to go reread the part of the spec dealing with type manging.

king_kilr posted:

I'd expect an array, in a boolean context, to evaluate as bool(array.length). Javascript has this lovely thing where one item arrays are equivalent to array[0].

But you can set array.length to whatever you want, so having a length doesn't even mean there's anything in there. The fact that there's a non-null, non-undefined object that I can ask about a length property would mean that it ought to be true in a boolean context (in Javascript - if you are reading this, please don't apply that as a blanket statement to all languages or to your language of choice).

Also:
code:
[0] == [0] //false
:confused:

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
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).

McGlockenshire
Dec 16, 2005

GOLLOCKS!

NotShadowStar posted:

Holy balls I noticed that 0 == "" and 0 == null in PHP. Also "string" == 0 in PHP.

This is literally the worst thing created. At least Perl has some hosed up logic behind it's typeless crazytown. img-php.png indeed.
code:
[mcg@mcg-workstation ~]$ php --interactive
Interactive shell

php > var_export( "string" == 0 ); // Strings are numeric zero.
true
php > var_export( (bool)"string" ); // Strings are boolean true.
true
php > var_export( true == 0 ); // Boolean true is not zreo.
false
php > echo PHP_VERSION;
5.3.3
I hate PHP so, so much.

MononcQc
May 29, 2007

McGlockenshire posted:

code:
[mcg@mcg-workstation ~]$ php --interactive
Interactive shell

php > var_export( "string" == 0 ); // Strings are numeric zero.
true
php > var_export( (bool)"string" ); // Strings are boolean true.
true
php > var_export( true == 0 ); // Boolean true is not zreo.
false
php > echo PHP_VERSION;
5.3.3
I hate PHP so, so much.
what is type juggling, hjal^p!
The result depends on the other side of the comparison and is always consistent with regards to that. It also supports === as a strict comparison operator.

php:
<?
php > var_export( "string" === 0 );
false
php > var_export( (bool)"string" );
true
php > var_export( true === 0 ); 
false
?>
I agree with Hammerite and consider this to be a dead horse.

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog
We'll stop bitching about PHP when people stop writing PHP applications.

Nevett
Aug 31, 2001

Munkeymon posted:

Also:
code:
[0] == [0] //false
:confused:

Not sure why this is confusing. Surely its just creating two separate arrays and comparing them by reference.

Spectral Elvis
Jul 23, 2007

A conversation today reminded me of this ... thing of wonder.

A product we're phasing out has a core (ahem) generic container class used to store all kinds of things. A core container class that masquerades as a vector. Taking a method at random shows the jewels within.

code:
XXObject * Vector::GetItemAt(int index)
{
	VectorObject *current;

	if(!mFirst)
		return(0);

	current=mFirst;

	for(int i=0;i<index;++i) {
		if(!current)
			return(0);
		current=current->GetNext();
	}

	return(current?current->GetData():0);
}
Strangely enough, the decision to replace this product was made before it was even released.

Spectral Elvis fucked around with this message at 21:34 on Dec 9, 2010

tef
May 30, 2004

-> some l-system crap ->

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.

You are claiming to be a painter but all you do is cover walls in your own faeces because you can't get the paint cans open.

Hammerite
Mar 9, 2007

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

tef posted:

You are claiming to be a painter but all you do is cover walls in your own faeces because you can't get the paint cans open.

If you want to slate PHP, I can think of at least 10 things that are more worthy of criticism than type-juggling.

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:

Hammerite posted:

If you want to slate PHP, I can think of at least 10 things that are more worthy of criticism than type-juggling.

Indeed. Beside the PHP Truth table in my cubicle I have a list that goes:

strpos: haystack, needle
array_search: needle, haystack
link: name, target

etc., etc.

tef
May 30, 2004

-> some l-system crap ->

Hammerite posted:

If you want to slate PHP, I can think of at least 10 things that are more worthy of criticism than type-juggling.

I have done many many times http://forums.somethingawful.com/showthread.php?threadid=2803713&userid=0&perpage=40&pagenumber=140#post382500354

This is the list of stuff that's wrong behind the inconsistently named library, with inconsistent function arguments, functions that work differently across platforms, the grammar being crippled, the type safety, the object system, the reference system, the vm itself.

php handles writing cgi scripts but doesn't handle any of the features of a modern web application. people say 'hurr' it is a language 'hurr' that mostly is embedded in apache
and by default just accepts text until <?php. it is a templating language for cgi scripts. php is a domain specific language, just a level much lower than you'd get with a general purpose language and framework.

php: a templating language so unfit for purpose that it spawned template libraries for it

tef fucked around with this message at 22:02 on Dec 9, 2010

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"

tef posted:

php handles writing cgi scripts but doesn't handle any of the features of a modern web application
that's the second time you've dissed cgi, and I'mma let you continue, but PHP is the worst horror of all time

Seriously, CGI is a dead-simple way to get basic dynamic webpages working. It doesn't need any huge runtime libraries, any virtual machines; just compile your page, scp it, and it'll work on anything from a reflashed router to shared hosting to clusters.

Also, PHP (as far as I know) can't be used to write CGI pages; it depends on an Apache/nginx/whatever module that runs the scripts themselves. I suppose you could write a CGI page using the PHP interpreter, but that's even worse than just plain ol' php

Finally, CGI can do everything a modern "web application" (I hate that loving marketing phrase) can; its only disadvantage is performance, and that's solved easily by using FastCGI

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
How'd the talk go btw tef? Also I will read the dns thing you wrote up when I get the chance, probably this weekend (doing interview prep for a Real Engineering(tm) opportunity atm)

wwb
Aug 17, 2004

quote:

Also, PHP (as far as I know) can't be used to write CGI pages; it depends on an Apache/nginx/whatever module that runs the scripts themselves. I suppose you could write a CGI page using the PHP interpreter, but that's even worse than just plain ol' php

The CGI-style is the default implementation on alot of platforms. Was so common they invented fast cgi to handle it.

PHP: a retarded tool for retarded people from a retarded age.

tef
May 30, 2004

-> some l-system crap ->

Otto Skorzeny posted:

How'd the talk go btw tef? Also I will read the dns thing you wrote up when I get the chance, probably this weekend (doing interview prep for a Real Engineering(tm) opportunity atm)

it went well

we mostly went hay, use the right tool for the job, and the talks contrasted well

I mostly got asked how do you give a talk for 20 minutes without breathing.

the video will be posted this week.

the ddns thing needs *a lot* more work and I'm gonna work on that when I finish my actual work and stop being distracted by writing an article on parsing.

tef
May 30, 2004

-> some l-system crap ->

Janin posted:

that's the second time you've dissed cgi, and I'mma let you continue, but PHP is the worst horror of all time

Finally, CGI can do everything a modern "web application" (I hate that loving marketing phrase) can; its only disadvantage is performance, and that's solved easily by using FastCGI

just sayin, modern web apps are more than just cgi, and php is barely that. ain't dissin on cgi, it's good for what it does. what i'm sayin is that you don't want to be writing in php any more than you want to be writing in c bindings for cgi, it's a lot of effort.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Nevett posted:

Not sure why this is confusing. Surely its just creating two separate arrays and comparing them by reference.

That was in response to his second sentace

quote:

Javascript has this lovely thing where one item arrays are equivalent to array[0].

Xenogenesis
Nov 8, 2005

nielsm posted:

From 2 pages ago, but I had to comment on this.


Seriously.

What is that subquery supposed to be doing at all? The join in it being a no-op doesn't exactly help.

Join on (blah and foo < s3.judgement).
Where s3.judgement is null.

:suicide:

Hahaha, you wish that join was useless.

The self join makes sure all the records on the left had a higher judgement than those on the right. The WHERE s3.judgement IS NULL removes all the rows from which there was a higher judgement.

Basically it's selecting the highest judgements from the table without using group by and aggregate functions (so I can actually get the ids I need).

I don't know how I live with myself either.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

NotShadowStar posted:

Holy balls I noticed that 0 == "" and 0 == null in PHP. Also "string" == 0 in PHP.

This is literally the worst thing created. At least Perl has some hosed up logic behind it's typeless crazytown. img-php.png indeed.

But "" != "string." a=b, b=c, but a!=c

So transitivity is apparently not a property of the == operator.

Also the case with "php", "0" and 0.

Edit: I know why this is the case, but it just seems so wrong.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

HappyHippo posted:

So transitivity is apparently not a property of the == operator.
If the documentation didn't call == the equality operator I'm not sure I'd actually have a problem with this. It does have a real equality operator (===), and there isn't really any reason to expect the fuzzy similarity operator to be transitive. Being different from other languages is not a horror by itself.

NotShadowStar
Sep 20, 2000
== and === is a horror in any language. There is never any need to do == because of the hosed-up ness of it all. Same with Javascript.

http://developer.yahoo.com/yui/theater/video.php?v=crockonjs-2

quote:

We have equality operators. Unfortunately they do type coercion, and they do type coercion before they compare things for equality, and that coercion can cause false positives, which is a bad thing. So I recommend to always use the triple equal operator instead, which is unfortunate, because it’s uglier, but you have to. The reason for that is… Try to find the pattern in here. There’s no transitivity at all. Transitivity says that if A and B are equal, and B and C are equal, then A and C should be equal, but they’re not. Again, we’ve got these mathematical absurdities going on where transitivity doesn’t hold, and it should. My expectation is that all of these should produce false, because in every case what’s on the left side is different than what’s on the right side. With the triple equal operator, it does the right thing; you actually get false in all the cases. So I recommend that you always, always use the triple equal operator. There might be times when you think you want the type coercion, but you should only do that if you actually understand what the type coercion will do, and I challenge anybody looking at this to guess what the conventions are.

Shavnir
Apr 5, 2005

A MAN'S DREAM CAN NEVER DIE
Apparently in MySQL 'a' = 'b' is false, but 'a' = 'b' = 'c' is true. :toot:

Cervix-A-Lot
Sep 29, 2006
Cheeeeesy
Sounds like php is terrible and should never be used. What is the ultimate language to use for the web.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

Easy Mac posted:

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

LISP MOTHERFUCKER THE ANSWER IS ALWAYS LISP

tef
May 30, 2004

-> some l-system crap ->

Mr. Wynand posted:

LISP MOTHERFUCKER THE ANSWER IS ALWAYS LISP

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

nielsm
Jun 1, 2009



Xenogenesis posted:

Hahaha, you wish that join was useless.

I see now why it works... I simply forgot to consider the case of the join failing to find any matches.



Also PHP is fine to use as long as you know why it sucks. Its design still makes more sense than mIRC Script.

tef
May 30, 2004

-> some l-system crap ->

nielsm posted:

Also PHP is fine to use as long as you know why it sucks. Its design still makes more sense than mIRC Script.

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

Adbot
ADBOT LOVES YOU

NotShadowStar
Sep 20, 2000

nielsm posted:

Also PHP is fine to use as long as you know why it sucks. Its design still makes more sense than mIRC Script.

There's a huge logical inconsistency in this statement.

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