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
Edison was a dick
Apr 3, 2010

direct current :roboluv: only

geonetix posted:

I'm not actually sure why, it's probably because I learned to computer that way. And I cannot live without "bindkey -v" to enable vi-like editing. If somebody has an actual valid pro/cons table of zsh vs bash vs (t)csh I'll be the first to read it.

code:
set -o vi
promises to do that in bash, but I've not done that in zsh so I can't compare.

Also I found csh considered harmful a while back, but never having used csh, I can't say how valid it is.

Edison was a dick fucked around with this message at 23:15 on Jul 24, 2012

Adbot
ADBOT LOVES YOU

theratking
Jan 18, 2012


love this poo poo.

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.
This is what happens if you let a front-end guy write your Django app.

Python code:
from django.db import models

class Data(models.Model):
    key = models.TextField()
    value = models.TextField()
You are looking at the entire models.py. :suicide:

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


theratking posted:



love this poo poo.

Github issues are pretty bad, but I wouldn't award them full-blown horror status

how!!
Nov 19, 2011

by angerbot

Sinestro posted:

This is what happens if you let a front-end guy write your Django app.

Python code:
from django.db import models

class Data(models.Model):
    key = models.TextField()
    value = models.TextField()
You are looking at the entire models.py. :suicide:

I recently phone interviewed with a company who gave me access to their github, and their code was exactly like this. They had one model called DictionaryStruct which was exactly like the one you posted, which was used for everything. They offered me a very good salary, but I had to decline their offer.

Zamujasa
Oct 27, 2010



Bread Liar

Sinestro posted:

This is what happens if you let a front-end guy write your Django app.

Python code:
from django.db import models

class Data(models.Model):
    key = models.TextField()
    value = models.TextField()
You are looking at the entire models.py. :suicide:
Boss did something like this (I think) in C#, where every single "global" value he created was its own class with a single private property, with the exact same get/set code (that is, copy/return the value, nothing else).

I combined them all into one class called GlobalVars and accessed the properties from there.


Not really a horror to use global variables in this circumstance, since we were wrapping around another app, and the whole disaster ran for a few seconds to get some data and died.


Aside: Bosscode has taken the "pay less, pay often" method of coding again, adding code to set the default timezone to every file instead of just setting the drat setting in php.ini once.

Then again, this the same person who copy-pastes the same "header" (comprised of two function definitions that are the exact same, but with a number in the name of one of them), so... :rolleyes:

theratking
Jan 18, 2012

Doc Hawkins posted:

Github issues are pretty bad, but I wouldn't award them full-blown horror status

I'd say the horror is that my direct supervisor doesn't really fully understand the concept of an error or an error message. His response to "what's the 500 error" is "it's a 500 error."

ymgve
Jan 2, 2004


:dukedog:
Offensive Clock
I don't even know what it's about, but some browsers try to be "smart" by replacing HTTP errors with their own "friendly" error messages. It's possible that 500 error is all that he sees and there are no specific details shown.

edit: And by "some browsers" I mean "At least Internet Explorer 9", which gives me this



on this HTTP error test page

ymgve fucked around with this message at 08:01 on Jul 25, 2012

Impotence
Nov 8, 2010
Lipstick Apathy
<!--
IE bug fix: always pad the error page with enough characters such that it is greater than 512 bytes, even after gzip compression abcdefghijklmnopqrstuvwxyz1234567890aabbccddee
ffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz1122
3344556677889900abacbcbdcdcededfefegfgfhghgihi
hjijikjkjlklkmlmlnmnmononpopoqpqprqrqsrsrtstsu
bcbcdcdedefefgfabcadefbghicjkldmnoepqrfstugvwx
hyz1i234j567k890laabmbccnddeoeffpgghqh
iirjjksklltmmnunoovppqwqrrxsstytuuzvvw0wxx1yyz
2z113223434455666777889890091abc2def3ghi4jkl5m
no6pqr7stu8vwx9yz11aab2bcc3dd4ee5ff6gg7hh8ii9j
0jk1kl2lmm3nnoo4p5pq6qrr7ss8tt9uuvv0wwx1x2yyzz
3aba4cbcb5dcdc6dedfef8egf9gfh0ghg1ihi2hji3jik4
jkj5lkl6kml7mln8mnm9ono
-->

Jewel
May 2, 2009

Biowarfare posted:

<!--
IE bug fix: always pad the error page with enough characters such that it is greater than 512 bytes, even after gzip compression abcdefghijklmnopqrstuvwxyz1234567890aabbccddee
ffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz1122
3344556677889900abacbcbdcdcededfefegfgfhghgihi
hjijikjkjlklkmlmlnmnmononpopoqpqprqrqsrsrtstsu
bcbcdcdedefefgfabcadefbghicjkldmnoepqrfstugvwx
hyz1i234j567k890laabmbccnddeoeffpgghqh
iirjjksklltmmnunoovppqwqrrxsstytuuzvvw0wxx1yyz
2z113223434455666777889890091abc2def3ghi4jkl5m
no6pqr7stu8vwx9yz11aab2bcc3dd4ee5ff6gg7hh8ii9j
0jk1kl2lmm3nnoo4p5pq6qrr7ss8tt9uuvv0wwx1x2yyzz
3aba4cbcb5dcdc6dedfef8egf9gfh0ghg1ihi2hji3jik4
jkj5lkl6kml7mln8mnm9ono
-->

Funnily enough, I think chrome had the same thing. I think it was a 404 page I was trying to get working with a .htaccess on an Apache server, but it wasn't working. Turns out it had to be over a certain filesize for it to work, and just placing a single <img> wasn't big enough :wtc:

theratking
Jan 18, 2012
I thought he knew what he was doing because he was directly reading the response from chrome dev-tools.

Deus Rex
Mar 5, 2005

Doc Hawkins posted:

Github issues are pretty bad, but I wouldn't award them full-blown horror status

why are github issues bad. they do what they're supposed to pretty well i think

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
Here's a nice, simple horror.

From the source of a product thumbnail page, repeated for every single thumbnail present on the page (minimum 36):

code:
        <!-- PM - STAR RATINGS GO HERE 

            

            TODO: the width for bn_current_rating needs to be calculated as a percentage (i.e. Rating 3.5 * 20 (each star is worth 20))

            See the script calc_rating in global.js to see how the calculation works



            <div class="bn_star_container">

	            <ul class="bn_star_rating">

		            <li class="bn_current_rating" style="width:80%;"></li> 

		        </ul>

	        </div>

        -->

Horror #2 is that they don't minify their JavaScript.

Pochoclo
Feb 4, 2008

No...
Clapping Larry
The most horrendous code I've ever seen, is some guy that thought he was coding motherfucking assembly code in PHP or something, check this out:

code:
$get_data = strpos($url_file,'-');
		if ($get_data!==false) {
			$url_src = $url_file;
			$url_file = substr($url_src,0,$get_data);	// Se actualiza el valor de $url_file
			$DX = substr($url_src,$get_data+1,strlen($url_src));
			$url_src = $DX;
			
			$get_data = strpos($url_src,'-');
			if ($get_data!==false) {
				
				$DX = substr($DX,0,$get_data);
				$EX = substr($url_src,$get_data+1,strlen($url_src));
				$url_src = $EX;
				$get_data = strpos($url_src,'-');
				if ($get_data!==false) {
					
					$EX = substr($EX,0,$get_data);
					$FX = substr($url_src,$get_data+1,strlen($url_src));
					$url_src = $FX;
					$get_data = strpos($url_src,'-');
					if ($get_data!==false) {
						
						$FX = substr($FX,0,$get_data);
						$GX = substr($url_src,$get_data+1,strlen($url_src));
						$url_src = $GX;
						$get_data = strpos($url_src,'-');
						if ($get_data!==false) {
							
							$GX = substr($GX,0,$get_data);
							$HX = substr($url_src,$get_data+1,strlen($url_src));
							$url_src = $HX;
							$HX = FriendlyUrlDecode($HX);
						}
						$GX = FriendlyUrlDecode($GX);
					}
					$FX = FriendlyUrlDecode($FX);
				}
				$EX = FriendlyUrlDecode($EX);
			}
			$DX = FriendlyUrlDecode($DX);
			$x_vars_set = true;
		}
Yeah, did you see those variable names?
The entire loving CMS is a single clusterfuck of an index.php, which has mySQL queries, HTML, and basically everything in it. It's also 3000 lines long.
ALL VARIABLE NAMES ARE TWO LETTERS LONG.

It's madness.

I mean, here I am, making a real effort to keep my team following best practices, coding in symfony2 neatly (you may or may not agree with the choice of symfony2, but it's still a very neat and modern MVC framework, I like it very much)... and there's still guys like THAT who are seemingly stuck in 1999 or something. What the flying gently caress.

On the other hand, thanks to them it's really easy to get a good-paying job. Companies here are so disappointed with the rampant bad coders, they'll hire a semi-competent programmer faster than you can blink.

Impotence
Nov 8, 2010
Lipstick Apathy

Ithaqua posted:

Here's a nice, simple horror.

From the source of a product thumbnail page, repeated for every single thumbnail present on the page (minimum 36):

code:
        <!-- PM - STAR RATINGS GO HERE 

            

            TODO: the width for bn_current_rating needs to be calculated as a percentage (i.e. Rating 3.5 * 20 (each star is worth 20))

            See the script calc_rating in global.js to see how the calculation works



            <div class="bn_star_container">

	            <ul class="bn_star_rating">

		            <li class="bn_current_rating" style="width:80%;"></li> 

		        </ul>

	        </div>

        -->

Horror #2 is that they don't minify their JavaScript.

Webserver I use automatically strips non-[if IE] comments and minifies CSS and JS automatically :v:

Beef
Jul 26, 2004

Pochoclo posted:

The most horrendous code I've ever seen, is some guy that thought he was coding motherfucking assembly code in PHP or something, check this out:


I find the repeating nested program structure to be a much worse coding horror than the 2-letter variables.

Pochoclo
Feb 4, 2008

No...
Clapping Larry

Beef posted:

I find the repeating nested program structure to be a much worse coding horror than the 2-letter variables.

Yeah, there's a reason I picked that specific part.

Now imagine all the 3000 lines of it are just as terrible.

It's like Boatmurdered, in PHP form.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
PHP, is_readable(), has a curiosity in its documentation.

quote:

bool is_readable ( string $filename )

Tells whether a file exists and is readable.

Returns TRUE if the file or directory specified by filename exists and is readable, FALSE otherwise.
OK? So you run it on a filename and it tells you if it both exists, and is in a readable permission. Awesome.

Except...

quote:

Upon failure, an E_WARNING is emitted.
I just tested it on a nonexistent file and it return false and did not throw a warning. So what on earth does 'upon failure' mean? What situation could a built-in function like this fail that doesn't count as a fatal error?

leterip
Aug 25, 2004

Golbez posted:

PHP, is_readable(), has a curiosity in its documentation.

OK? So you run it on a filename and it tells you if it both exists, and is in a readable permission. Awesome.

Except...

I just tested it on a nonexistent file and it return false and did not throw a warning. So what on earth does 'upon failure' mean? What situation could a built-in function like this fail that doesn't count as a fatal error?

The bigger horror is that it exists at all. There is no way to provide that function without creating a race condition. What if someone deletes the file in between that call and your attempt to read it?

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

leterip posted:

The bigger horror is that it exists at all. There is no way to provide that function without creating a race condition. What if someone deletes the file in between that call and your attempt to read it?

And if I try to run fopen() on a non-existent file, it throws a warning. Keep in mind that it also returns false. The documentation even helpfully suggests using @ to suppress the warning. Perhaps PHP functions should throw exceptions, because this seems like a reasonable place for that.

pseudorandom name
May 6, 2007

Golbez posted:

PHP, is_readable(), has a curiosity in its documentation.

OK? So you run it on a filename and it tells you if it both exists, and is in a readable permission. Awesome.

Except...

I just tested it on a nonexistent file and it return false and did not throw a warning. So what on earth does 'upon failure' mean? What situation could a built-in function like this fail that doesn't count as a fatal error?

In theory, all the usual problems you'd have with a file name (too much symbolic link indirection, path name is too long, one of the directories in the path isn't, etc.), except PHP converts any error returned from access() to false and calls it a day.

leterip
Aug 25, 2004

Golbez posted:

And if I try to run fopen() on a non-existent file, it throws a warning. Keep in mind that it also returns false. The documentation even helpfully suggests using @ to suppress the warning. Perhaps PHP functions should throw exceptions, because this seems like a reasonable place for that.

The point is that you have to assume that the fopen() call could raise a warning regardless of how much checking you do because by the time you get to actually opening the file the state of the filesystem could be different, so why bother doing the checking? It's a completely worthless function.

raminasi
Jan 25, 2005

a last drink with no ice

leterip posted:

The bigger horror is that it exists at all. There is no way to provide that function without creating a race condition. What if someone deletes the file in between that call and your attempt to read it?

That isn't exactly a PHP problem, though. Tons of APIs have stuff like that.

Sebbe
Feb 29, 2004

I've been lobbying to the PHP developers for years to change is_readable() to take source code as input instead of a file name. :v:

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde

Gazpacho posted:

I can assure you that the real problem is programmers just not knowing what memory is.
Followup: http://blogs.msdn.com/b/oldnewthing/archive/2012/07/25/10333134.aspx

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Maybe doesn't belong in here, but...

Only registered members can see post attachments!

hobbesmaster
Jan 28, 2008

Strong Sauce posted:

Maybe doesn't belong in here, but...



I assume that the second line 27 is supposed to be a *?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
TextMate 2 is if not a coding horror at least a coding project horror. Is it possible to parlay years of widespread success into something more flaccid than TM2?

Strong Sauce
Jul 2, 2003

You know I am not really your father.





I'm still using TextMate and those were two separate lines, not a wordwrapped line. Not sure what caused the problem.

Comrade Gritty
Sep 19, 2011

This Machine Kills Fascists

leterip posted:

The point is that you have to assume that the fopen() call could raise a warning regardless of how much checking you do because by the time you get to actually opening the file the state of the filesystem could be different, so why bother doing the checking? It's a completely worthless function.

There are other reasons to check if a file exists or is readable than to write (or read) from it. Sometimes you just want to know if the file exists and is readable.

ozymandOS
Jun 9, 2004

Steampunk Hitler posted:

There are other reasons to check if a file exists or is readable than to write (or read) from it. Sometimes you just want to know if the file exists and is readable.

Okay. But the information you receive from this function could be immediately out of date, no matter what you are going to use it for. It's a useless function.

silvergoose
Mar 18, 2006

IT IS SAID THE TEARS OF THE BWEENIX CAN HEAL ALL WOUNDS




BP posted:

Okay. But the information you receive from this function could be immediately out of date, no matter what you are going to use it for. It's a useless function.

If all you want to know is if a process ran already today, you can just check to see if a file is there and readable. If someone for some godawful reason deletes it thereafter to try to have the process run again anyway, who the hell cares, you don't run again and it's their fault for being slow.

(this is for the very popular "touch ALREADY_RAN_DATESTAMP" way of tracking this, of course)

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
^^^ okay I suppose that works

BP posted:

Okay. But the information you receive from this function could be immediately out of date, no matter what you are going to use it for. It's a useless function.

What about

Scenario 1: Have a script that runs for 10 minutes but only if it can read a file. So we check if the file is readable first, then run the 10 minutes, and at the end open the file and write to it.

Scenario 2: Open the file first because handles are cheap and it doesn't matter if you fopen it or check if it's readable, but this keeps it locked for 10 minutes which really is that a bad thing?

Yeah, you're right, I got nothing.

So, then we have is_writable(), but also this nugget: file_exists().

quote:

bool file_exists ( string $filename )

Checks whether a file or directory exists.

Returns TRUE if the file or directory specified by filename exists; FALSE otherwise.

Note: The check is done using the real UID/GID instead of the effective one.

Note: Because PHP's integer type is signed and many platforms use 32bit integers, some filesystem functions may return unexpected results for files which are larger than 2GB.

I am probably missing something here, but why the hell would this return "unexpected results" because of a large file? It can't see if that file exists if it's more than 2gb? What unexpected results would we have? Returning false if the file is actually there? Is this actually a thing that happens?

Golbez fucked around with this message at 14:58 on Jul 27, 2012

Plorkyeran
Mar 22, 2007

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

Golbez posted:

I am probably missing something here, but why the hell would this return "unexpected results" because of a large file? It can't see if that file exists if it's more than 2gb? What unexpected results would we have? Returning false if the file is actually there? Is this actually a thing that happens?
I assume it's just a generic warning that a monkey slapped on all filesystem functions rather than applying any sort of thought.

Then again it is PHP, so maybe checking for the existence of a file includes checking the size of the file for some reason.

Goat Bastard
Oct 20, 2004

BP posted:

Okay. But the information you receive from this function could be immediately out of date, no matter what you are going to use it for. It's a useless function.

Well "this file existed when I started doing what I'm doing so I'm going to assume it still exists" and "this file has never existed within the scope of what I'm doing" are two quite different situations that usually call for different actions. Obviously you still have to write defensive code, but it's a bit of stretch to say that checking if a file exists is useless.

ozymandOS
Jun 9, 2004

Goat Bastard posted:

Well "this file existed when I started doing what I'm doing so I'm going to assume it still exists" and "this file has never existed within the scope of what I'm doing" are two quite different situations that usually call for different actions. Obviously you still have to write defensive code, but it's a bit of stretch to say that checking if a file exists is useless.

True. I guess you can use a file existence check as a way to short-circuit unnecessary code--ie skip doing processing that will eventually fail due to a missing file, rather than waiting until you actually need the file before failing. But you should always also check at time of open.

Zamujasa
Oct 27, 2010



Bread Liar

silvergoose posted:

If all you want to know is if a process ran already today, you can just check to see if a file is there and readable. If someone for some godawful reason deletes it thereafter to try to have the process run again anyway, who the hell cares, you don't run again and it's their fault for being slow.

(this is for the very popular "touch ALREADY_RAN_DATESTAMP" way of tracking this, of course)

I use something like this for a cron job at work; it only runs every 5 minutes (or manually), and when it starts up it checks if a file exists (and tries to get the content if it does). If the file doesn't exist, it continues. If the file does exist, but the timestamp is more than five minutes old, it continues as well (but writes the latest timestamp to the file). At the end, the file is removed.

It's not entirely worthless; I personally think that the obsession over race conditions is a little unwarranted if you have some control over what's going on and you aren't multithreaded, but everybody seems to throw a fit over them.

Eggnogium
Jun 1, 2010

Never give an inch! Hnnnghhhhhh!

Zamujasa posted:

I use something like this for a cron job at work; it only runs every 5 minutes (or manually), and when it starts up it checks if a file exists (and tries to get the content if it does). If the file doesn't exist, it continues. If the file does exist, but the timestamp is more than five minutes old, it continues as well (but writes the latest timestamp to the file). At the end, the file is removed.

It's not entirely worthless; I personally think that the obsession over race conditions is a little unwarranted if you have some control over what's going on and you aren't multithreaded, but everybody seems to throw a fit over them.

A little caution is warranted even when today's environment doesn't call for it, because next year all kinds of other processes could have been introduced that interfere with your program's resources.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
We're losing sight of the big picture. The existence of is_readable is not the true horror. The true horror is that fopen() will always throw a warning if the file is not readable, unless you silence errors on the function call. It seems like they expect you to run is_readable first, and then run fopen, but in normal usage that could still result in fopen not opening the file. Most people would check to see if it returned false and move on, but now you have to manipulate the error reporting or simply ignore when your log gets a warning, both of which are poor options.

Adbot
ADBOT LOVES YOU

Zamujasa
Oct 27, 2010



Bread Liar

Eggnogium posted:

A little caution is warranted even when today's environment doesn't call for it, because next year all kinds of other processes could have been introduced that interfere with your program's resources.

I agree, I'm just saying that everyone seems to be acting as if race conditions are the newest goto.


As for PHP, whatever happened to PHP 6? I seem to recall it existing at some point years and years ago, but then it got rolled back out of nowhere and seems to have been erased from existence. Is that just my imagination?

Because it seems like a PHP 6 would be a great time to start working on cleaning up some of the larger horrors in PHP, like the lack of exceptions.

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