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
ijustam
Jun 20, 2005

You can have brackets close in separate code chunks? :psyduck:

Adbot
ADBOT LOVES YOU

Vanadium
Jan 8, 2005

How else would you do this?

php:
<? for ($i = 0; $i < 5; ++$i) { ?>
welp
<? } ?>

Contero
Mar 28, 2004

php:
<? WELP: ?>
welp
<? goto WELP; ?>

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
Why does a modern programming language still have gotos!?

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Ensign Expendable posted:

Why does a modern programming language still have gotos!?
PHP added gotos in 2009, actually.

No Safe Word
Feb 26, 2005

Ensign Expendable posted:

Why does a modern programming language still have gotos!?

Modern programming languages having gotos is not a horror.

PHP having gotos probably is, and them explicitly adding them ~15 years after the language came about is probably a bigger one

The Gripper
Sep 14, 2004
i am winner

No Safe Word posted:

Modern programming languages having gotos is not a horror.

PHP having gotos probably is, and them explicitly adding them ~15 years after the language came about is probably a bigger one
The official docs even include an XKCD comic about using gotos http://php.net/manual/en/control-structures.goto.php

baquerd
Jul 2, 2007

by FactsAreUseless

Ensign Expendable posted:

Why does a modern programming language still have gotos!?

Every so often explicit code jumps are useful, here's a fragment I recently used one in. While you can write this block in other ways, I like the flow better this way.

code:
  nextList:
  for (String key : thresholdMap.keySet()) {
    ArrayList<String> currAdditiveKeys = new ArrayList<String>(Arrays.asList(key.split("\\+")));

    if (currAdditiveKeys.size() > 1) {
      for (ArrayList<String> testKeyList : additiveThresholdKeys) {
        if (testKeyList.equals(currAdditiveKeys)) {
          continue nextList;
        }
      }
      additiveThresholdKeys.add(currAdditiveKeys);
    }
  }

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
php:
<?php
function h3($body) {
?>
<h3><?= $body ?></h3>
<?php
}

h3("One");
h3("Two");
?>

code:
<h3>One</h3>
<h3>Two</h3>

baquerd
Jul 2, 2007

by FactsAreUseless

Suspicious Dish posted:

<?= $body ?>

What is this special "<?=" opener? I can't find any docs on that.

Freaksaus
Jun 13, 2007

Grimey Drawer

baquerd posted:

What is this special "<?=" opener? I can't find any docs on that.

I believe that just does an echo.

MasterSlowPoke
Oct 9, 2005

Our courage will pull us through
It's short for "<? echo ".

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

No Safe Word posted:

Modern programming languages having gotos is not a horror.

PHP having gotos probably is, and them explicitly adding them ~15 years after the language came about is probably a bigger one

I use gotos in PHP to abandon deep foreach loops because break N; is bullshit.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
trex eaterofcadrs: I find that when I have deeply nested loops which I might want to exit, it's better to break the loop nest out into a separate function and do an early return.

I've actually spent years trying to find a situation where a labeled break is the cleanest way to solve a problem, and I've always come up with a different solution. The best defense of goto that I've seen is implementing state machines in procedural languages.

Toady
Jan 12, 2009

Ensign Expendable posted:

Why does a modern programming language still have gotos!?

goto isn't automatically bad. Example: http://kerneltrap.org/node/553/2131

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Would anybody consider it to be a design horror whenever you hear somebody talk about "adding a layer," then seeing the layers being represented as a bunch of boxes with arrows pointing all over the place? Wouldn't you expect layers to, say, layer?

If that is so odd, would you consider it to be a megahorror when somebody proposes a layer to poll on a database to find new operations to do?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Internet Janitor posted:

trex eaterofcadrs: I find that when I have deeply nested loops which I might want to exit, it's better to break the loop nest out into a separate function and do an early return.

I've actually spent years trying to find a situation where a labeled break is the cleanest way to solve a problem, and I've always come up with a different solution. The best defense of goto that I've seen is implementing state machines in procedural languages.

I have one case where I use goto; matched with a label, out:

code:
static Texture *
load_texture_from_name (char *name)
{
  Texture *texture = NULL;
  char *filename;
  FILE *fp;
  png_structp png_ptr = NULL;
  png_infop info_ptr = NULL;

  filename = asprintf (TEXTURE_DIR "%s.png", name);
  fp = fopen (filename, "rb");

  png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
  if (png_ptr == NULL)
    goto out;

  info_ptr = png_create_info_struct (png_ptr);
  if (info_ptr == NULL)
    goto out;

  if (setjmp (png_jumpbuf (png_ptr))
    goto out;

  /* Not going to include full IO stuff, consult libpng docs */

out:
  free (filename);
  fclose (fp);
  png_destroy_read_struct (png_ptr, info_ptr, NULL);

  return texture;
}
That is, memory management in C sucks.

Contero
Mar 28, 2004

Internet Janitor posted:

trex eaterofcadrs: I find that when I have deeply nested loops which I might want to exit, it's better to break the loop nest out into a separate function and do an early return.

I've actually spent years trying to find a situation where a labeled break is the cleanest way to solve a problem, and I've always come up with a different solution. The best defense of goto that I've seen is implementing state machines in procedural languages.

I haven't had to use a goto or labelled break in years, but I certainly feel more comfortable knowing they're available.

hobbesmaster
Jan 28, 2008

Ensign Expendable posted:

Why does a modern programming language still have gotos!?

A reminder that Djikstra wrote that paper in 1968. Take a look at arithmetic ifs and imagine trying to get anything done in FORTRAN circa 1968.

Rothon
Jan 4, 2012

Suspicious Dish posted:

I have one case where I use goto; matched with a label, out:

code:
static Texture *
load_texture_from_name (char *name)
{
  Texture *texture = NULL;
  char *filename;
  FILE *fp;
  png_structp png_ptr = NULL;
  png_infop info_ptr = NULL;

  filename = asprintf (TEXTURE_DIR "%s.png", name);
  fp = fopen (filename, "rb");

  png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
  if (png_ptr == NULL)
    goto out;

  info_ptr = png_create_info_struct (png_ptr);
  if (info_ptr == NULL)
    goto out;

  if (setjmp (png_jumpbuf (png_ptr))
    goto out;

  /* Not going to include full IO stuff, consult libpng docs */

out:
  free (filename);
  fclose (fp);
  png_destroy_read_struct (png_ptr, info_ptr, NULL);

  return texture;
}
That is, memory management in C sucks.

Another nice feature is that execution falls through labels nicely, so you can do more complicated cleanup like this.

qntm
Jun 17, 2009
In retrospect I have no problem with goto as long as it doesn't jump backwards through the code somehow.

Now, in terms of nonlinear code execution, here's the real horror.

NovemberMike
Dec 28, 2008

Suspicious Dish posted:

php:
<?php
function h3($body) {
?>
<h3><?= $body ?></h3>
<?php
}

h3("One");
h3("Two");
?>

code:
<h3>One</h3>
<h3>Two</h3>

Wait, this actually works? This just seems wrong to me for some reason.

pigdog
Apr 23, 2004

by Smythe

baquerd posted:

Every so often explicit code jumps are useful, here's a fragment I recently used one in. While you can write this block in other ways, I like the flow better this way.

code:
  nextList:
  for (String key : thresholdMap.keySet()) {
    ArrayList<String> currAdditiveKeys = new ArrayList<String>(Arrays.asList(key.split("\\+")));

    if (currAdditiveKeys.size() > 1) {
      for (ArrayList<String> testKeyList : additiveThresholdKeys) {
        if (testKeyList.equals(currAdditiveKeys)) {
          continue nextList;
        }
      }
      additiveThresholdKeys.add(currAdditiveKeys);
    }
  }

I don't have a compiler at hand at the moment, so this is straight from the hip, but I think this could be written as

code:
for (String key : thresholdMap.keySet()) {
	ArrayList<String> currAdditiveKeys = new ArrayList<String>(Arrays.asList(key.split("\\+")));
	if (currAdditiveKeys.size()>1 && !additiveTresholdKeys.contains(currAdditiveKeys)) {
		additiveTresholdKeys.add(currAdditiveKeys);
	}
}

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?

NovemberMike posted:

Wait, this actually works? This just seems wrong to me for some reason.

If PHP had a slogan, that would be it.

Plorkyeran
Mar 22, 2007

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

NovemberMike posted:

Wait, this actually works? This just seems wrong to me for some reason.
It's perfectly sensible if you think of PHP as a templating language rather than a general-purpose programming language. Actually switching between PHP and HTML when using PHP as a programming language is a horror, of course.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Plorkyeran posted:

It's perfectly sensible if you think of PHP as a templating language rather than a general-purpose programming language. Actually switching between PHP and HTML when using PHP as a programming language is a horror, of course.

Yeah, all php is doing is building an output buffer and writing it to some pipe/stream. Escaping is really "shorthand" for buffer concatenation.

Zhentar
Sep 28, 2003

Brilliant Master Genius
I'm pretty sure the ability to do things like that is the only reason most people put up with PHP at all.


Edit: VB.NET can do similar things with XML Literals:
code:
Dim xml = <?xml version="1.0"?>
          <menu>
              <course name="appetizer">
                  <%= From m In menu _
                      Where m.Course = "appetizer" _
                      Select <dish><%= m.Food %></dish> _
                  %>
              </course>
              <course name="main">
                  <%= From m In menu _
                      Where m.Course = "main" _
                      Select <dish><%= m.Food %></dish> _
                  %>
              </course>
              <course name="dessert">
                  <%= From m In menu _
                      Where m.Course = "dessert" _
                      Select <dish><%= m.Food %></dish> _
                  %>
              </course>
          </menu>

Zhentar fucked around with this message at 23:53 on Apr 19, 2012

baquerd
Jul 2, 2007

by FactsAreUseless

pigdog posted:

I don't have a compiler at hand at the moment, so this is straight from the hip, but I think this could be written as

code:
for (String key : thresholdMap.keySet()) {
	ArrayList<String> currAdditiveKeys = new ArrayList<String>(Arrays.asList(key.split("\\+")));
	if (currAdditiveKeys.size()>1 && !additiveTresholdKeys.contains(currAdditiveKeys)) {
		additiveTresholdKeys.add(currAdditiveKeys);
	}
}

Yeah you're right, I did what was going to happen behind the scenes needlessly there.

pseudorandom name
May 6, 2007

hobbesmaster posted:

A reminder that Djikstra wrote that paper in 1968. Take a look at arithmetic ifs and imagine trying to get anything done in FORTRAN circa 1968.

Yeah, you have to remember that paper isn't so much against goto as it is advocating the use of language constructs like loops, blocks, else clauses, and switch statements, which weren't common at the time.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Suspicious Dish posted:

php:
<?php
function h3($body) {
?>
<h3><?= $body ?></h3>
<?php
}

h3("One");
h3("Two");
?>

code:
<h3>One</h3>
<h3>Two</h3>

The only coding horror is that he doesn't bother just using the short tags since he's already ruined it by having a "<?="

Why bother with "<?php" if you're already guaranteeing your script to fail when someone turns off short tag support.

Edit: Ah apparently since 5.4 <?= is accessible regardless of whether short tags is on or off... Certainly not a coding (implementation?) horror. No siree bob.

Strong Sauce fucked around with this message at 01:09 on Apr 20, 2012

tef
May 30, 2004

-> some l-system crap ->

Vanadium posted:

How else would you do this?

php:
<? for ($i = 0; $i < 5; ++$i) { ?>
welp
<? } ?>

like so

php:
<? for ($i = 0; $i < 5; ++$i): ?>
welp
<? endfor ?>

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

tef posted:

like so

php:
<? for ($i = 0; $i < 5; ++$i): ?>
welp
<? endfor ?>

Probably the absolute best aspect of php.

Contero
Mar 28, 2004

Plorkyeran posted:

Actually switching between PHP and HTML when using PHP as a programming language is a horror, of course.

I'm not a professional web dev by any means, but why is this such a horror?

The function makes sense if you think about it differently:

php:
<?php
function h3($body) {
   ?><h3><?= $body ?></h3><? 
}

h3("One");
h3("Two");
?>
Where

?><h3><?= $body ?></h3><?

expands to:

echo "<h3>" . $body . "</h3>"

It's godawfully ugly when it's spaced out like that of course. I just think of these kind of languages as having statement-level automatically-printing html literals.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice
ASP.Net will let you do the same thing, so do the MVC partial views. It's just shorthand for wrapping the text between the code bits in a string then doing an output stream write of that string.

Wait, it's PHP it probably does something much dumber than that...

Plorkyeran
Mar 22, 2007

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

Contero posted:

I'm not a professional web dev by any means, but why is this such a horror?
"Don't mix HTML generation and program logic" is pretty much the most basic rule for designing a web application that is not an unmaintainable mess. A straightforward conclusion based on this is that a feature which makes it easier to embed HTML should only be used when PHP is being used as a templating engine, not as a general-purpose programming language.

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde

Contero posted:

I'm not a professional web dev by any means, but why is this such a horror?
It's a horror because the dev is going out of his way to avoid HTML templating in an HTML template language. It's not unique to PHP. I've seen the same thing in Mason from devs who just don't "get" templates.

Scaevolus
Apr 16, 2007

There's a "new" OpenSSL vulnerability in the parser for ASN.1, a good example of the hilarious overcomplication that design-by-committee causes.

Some people are smart:

djmdjm posted:

FYI OpenSSH's sshd is not vulnerable, despite using OpenSSL. Back in 2002 and after a different ASN.1 bug, Markus Friedl observed that RSA verification used the OpenSSL's full ASN.1 parser to parse PKCS#1 RSA signatures despite them having an almost entirely fixed format under the parameters used in the SSH protocol.
He wrote a minimal RSA signature verification implementation that we've used ever since. This is the eighth bug that it has saved us from in the last ten years.

Some are cheeky as well:

mdowd posted:

I published that bug in our book (TAOSSA) in 2006. I just neglected to mention it was 0day.

Contero
Mar 28, 2004

Plorkyeran posted:

"Don't mix HTML generation and program logic" is pretty much the most basic rule for designing a web application that is not an unmaintainable mess. A straightforward conclusion based on this is that a feature which makes it easier to embed HTML should only be used when PHP is being used as a templating engine, not as a general-purpose programming language.

If all you're saying is "separate business logic from presentation" then I'm completely on board with you.

I think you've confused me by using "program logic" (is a loop not program logic?) and "general-purpose programming" to mean complicated or application specific logic:

Plorkyeran posted:

Actually switching between PHP and HTML when using PHP as a programming language is a horror, of course.

If not as a programming language I'm not sure how you're supposed to use PHP.

The way you worded it made it sound like you were advocating something like this:

code:
<center>
<table>
<c:forEach var="book" begin="0" items="${bookDB.books}">
  ...
<c:set var="salePrice" value="${book.price * .85}" />
  <c:set var="price" value="${book.price}" />
  <c:choose>
    <c:when test="${book.onSale}" >
      <jsp:invoke fragment="onSale" />
    </c:when>
    <c:otherwise>
      <jsp:invoke fragment="normalPrice"/>
    </c:otherwise>
  </c:choose>
...
</table>
</center> 
Which I consider to be a horror. Remember kids, if text isn't formatted as XML, it's literally impossible to parse!

duck monster
Dec 15, 2004

Gazpacho posted:

If you consider COBOL dead maybe your "sense of the industry" isn't quite as good as you think. :smug:

I spent the first part of my career as a COBOL programmer. Its not the language thats dead, but me who is dead, inside. Terrible terrible language.

But yeah, theres still billions of lines of that godawful poo poo out there.

Adbot
ADBOT LOVES YOU

duck monster
Dec 15, 2004

Zamujasa posted:

php:
<?
// END CODE FROM testcreateinfo.php
}}}}}}
}// goodtogo = 1, infoid passed is available to the passed username/password
 }// end of check to see if info id is passed
} // end of valid user/pass test and info return
} // end of is api command 'doeverything'
mysql_close($con);
} // End of is api functions?>
:smithicide:

(The lack of formatting here isn't some error, there are about 4 copies of this file and this is how they are: left justified. boss doesn't believe in indentation because he does coding on a 1024x768 TV and indents are just wasted space. :suicide:)


Edit: Oh, the snip from the last post is from this file, too, but run through a code reformatter. (Rest assured, it was left-justified too.)

quote:

} // end of is api command 'doeverything'
hahaha

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