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
qntm
Jun 17, 2009
Today I discovered that FTP has no capability to "get" a complete directory and all of its subdirectories.

This isn't really a coding horror, it's more of an absence-of-coding horror. What is the thought process that leads to an omission like that? I have severe problems attributing this to malice or incompetence, it has to be literally "I'm writing a program which lets people retrieve files and directories from remote locations. Oh, but not directories. I think I'll leave that bit out."

Adbot
ADBOT LOVES YOU

qntm
Jun 17, 2009

ToxicFrog posted:

This isn't a horror at all. As others have pointed out, the protocol has everything you need to easily implement recursive transfers, and any decent ftp client - nsftp, lftp, filezilla, wget, etc - supports them.

The real horror is that the plain 'ftp' command that most operating systems ship with hasn't been updated since the early 80s.

Yeah, it's the ftp command that I'm complaining about, not the protocol itself. If it's so easy to implement clever recursive transfers on top of ftp, why hasn't it been done and incorporated into ftp?

qntm
Jun 17, 2009

Ari posted:

You know what the worst part is? $this.

What's wrong with $this?

qntm
Jun 17, 2009

NotShadowStar posted:

You mean ==? I'm not sure how that even works without a compiler/parse error. But hey even long veterans mix up =/== sometimes when not paying attention and they can be a bitch to find. I blame no language since C having the balls to go back to using := for assignment for visual distinction.

I really used to like my graphing calculator which used "->" as its assignment operator, e.g.

code:
false->showPopUps
well, it could only handle integer variables with a single-character name so it was more like

code:
0->P
Even so, it was "put this value in that box." It made perfect sense to me.

qntm
Jun 17, 2009

TRex EaterofCars posted:

Weak, JCL for life. Significant whitespace and hard to distinguish characters weed out the scrub tier pretty quickly.

Call me a scrub. JCL: Significant whitespace. "Case-sensitive" in the sense that everything has to be in capitals. Line length limit of 80 characters, 2 of which are the "//" which has to be at the beginning of every valid line and 8 of which are mandatory card sequence numbers. Comments aren't delimited, they're just anything you manage to fit in the space left after the end of the statement. I'm pretty sure it can't do loops which means it's not Turing-complete. And whenever you call a JCL procedure, you can also manually override the datasets (input/output streams) used at any labelled line in that procedure. Since every line has to have label, the result is that as soon as your useful procedure becomes public you can never modify the name or function of any line in that procedure without breaking someone else's code.

qntm
Jun 17, 2009
http://en.wikipedia.org/wiki/Python_%28programming_language%29

quote:

While many programming languages round the result of integer division towards zero, Python always rounds it down towards minus infinity; so that 7//3 is 2, but (−7)//3 is −3.

Python provides a round function for rounding floats to integers. Version 2.6.1 and lower use round-away-from-zero: round(0.5) is 1.0, round(-0.5) is -1.0. Version 3.0 and higher use round-to-even: round(1.5) is 2.0, round(2.5) is 2.0.

??!

qntm
Jun 17, 2009
This, then, could be a variant upon Poe's Law?

qntm
Jun 17, 2009

quiggy posted:

Is it bad that this would work on me?

The best chat-up lines are the insanely geeky ones because anybody they work on is an insane geek.

qntm
Jun 17, 2009
In Python, to quote the Python thread, a folder is a package.

In Perl, this is not true. When you use the "use" function, all the terms are directories except the last one which is the file. And the double colon :: is the delimiter between each term. ...But the file can contain a package or packages plural which are named completely differently. You have absolutely no idea what semantics you just imported. Plus, when you do start to make use of stuff in that package, suddenly all the terms are levels in the package heirarchy except the last term which is a function or variable inside the file, and the double colon is now magically the package heirarchy delimiter. Only now have I realised that any agreement between the package heirarchy and the filesystem heirarchy is basically just a huge coincidence, and even now I probably still have most of this wrong. Why would a programming language even allow you to do such confusing things?

qntm
Jun 17, 2009

Otto Skorzeny posted:

You seem to have thoroughly confused the default place perl looks for a Perl package based on its namespace with some sort of deep meaning, and also forgotten that you have very, very fine grained control of what semantics you import.

Well, by all means explain it. As I understand it, "use Foo::Bar;" will make Perl look through all of the directories in @INC for a file named "Foo/Bar.pm", NOT for a file containing "package Foo::Bar;". That is, it is a command to import a specific file, and "::" is being made into a directory separator. Meanwhile, Foo/Bar.pm could start off with "package Something::Else;", so that when, later in the script, you start calling Something::Else::function(), (1) the "::" suddenly has a completely different meaning and (2) the reader has no idea where this function has mysteriously appeared from.

qntm
Jun 17, 2009

ToxicFrog posted:

code:
  s = s.replace(/^\s+/, ''); // trim leading whitespace

Except this doesn't work, because outside of a pair of square brackets, the ^ metacharacter isn't "negation", it matches the end of the string. So /^\s+/ will match nothing. I think what's needed is either /[^\s]+/ or /\S+/.

qntm
Jun 17, 2009

seiken posted:

Woah, why have I never thought of the !! operator before? Since it doesn't do anything you can pepper it around your code to indicate the important bits!

I guess !! is equivalent to a boolean cast? Like, if the input was appState.length, which is an integer from 0 upwards, !!appState.length will be FALSE if appState.length was 0 and TRUE if appState.length was greater than 0.

I've seen code where !!! was used to call special attention to negation operations.

qntm
Jun 17, 2009

h_double posted:

I once had to maintain a whole mess of Perl code written by a guy who "didn't believe in" modules or CPAN. What if you are on a secured network that can't readily pull packages from CPAN? What if you update a module and it breaks your code?

Half of the scripts were full of copy-pasted subroutines to do network stuff, forks, etc. all by hand.

We have that kind of scenario where I work, but the problem is our Perl needs to be run on about 65 different machines all running different operating systems. "Getting a module from CPAN" becomes such a tall order that if something isn't included in every Perl installation by default, rolling your own or figuring out how to do without it almost always ends up being quicker and easier.

qntm
Jun 17, 2009

ErIog posted:

The better question at this point is, why are your 65 machines running different operating systems?

They're test machines. The software I work on is available for almost every platform you've ever heard of, so we need to test it in a fairly hefty variety of environments. The Perl in question is our test material. You would be amazed how many otherwise robust and useful Perl modules have never been tested on an EBCDIC system.

qntm
Jun 17, 2009

Janin posted:

I'm honestly shocked that Perl runs at all on a EBCDIC platform

EBCDIC is the real coding horror.

qntm
Jun 17, 2009

YeOldeButchere posted:

Well, no, but I meant other than that. Or is it really all it's used for?

IBM makes literally billions of dollars from ensuring that the banking and airline software that these banks and airlines use - software which was indeed written in the 1970s, for original System/360 machines, in COBOL, in EBCDIC, whose original source code is lost, and whose original programmers probably retired in the 1980s and died in the 2000s - continues to work and does not need to be replaced. When you look at the amount of commerce which passes through those systems (since these are investment banks, they're running into the trillions each year), the track record of reliability that those programs have proved themselves to have (a level of reliability which any replacement program would have to match) and you realise just how much there is to lose if the replacement program fails, and how likely it is that the replacement program will in fact fail somehow, you find yourself willing to pay really insane amounts of money not to have to make that change.

It's actually not a terrible business partnership. The customer gets a fairly strong guarantee that their system is bulletproof and IBM doesn't have to do much beyond gradually improve the performance and capacity of each year's new mainframe. If you want to work with the same system for thirty years and never learn anything new, which a frightening number of IT people inexplicably seem to want to do, a job writing COBOL is a job for life, or at least for the forseeable future.

Of course, if you're a fresh-faced newcomer to the world of software engineering and you're used to the natural state of information technology being one of continuous rapid change (and improvement), then using green screen terminals is quite a culture shock. And realising that the green screens are never, ever going to go away is worse. And converting everything from EBCDIC to ASCII in order to edit it locally (instead of editing it on the remote machine using vi - not vim, vi) gets old fast.

qntm
Jun 17, 2009

tef posted:

this just shows how far we've come in 40 years of software engineering.

Not really, it's just impossible for a computer program to demonstrate 40 years of continuous reliability under heavy load without having been written 40 years ago. There's plenty of code out there which was written "only" 20 years ago or 10 years ago and has done its job perfectly ever since and will continue to do so long into the future. If you want someone to replace your working but antiquated COBOL with something modern i.e. recently-made, then proving that any possible replacement can meet the task means testing it to breaking point and under NASA-level intensity and scrutiny.

There is nothing to stop people writing programs right now, in modern languages, which will operate perfectly for the next 40 years. It happens all the time. The problems are (1) getting explicit requirements out of a program which was invariably programmed with a great deal of skill and subtlety but has little to no surviving documentation (those requirements could be met if they were clear), (2) proving that the replacement matches those requirements to the satisfaction of the person with the money and the severe disinclination to switch, and (3) making the switch seamlessly. We could do this. There's nothing stopping any of this happening, other than the fact that it's cheaper for the customer and more profitable for the provider for everybody to stick with what works.

qntm
Jun 17, 2009
When in history has anybody charged money for an alpha release of something? In fact, when has an alpha release ever been made available to the general public?

Notch is charging money for an unfinished product and using "alpha" as an excuse for poor quality control.

qntm
Jun 17, 2009
That's why you can simply use === and !== in every situation. It's a universal rule that always ensures that two things being compared are exactly identical.

Oops, unless they're objects, in which case you have to use ==. Got me again, PHP!

qntm
Jun 17, 2009

yaoi prophet posted:

code:
$regexp = preg_replace('(', '[(]', $regexp);
I don't know whether that statement, PHP, SQL, or all three is the horror here.

That statement there is a pretty big horror.

code:
"\(stuff\)" => "\[(]stuff\)"
Congratulations, you have inserted a literal left-bracket and right-bracket?

qntm
Jun 17, 2009

yaoi prophet posted:

code:
// we should protect against SQL injection attacks here...?
You don't say. No super-valuable data or anything, just stuff that would take a couple weekends on some high-end machines to replace. Though I guess since mysql_query() only allows single queries, the built query is a select and the database isn't secret or anything and would take a weekend of number-crunching to regenerate, there's not really much that could be done. Then again, there might be some hilarious way to embed UPDATE/DELETEs into a SELECT because lol MySQL.

I replaced it with a prepared statement, then ran into escaping-related issues because one of the things I was using was a regexp that involved both literal parens and grouping parens and I couldn't for the life of me figure out how to escape properly. So I just wound up running

code:
$regexp = preg_replace('(', '[(]', $regexp);
beforehand. Simpler than loving around with backslashes. I don't know whether that statement, PHP, SQL, or all three is the horror here.

No, it's no good. I have read this three times and I have absolutely no idea why you are having a problem at all. Yes, there is almost certainly a hilarious way to embed UPDATE/DELETEs into a SELECT. Yes, there are many other much more damaging things that could be done to your database than simply deleting data from it. No, the database being "not secret or anything" doesn't mean you don't need to protect against this. No, the fact that it would take "a weekend of number crunching" to repair the database doesn't mean you don't need to protect against this.

At the outset, you should have been able to completely solve your problem by wrapping single quotes and mysql_real_escape_string() around all of your fields. If this didn't work, you must have been doing something very wrong, but the fact that you haven't even mentioned trying this is even wronger.

Prepared statements, almost by definition, have absolutely no problem with the escaping of backslashes because correct quoting and escaping is handled automatically. You can't even override it! So if you're still having problems there, then, again, something is very wrong.

There is no circumstance in which you should be escaping a PHP variable for inclusion into a MySQL query manually. Also, as I mentioned, the function you're using to "escape" your string is apocalyptically broken. And even if it wasn't, which it is, you should be using str_replace(), not preg_replace().

yaoi prophet posted:

Fortunately nobody is going to be searching for stuff including backslashes in our data.

yaoi prophet posted:

At least it'll fail safe :colbert:

If people searching for backslashes can break your query then your query is broken. It is very easy to make dynamic MySQL queries 100% safe, and there is no excuse for not doing so. I have no idea what "fail safe" is supposed to mean.

Basically what I'm saying is that everything in this scenario is a horror except for PHP and MySQL.

qntm
Jun 17, 2009
code:
>>> a = ([], 2)
I don't even understand how this can possibly be legal in Python. Tuples are immutable, so how come you can put a mutable list inside one?

qntm
Jun 17, 2009

Toady posted:

Every time I read $your_favorite_language code or the bizarre things that $your_favorite_language does I wonder how the hell that language caught on. It's like someone's academic experiment that broke out of the lab.

So what you're saying is that every single programming language has serious horrors in it and none of them are good, let alone perfect.

I agree entirely.

qntm
Jun 17, 2009

revmoo posted:

132 Errors, 77 warning(s)

To be fair, one unclosed paragraph tag can result in 1 error for every following paragraph, so you can cause 100 errors with one mistake quite easily.

Also, since when is XHTML 1.0 Strict deprecated?

qntm
Jun 17, 2009

BonzoESC posted:

The best part was the simple XSLT used to rename a variable, and Tim Bray crying from laughter in the audience.

Is there supposed to be audio with that presentation?

qntm
Jun 17, 2009

yaoi prophet posted:

code:
$node = "(?<node>\([A-Z]+[[:blank:]]+([^()]+|((?&node)[[:blank:]]*)+)[[:blank:]]*\)[[:blank:]]*)"
I love PCREs so much.

PCREs support whitespace and comments so I think this would work:

code:
$node = "
 (?x                      # ignore whitespace, allow comments
  (?<node>                # named subpattern, "node"
   \(                     # literal left parenthesis
   [A-Z]+                 # node name
   [[:blank:]]+           # gap
   ( [^()]+ | (?&node)+ ) # stuff, or another nested node (recursion)
   [[:blank:]]*
   \)                     # literal right parenthesis
   [[:blank:]]*
  )                       # end named subpattern
 )
"

qntm
Jun 17, 2009

bobthecheese posted:

php quine

php:
<?
echo file_get_contents($_SERVER['SCRIPT_FILENAME']);
?>
Is that cheating?

No, this PHP quine is cheating:

code:
Any text you like as long as you don't drop into PHP mode

qntm
Jun 17, 2009

Janin posted:

Perhaps IBM's customers are paying by the byte.

Paying by the processor cycle is actually closer to the truth.

qntm
Jun 17, 2009

HFX posted:

Sometimes they do. Like when you coworker puts empty lines between every line of a method like it was some double spaced paper. Arg list too long, yeah, double space that too.

Some time ago I had the idea for a code editor where each blank line would be half the height of a line with text in it, just to make it more pleasant to read. I never got around to looking for an editor which actually does this but I think it'd be neat.

qntm
Jun 17, 2009

bobthecheese posted:

American English, that is :(

gently caress you CSS, the word is "colour"!

And it's text-align "centre" too while we're at it

I think we're stuck with the "Referer" HTTP header, though.

qntm
Jun 17, 2009
Wait, so

http://twitter.com/!/forrst/status/40425431857512448

says

quote:

Staff Pick: Can you write a FizzBuzz program without if/else/switch? http://t.co/RBecdHr

which links to

http://forrst.com/posts/Why_Cant_Programmers_Design_Software-gOg

which says, among a great many other things

code:
public boolean applies(int number) {
    return number % this.mod == 0;
}
code:
for (FizzBuzzOperation fizzbuzz : this.fizzbuzzes) {
    if(fizzbuzz.applies(number))
        return fizzbuzz;
}
?

So I guess the real challenge overcome here was to slightly obfuscate the location of the "if" statement!

qntm
Jun 17, 2009
code:
print ["FizzBuzz", $_, $_, "Fizz", $_, "Buzz", "Fizz", $_, $_, "Fizz", "Buzz", $_, "Fizz", $_, $_ ]->[$_ % 15]."\n" for 0..99
I don't think I'm doing it right :shobon:

qntm
Jun 17, 2009

Aleksei Vasiliev posted:

The site is also a horror itself: http://phpsadness.com/?page=sad/18
Well, yeah. What the gently caress did you think static variables were for?

Possibly the author is expecting static variables to be bound to the class itself in some way, like you see in Java?

qntm
Jun 17, 2009

aux posted:

Worst part is the "return OK" at the end, I'm ok with nested if statements to some extent (I've seen some horrible horrible nested if's in my time)

I like the implication that the variable OK could be set to false, and "return OK" could therefore be a very bad thing.

qntm
Jun 17, 2009
A boolean called "OK", like "TRUE", "FALSE", "SUCCESS" and "FAILURE", looks like a constant. Especially when you start using it in conditionals. "if(OK)" reads like "if(true)" or "if(1)". "if(OK == false)" just looks like nonsense. "isOK" would be an improvement, but "isValid" would be better.

qntm
Jun 17, 2009

Wheany posted:

var LOG_OK = 1;

Looks like "login ok" or "user logged in", right? WRONG! It's opposite day!

if(!(username.length > 0 && username != "guest")){
LOG_OK = 0;
}

[.....]

if(!LOG_OK){
showConfigLink();
}

Why would you even?

My favourite is a big chunk of code which made extensive use of a variable called $noRetries. It was about half an hour before I realised that this was intended to mean "number of retries", not "disable retries".

qntm
Jun 17, 2009

duck monster posted:

Ignore the retarded image macros in the thread on this patch:

https://github.com/MrMEEE/bumblebee/commit/a047be85247755cdbe0acce6#diff-0

code:
@@ -348,7 +348,7 @@ case "$DISTRO" in

   ln -s /usr/lib/mesa/ld.so.conf /etc/alternatives/gl_conf
   rm -rf /etc/alternatives/xorg_extra_modules
   rm -rf /etc/alternatives/xorg_extra_modules-bumblebee
-  rm -rf /usr /lib/nvidia-current/xorg/xorg
+  rm -rf /usr/lib/nvidia-current/xorg/xorg
   ln -s /usr/lib/nvidia-current/xorg /etc/alternatives/xorg_extra_modules-bumblebee
   ldconfig 

  ;;
:ughh:

I wonder how many people got their machines bricked by this clanger.

I don't know much about bash but doesn't this change fix the line of code which deletes /usr? Surely the change where that error was introduced would be more of a facepalm.

EDIT: Here we go.

qntm fucked around with this message at 18:35 on Jun 16, 2011

qntm
Jun 17, 2009

Thel posted:

You're not thinking badlyenterprisey enough.

code:
public boolean isTrue(boolean ValueToBeTested) {
    boolean trueBoolean = BooleanFactory.getInstance(BooleanValues.BooleanTRUE);
    boolean falseBoolean = BooleanFactory.getInstance(BooleanValues.BooleanFALSE);
    if(ValueToBeTested != falseBoolean) {
        if(ValueToBeTested == trueBoolean {
            return trueBoolean;
        } else {
            throw new InvalidArgumentException(ValueToBeTested + " is not a valid boolean value.");
        }
    }    
    if(ValueToBeTested != trueBoolean) {
        if(ValueToBeTested == falseBoolean {
            return falseBoolean;
        } else {
            throw new InvalidArgumentException(ValueToBeTested + " is not a valid boolean value.");
        }
    }
    throw new ValueMatchingException(ValueToBeTested + " is neither true nor false.");
    return false;
}

Is it good that I couldn't come up with nonsense like this even if I tried?

qntm
Jun 17, 2009

Presto posted:

This is C/C++, plus is higher precedence than shift

This is a horror.

Adbot
ADBOT LOVES YOU

qntm
Jun 17, 2009

Aleksei Vasiliev posted:

There are languages that prioritize shifts over addition/subtaction?

I would have thought every language did this. A shift is, after all, a glorified multiplication or division in most cases. But apparently not, and it trips me up every single time.

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