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
Munkeymon
Aug 14, 2003

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



Smackbilly posted:

haha oh god... at least that gets creativity points. Who needs RTTI when you have exceptions?

On the subject, I got to extend a code base for a student project that did stuff like this:

code:
if(successCondition)
{
  //do some cleanup
  throw new WhateverIdoHappenedToWorkException(returnValue);
}
else
{
  /*do the same cleanup with a couple things possibly 
    commented out for some reasonbecause copy and paste 
    is like a control structure, right?*/
  throw new WhateverIdoFailedException();
}
And the calling code had a big try/catch/catch/catch... block to handle the 'result'. Some had multiple success or failure 'conditions' that had to be caught. This technique was used instead of events, or at least mostly in places events should have been used*, in C#. It was all written by a 4th year CS undergrad.

*Class functions would throw exceptions on completion (or error) to be caught by other class functions. There were also a few places where whoever wrote it clearly could have used a switch if it had occurred to him.

Adbot
ADBOT LOVES YOU

Munkeymon
Aug 14, 2003

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



more falafel please posted:

Exceptions are like goto, only they're just "gosomewhere".

Plus they're objects and can carry a payload of other objects. It's the perfect fusion of functional and object oriented 'features' in one disturbing package.

Munkeymon
Aug 14, 2003

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



Sivart13 posted:

I get the feeling even posting the best-written COBOL you could find would still be valid for this thread.

Actually, if this:
code:
IF WS-OPT = 'P' OR 'L'
does what it looks like it does, then that's kind of nice, actually. Explicitly writing out things like if(something == A || something == F) always kind of bugged me for some reason.

Munkeymon
Aug 14, 2003

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



ashgromnies posted:

Wouldn't that kill the English readability of something like:

code:
if ($user->is_valid() && $user->has_enough_money()){
though? You'd need to make it

code:
if ($user->is_valid() == 1 && $user->has_enough_money() == 1){
which I don't like! It kills the readability of boolean expressions, and I'm also not sure of how it would work in dynamic languages where if($var) and if($var == 1) are completely different.

I was thinking a shorthand just for this case:
code:
if(mode == [1 | 2 | 3 | 5 | 8])
So ==[] is like a new operator that's really just syntactic sugar for the condition checks the compiler is going to emit anyway. That's just a quick example, though. I haven't given much thought to the 'best' way to do it.

Munkeymon
Aug 14, 2003

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



Volte posted:

Well some languages like Python have an 'in' operator. Like
code:
if mode in [1, 2, 3, 5, 8]

I know, but I was specifically thinking of C-style languages where ==[] might look more at home in a conditional. Also, JavaScript and C# already use in for other things.

Munkeymon
Aug 14, 2003

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



Damnit, guys. Quit bringing practical solutions to my fantasy land.

No Safe Word posted:

Monkeypatching FTL.

I don't know that it counts as monkeypatching but I still like it less than adding some shorthand to the language.

And where the hell is your avatar from?

Munkeymon
Aug 14, 2003

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



No Safe Word posted:

Hacking into a class that you didn't create is, in my mind, monkeypatching. Whether it's tacking on a method or redefining an existing one.

The super official Wikipedia definition says it has to happen at run time which may or may not be the case depending on how they do the magic in the IL. At any rate, wouldn't that method show up in CodeSense and be type cheched at compile time, making it signifigantly safer and more visible than the traditional monkeypatch?

quote:

edit:

SNL's Digital Short "Dear Sister", I made the animation myself from screencaps

I forgot I had it because I browse with avatars off at work :)

Thanks, now I'll ahve to go check it out.

Munkeymon
Aug 14, 2003

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



Janin posted:

If it's going to throw an exception anyway, why even use has_next()?

code:
import random
import sys

def gen_func ():
	while True:
		var = random.randint (0, 2)
		if var == 0:
			sys.exit ()
		yield var
		
gen = gen_func ()
gen.has_next () # How could this **ever** be implemented?

That's a lot like saying 'If the program is going to exit when it crashes, why bother trying to fail gracefully?' If you design your generator to make a mess then it will make a mess. Congratulations on restating the garbage in garbage out principal again.

It just doesn't make a lot of sense to use what most people would consider/assume to be specialized error handling machinery for flow of control or event notification. Not that you can't, but don't expect the rest of the world to agree that it's a perfect system and a great idea.

Munkeymon
Aug 14, 2003

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



Janin posted:

The generator is not "making a mess". Many generators have side effects, and it's important that the side effects happen at the prescribed time. I inserted the sys.exit() to prevent arguments about pre-caching results; often, the results themselves are unimportant and it's the side-effects of the generator that matter.

I would say that exiting any serious program from (essentially) inside a loop conditional is making a mess. That's getting into serious WTF territory unless you're just doing it to screw with someone.

quote:

The issue with using a has_next()/get_next() style is that it's not as general as the current system. Any loop implemented with has/get_next() can be wrapped in a generator, but the converse is not true because the behavior of a generator allows unpredictable results.

I think it would make some sense to force people to use a generator that can have side effects differently than one that can't in most cases, but that could easily be my newness to Python talking.

quote:

I don't think anybody is arguing that it's perfect, but it's certainly better than the alternatives. People just need to get over the "all exceptions are errors" mentality.

Then maybe it should be called an event, rather than an exception(al circumstance)? We could just call all numbers ints, since we're rewriting common paradigms. Some ints will just happen to have decimals.

Munkeymon
Aug 14, 2003

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



Janin posted:

Or you could just use exceptions. Obviously you've learned, or been taught, that exceptional circumstances are inherently errors. In Python, this is not the case; an exception just means that the code was unable to finish executing, for any reason.

If exception handling was to be replaced with another paradigm, I'd prefer something like LISP's conditions.

It does look an awful lot like Guido shoehorned what would be an event anywhere else into the exception model because, in the context of every other language I have used, this is strange behavior. Conditions already look like a better idea just because they don't try to call a shoe a sock.

Munkeymon fucked around with this message at 22:21 on Nov 7, 2008

Munkeymon
Aug 14, 2003

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



Janin posted:

What languages have you used? If you've only used the C family (C++/C#/Java) then the idea of a non-error exception will seem strange, but to understand Python you need to realize that they are different concepts.

It's often a good idea to give different concepts different names - and possibly even different structure - to avoid confusion. When you borrow the name and structure for a construct like exceptions from the popular language crowd and then subtly change what it's generally used for, you create a situation where problems are more likely for most programmers who use your language. I could also see a Python-taught programmer bringing this concept to a different language and making a huge mess.

Anyway, it's silly to argue over this now since it's not going to go back in time and affect Guido's decision, but I think he screwed up there. Not a huge deal, but still not the best idea he's had.

Munkeymon
Aug 14, 2003

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



geetee posted:

php:
<?
$LIVE_PRODUCTION_FLAG='TEST';
//Change above only to 'ON' or 'TEST'.
?>
If that "flag" wasn't bad enough, no less than 5 lines down:
php:
<?
if (isset($LIVE_PRODUCTION_FLAG) && ...) {
?>
I'm pretty sure it's still set to some obnoxious value.

What, you don't think they should test the live production flag :holy:

Munkeymon
Aug 14, 2003

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



TSDK posted:

... and why is a function for reading called 'write' at one point?

It's obviously writing the file to the buffer you big noob ugh it's like you've never seen real code before

There's probably a write(StringBuffer con,StringBuilder fle) that writes the buffer back to the file :suicide:

ymgve posted:

To elaborate more on my question, which of these are good/bad?

I like the third and first ones (in that order), myself.

Munkeymon
Aug 14, 2003

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



ymgve posted:

I've always felt the third one is a bit iffy because you have the same call twice, so if you ever change the code around, you have two locations that you need to change. Not so hard in this simple example, though.

I feel better about the first one, but it does seem a bit "unclean" to do an assignment inside the while() evaluation.

(Then again, this comes from someone who prefers break...)

True, but how often would you expect a read call to change form in a signifigant way?

Did you recently change your username?

Munkeymon
Aug 14, 2003

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



ymgve posted:

Nope, same username since registration. Why?

Memory corruption on my part, I guess. I mostly remember avatars, anyway.

Ryouga Inverse posted:

I think I want to kill myself.

Just kill the guy who turned that poo poo in and maybe his job could be filled by someone who doesn't leave the # out of C#.

Munkeymon
Aug 14, 2003

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



Jethro posted:

I think he's programing C♭ instead.

I'm not musical enough to know what the hell that thing is :(

Munkeymon
Aug 14, 2003

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



php:
<?
if(strpos($userid,".")>=0)$userid=-5;
?>
Lead Programmer: Hey, how come all the userids in this table are -5?

Me, 1 hour later: gently caress!

Now I'm searching our entire codebase for more cases of PHP programmers not understanding PHP.

Obligatory: PHP is a coding horror :(

Munkeymon
Aug 14, 2003

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



Sartak posted:

Even still, why would you subtract 5 from the userid if it contains a period?

The userid is supposed to be coming from a 3rd party authentication system and apparently there were periods getting in there somehow (and probably causing database errors) from someone at some point in the last 5 years. Rather than force people writing code upstream of the core authentication system to deal with it properly, someone decided it would be a great idea to hide a line in the system that will gently caress the userid right in the ear in this one specific case and then went and did it in a profoundly stupid way. I could post a bunch of our codebase in this thread but I'm extra pissed about this one because I read over this line 4 or 5 times before it occurred to me why it was wrong.

It's supposed to set the userid to -5, by the way (it's = -5 not -= 5).

Munkeymon
Aug 14, 2003

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



More!
php:
<?
   $today = getdate();
   $todayDate = sprintf("%04d%02d%02d_%02d%02d%02d", $today['year'], 
      $today['mon'], $today['mday'], $today['hours'], 
      $today['minutes'], $today['seconds']);
   $todayDate = $todayDate ^ "pippopippopippo";
   $toret = $userid . "." . $todayDate;
?>
Thank loving god it was commented out, but my brain shut down for a second when I saw $todayDate = $todayDate ^ "pippopippopippo"; in the grep results.

Munkeymon
Aug 14, 2003

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



Mill Town posted:

Apparently XOR is defined on strings in PHP. :psyduck:
http://ca.php.net/manual/en/language.operators.bitwise.php

HAHAHahah haha hah ha :suicide:

Even better: the manual says the only operators that work on strings are . and .= http://us.php.net/manual/en/language.operators.string.php

Munkeymon
Aug 14, 2003

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



FeloniousDrunk posted:

Seems to me all of that above could be written as:
php:
<?
$toret=$userid.'.'.(date('Ymd_His')^'pippopippopippo');
?>
which seems to be making some sort of maybe session key?

Yes and yes. It was changed at some point to the following (which doesn't deserve to be a full function if you ask me)
php:
<?
   $toret = md5($userid . "." . time());
   return $toret;
?>
We have a single point of return policy. It makes for some :downs: moments in the code. There are also a lot of things done in weird, circuitous ways like using rtrim(ltrim($input)) all over the place instead of trim(). I suspect it's some of the people who have worked on the software were incurious/lazy enough to learn only a small subset of the standard PHP namespace and shoehorn everything into that, but it could also be remnants of the PHP3 where it all began.

Munkeymon
Aug 14, 2003

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



Ugg boots posted:

I know some people like that, but Ugg I hate it. I'd rather jump the hell out of a triply-nested loop with a Return statement than try to get out some other way. (Though I guess PHP has a break(x) function that breaks you out of multiple loops, doesn't it?)

Yep, but I don't think I've seen it used anywhere I didn't put it in, and for the record, I also think single point of return is stupid. It has ceritanly caused or helped cause some ugly poo poo in our software.

Munkeymon
Aug 14, 2003

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



tripwire posted:

There is no god but PERL and regular expressions are his prophets.

Can't figure out whay that popped into my head - I certianly don't like PERL that much.

Munkeymon
Aug 14, 2003

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



Triple Tech posted:

Perl. Perl. Do you go around saying poo poo like JAVA or RUBY? <:mad:>

Do Java or Ruby stand for something? 'Cuz I'll start doing that if they do.

Munkeymon
Aug 14, 2003

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



6174 posted:

If you're going to go for the false etymology, you might as well go for Pathologically Eclectic Rubbish Lister.

Yeah, that's really a lot more accurate.

Edit: Why the hell did he call it Perl if that didn't stand for something? Or did he just invent a language and then call it something?

Munkeymon fucked around with this message at 18:55 on Feb 12, 2009

Munkeymon
Aug 14, 2003

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



Plorkyeran posted:

Indeed, Wall claims that the name was intended to inspire many different expansions.[14]

I swear that guy would be most happy living in the programmer's district of Toonland or whatever it was from Roger Rabbit.

quote:

What's your language today, Larry?

Oh, I thought I'd mash together MUMPS and Ruby and then make people end lines with the visual bell character. This will be a module for Perl 6 but I want to get it out of the way now.

Munkeymon
Aug 14, 2003

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



Ugg boots posted:

You really like the word frobnicate, don't you?

At least it's something other than foo(bar).

Munkeymon
Aug 14, 2003

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



McGlockenshire posted:

Much to our collective horror, the values are modifiable within the sort. I have no idea who thought this was a good idea, but I'm going to give him or her a piece of my mind should we ever meet. So, during the sort, the left value is always being modified. I'm not sure what method Perl uses internally to perform the sort, the results are the same every time on Perl 5.10.0.

Why would anyone do this? :psypop:

Wouldn't a pass-by-reference system be the best generic way to do it in Perl if you want people to be able to, say, sort an array of arrays by the lengths of the constituent arrays?

Honest question - I'm not a Perl expert, I just tinker with it occasionally.

Munkeymon
Aug 14, 2003

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



Dijkstracula posted:

Indeed, you need to pass by reference, but in your example (unless I'm misunderstanding your question) there's no need to allow the dereferenced array to be modifiable.

Personally I think the better solution would just be to enforce some sort of const correctness on the sorted list, or at the very least issue a warning when it's being modified.

Wouldn't that basically be creating a seperate and logically inconsistent state for the interpreter to be in while sorting? I'd say it's better to just let a few profoundly stupid/crazy people to shoot themselves in the foot than to create new potential interpreter bugs and certian work for some maintainer.

Munkeymon
Aug 14, 2003

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



BigRedDot posted:

I work on sonar systems for submarines, I can say confidently that regular expressions are not at all an integral part of the programming we do.

But what if you have to find an enemy submarine that resembles a well-formed propper name? What then Mr. Smarty-Pants?

Munkeymon
Aug 14, 2003

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



Otto Skorzeny posted:

I was assuming that any taint feature in PHP would be a shittier and dumber cargo-cult-copy of its Perl analog (like every PHP feature)

http://blog.php-security.org/archives/92-CORE-GRASP-PHP-Tainted-Mode.html

welp

Munkeymon
Aug 14, 2003

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



Painless posted:



Maybe someday someone will make the ultimate PHP security patch - a patch that causes PHP to remove itself from the server on first use.

Munkeymon
Aug 14, 2003

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



Flobbster posted:

I don't know how good VB (compile) --> MSIL (decompile) --> C# would look

It still looks pretty good except for a few small problems like certain features of VB causing implicit declarations that got (maybe still get?) turned into stuff like $12AB = something; that doesn't compile if you just paste it into a code file because of the $.

I was in charge of obfuscating the build at the place I used to work and most obfuscaters I tried did a passable job of mangling the logic, but would usually gently caress up namespace resolution to produce code that crashed all over the place unless you excluded huge chunks of your project from obfuscation :v:

Munkeymon
Aug 14, 2003

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



Nigglypuff posted:

this is an irl job that people have :psyduck:

I was in charge of making an obfuscated build because I was in charge of the build because I was in charge of continuous integration. Obfuscation wasn't supposed to be a big deal because you're just supposed to be able to point the product we were using at the assemblies and tell it to go nuts, but it took days of tweaking settings in the obfuscater to get the obfuscated assemblies to not crash on startup. I never did get a fully functional, obfuscated build made while I was there. No, it was not fun. I think the product was Object Blender or something?

The SmartAssembly demo worked on the first try, but he had already bought the other piece of poo poo as a bundle with some pre-made Vista-like UI controls from the same company.

Munkeymon
Aug 14, 2003

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



Lonely Wolf posted:

Well I hope this thread has taught you that it's far cheaper and far more effective to simply hire worse programmers.

We did have a guy overloading different Collections classes so he could rename the access methods, so there's that. CollectionSubtype.count_mine() is clearly superior :v: I think the real moral of the story is that you should buy your IL obfuscater from the same place you get your prebuilt UI widgets because saving a few hundred bucks is totally worth days of programmer time per release and you know those guys know their IL obfuscation because that ribbon widget is totally shiny as gently caress.

Munkeymon
Aug 14, 2003

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



Does this:
php:
<?
if(is_numeric($extid))
   $sql .= "us_extid=$extid";
else
   $sql .= "us_extid='".$extid."'";
?>
count? No? How about when the us_extid column is always a varchar column? Still no? How about when PHP sees a value of '0######'* in $extid and flips a loving coin to decide whether its a number or not? It's probably also because our poo poo pile software treats that variable as either a number or a string depending on how the original programmer was feeling the second he happened to be writing any one of the 200 preceding lines in this function, so maybe it's not 100% PHP's fault, but PHP's inconsistent type guessing is the enabler here. gently caress, I had the most frustrating morning.

*that's a 6-digit number with a leading zero, fyi

Munkeymon
Aug 14, 2003

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



Sprawl posted:

Can't you typer your variable before you put stuff into it?

And 1 quick google found this.

Strict typing would require about a week of work for rewriting and testing while this had to be done today. Also, I don't see how the behavior of == makes any difference to is_numeric, which quite clearly changed its behavior when acting on the same data as I tapped F5 a few times earlier today.

Munkeymon
Aug 14, 2003

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



Mill Town posted:

DB DB DB... Th-th-th-that's all folks!

:downsrim:

I chuckled. I think us PHP users have to find humor where we can

Munkeymon
Aug 14, 2003

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



zootm posted:

I knew a guy who did something near-identical to this (in Java) when I was at uni. I suggested the single-line version and he just kinda looked stunned, then said he'd "maybe think about doing it that way later". Oh, well.

That was amateur horror. It takes professionals to create Live Horrors

code:
function util_clearBlanks(str) {
   return util_clearAllBlanks(str,0);
}
function util_clearAllBlanks(str,intern) {
   var db, sss;
   var i,j,k;
   var out = "";

   if (str != "") {
      sss = str.toString();
      db = sss.split(" ");
      
      for (i=0; (i<db.length) && (db[i] == ""); i++) { }
      for (j=db.length-1; (j>=0) && (db[j] == ""); j--) { }
   
      //alert(db.length + " - " + i + " - " + j);
      for (k=i; k<=j; k++) {
         //alert("'" + db[k] + "'");
         if (db[k] != "") {
            if (intern != 1 && out != "") out = out + " ";
            // if (out != "") out = out + " ";
            out = out + db[k];
         }
      }
   } else {
      out = str;
   }
   
   return(out);
}

Adbot
ADBOT LOVES YOU

Munkeymon
Aug 14, 2003

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



Lonely Wolf posted:

I want to quote my favorite line, but I just can't decide: they're all so bad.

Have you considered joining the rank of heroes who have come to work with a shotgun and a heart tempered in justice?

The person who wrote this is in an office in Europe, so that wouldn't even help. I would like to find a new job, though. Anyone in Minneapolis hiring? :allears:

RussianManiac posted:

I am pretty sure this is just somebody doing a horror on purpose.

Hahahahahahaaaaaa no.

Pretty sure this is the same guy:
code:
function util_doubleBackSlash(str) {
   var out;
   var len;
   var j,i;

   j=0;
   out = new String("");
   len = str.length;
   for (i=0; i<len; i++) {
      ch = str.charAt(i); 
      if (ch == '\\') {
         out += "\\";
         j += 1;
      } else {
         out += ch;
         j++;
      }
   }
   return(out);
}
Oh but it's been replaced and...
code:
function util_doubleBackSlash1(Str) {
   var re = /\\/gi;
   Str = Str.replace(re, "\\\\");
   return Str;
}
:suicide:

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