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
Arms_Akimbo
Sep 29, 2006

It's so damn...literal.
I started this job as a network contractor, I was only supposed to run some cabling and hook up some new workstations. Then my shop burned down and he offered me a position full time. My job now is to port this complete disaster over to a more modern and secure system than VBA in Access 2000. The best part is that there's only four full time employees here, and not a single one of them knows how the entire system works, so I'm forced to actually try to translate this disaster on my own and make it work on a new platform without knowing a single thing about operations here. (This has been live and in use by the company for seven years now)

tAutonumber has one record in it, who's sole duty is to hold the value of the most recent order number created so the table that stores the orders knows to increment the order value by one. :suicide:

code:
test = "a"
        Dim Msg, Style, Title, Response
        Msg = "Create New Order no.?"   ' Define message.
        Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
        Title = "Order Create Verification"  ' Define title.
        Response = MsgBox(Msg, Style, Title)
        If Response = vbYes Then    ' User chose Yes.
            Dim num As Long, newh As String, sta As String, newchk As Boolean
            
           
                                   
redo:
            
            num = DLookup("value", "tautonumber", "[recno]=1")
            HAWBan.Edit
            HAWBan![Value] = num + 1
            HAWBan.Update
            newh = CStr(num)
            orderno = newh
          
                      
            Dim newawb As String
            'test = "a"
            test = IsNull(DLookup("[order]", "tOrders", "[order] = [orderno]"))
              testa = "a"
                If test Then
                GoTo nextone
                End If
            newawb = DLookup("[order]", "tOrders", "[order] = [orderno]")
                If newawb <> "" Then
                GoTo redo
                End If
nextone:
            'test = "a"
        Else    ' User chose No.
            [order].SetFocus
            'test = "a"
        GoTo Exit_cmdOpen_Click
        End If
        
 End If
    
    
    
    
    Dim stDocName As String
    Dim stLinkCriteria As String
             testa = "a"
    stDocName = "fOrders"
    
    stLinkCriteria = "[order] = Forms![fOrder Selector]![orderno]"
    
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Forms![fOrders]![order] = Forms![forder selector]![orderno]
    
    
  test = "a"

Adbot
ADBOT LOVES YOU

gold brick
Jun 19, 2001

no he isn't
code:
Public Enum Places
       A
       B
       C
       D
       F
End Enum
Thanks for getting rid of those magic numbers, guy.

wolf_man
Oct 5, 2005

Nunez?

ryanmfw posted:

I've seen some elegant solutions at programming competitions:

code:
for(int i=1; i<1000; i++)
if(i==1){ printf("One");}
if(i==2){ printf("Two");}
if(i==3){ printf("Three");}
....
if(i==999){ printf("Nine Hundred And Ninety Nine");}
}
Took a team the entire length of the competition to write (6 hours), and it didn't even pass.

6 hours? this was the best I could come up with, took me about 15min.

code:
<?php
$ones = array('','one','two','three','four','five','six','seven','eight','nine');
$teens = array('','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen');
$tens = array('','ten','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety');
	
for($i=1;$i<1000;$i++){	
	if($i<10){
		echo $ones[$i].'<br />';
	}else{
		$x = floor($i/10);
		$y = ($i%10);
	
		if($i>99){
			$z = floor($x/10);
			$x =($x%10);
			echo $ones[$z].' hundred'.(($x || $y) ? ' and ':' ');	
		}
		echo ( ($x==1 && $y>0) ? $teens[$y] : $tens[$x].' '.$ones[$y]),'<br />';
	}
}
?>
Is there a more elegent/better way of solving this problem ?, which requires a few hours to figure out?

(really, I am curious)

POKEMAN SAM
Jul 8, 2004

wolf_man posted:

Is there a more elegent/better way of solving this problem ?

Probably not using PHP would make it more elegant :iceburn:

Sivart13
May 18, 2003
I have neglected to come up with a clever title

wolf_man posted:

6 hours? this was the best I could come up with, took me about 15min.
Congratulations! You have successfully determined that taking six hours to write a hard-coded version of this problem is indeed a "Coding Horror".

wolf_man posted:

Is there a more elegent/better way of solving this problem ?, which requires a few hours to figure out?
I think some of the more obscure selections on http://99-bottles-of-beer.net/ might've taken people a bit of time.

Save the whales
Aug 31, 2004

by T. Finn

wolf_man posted:

Is there a more elegent/better way of solving this problem ?, which requires a few hours to figure out?

(really, I am curious)

Heh, this was fun. I don't know if this is more elegant, but it can sure spell out a lot of numbers! In Java:

code:
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class Main
{
  static String[] ones = { "one", "two", "three", 
    "four", "five", "six", "seven", "eight", "nine", 
    "poop", "eleven", "twelve", "thirteen", "fourteen", 
    "fifteen", "sixteen", "seventeen", "eighteen", 
    "nineteen" };
  
  static String[] tens = { "ten", "twenty", 
    "thirty", "fourty", "fifty", "sixty", "seventy", 
    "eighty", "ninety" };
  
  static String[] powers = { "thousand", "million", 
    "billion", "trillion", "quadrillion", "quintillion", 
    "sextillion", "septillion", "octillion", "nonillion", 
    "decillion", "undecillion", "duodecillion", 
    "tredecillion", "quattuordecillion", "quindecillion", 
    "sexdecillion", "septendecillion", "octodecillion", 
    "novemdecillion", "vigintillion" };
  
  static BigInteger oneThousand = new BigInteger("1000");
  
  static String spell(int i)
  {
    return spell(Integer.toString(i));
  }
  
  static String spell(long i)
  {
    return spell(Long.toString(i));
  }
  
  static String spell(String s)
  {
    return spell(new BigInteger(s));
  }
  
  static String spell(BigInteger i)
  {
    if (i.equals(BigInteger.ZERO)) return "zero";
    List<String> c = new ArrayList<String>();
    boolean negative = i.compareTo(BigInteger.ZERO) < 0;
    i = i.abs();
    int pow = 1;
    BigInteger q = new BigInteger("1");
    while (i.compareTo(q) >= 0)
    {
      int n = i.divide(q).mod(oneThousand).intValue();
      String one = n % 10 > 0 ? n % 100 < 20 ? 
          ones[n % 100 - 1] : ones[n % 10 - 1] : null;
      String ten = (n % 100 == 10 || n % 100 >= 20) && 
      (n / 10) % 10 > 0 ? tens[n / 10 % 10 - 1] : null;
      String hundred = (n / 100) % 10 > 0 ? 
          ones[n / 100 % 10 - 1] + " hundred" : null;
      StringBuilder sb = new StringBuilder();
      if (hundred != null) sb.append(hundred);
      if (hundred != null && ten != null) sb.append(" ");
      if (ten != null) sb.append(ten);
      if (hundred != null && ten == null && one != null) 
        sb.append(" ");
      if (ten != null && one != null) sb.append("-");
      if (one != null) sb.append(one);
      if (pow > 1 && sb.length() > 0) sb.append(" " + 
          (pow - 2 < powers.length ? powers[pow - 2] : 
            "(10^" + (pow - 1) * 3 + ")"));
      if (sb.length() > 0) c.add(sb.toString());
      pow++;
      q = q.multiply(oneThousand);
    }
    if (negative) c.add("negative");
    Collections.reverse(c);
    return join(c, " ");
  }
  
  static String join(Collection<?> c, String s)
  {
    Iterator<?> iter = c.iterator();
    StringBuilder sb = new StringBuilder();
    if (iter.hasNext())
    {
      sb.append(iter.next());
    }
    while (iter.hasNext())
    {
      sb.append(s);
      sb.append(iter.next());
    }
    return sb.toString();
  }
  
  public static void main(String[] args)
  {
    for (int i = 0; i < 1000; i++)
    {
      System.out.println(spell(i));
    }
  }
}

Smackbilly
Jan 3, 2001
What kind of a name is Pizza Organ! anyway?

Save the whales posted:

code:
  static String[] tens = { "ten", "twenty", 
    "thirty", [b]"fourty"[/b], "fifty", "sixty", "seventy", 
    "eighty", "ninety" };
  

Bug report. Severity: Critical.

Save the whales
Aug 31, 2004

by T. Finn

Smackbilly posted:

Bug report. Severity: Critical.

Arrrgh! *dies*

edit:

quote:

Here's a hint.

Jesus. Settle down.

Save the whales fucked around with this message at 08:02 on Jul 12, 2008

blorpy
Jan 5, 2005

Is this going to become another fizzbuzz? As with that, anyone who posts a solution is probably not fit to do so.

crazypenguin
Mar 9, 2005
nothing witty here, move along

Chain Chomp posted:

Is this going to become another fizzbuzz? As with that, anyone who posts a solution is probably not fit to do so.

I had forgotten that utter clusterfuck until now. There was like one correct solution in the several hundred solutions posted to that blog. It was atrocious.

And hilarious.

I forget who's blog it was, but man it must have sucked to be that guy. "Gee, a pile of morons make up my readership. :smith:"

blorpy
Jan 5, 2005

crazypenguin posted:

I forget who's blog it was, but man it must have sucked to be that guy. "Gee, a pile of morons make up my readership. :smith:"

Here's a hint.

quote:

Coding horrors: post the code that makes you laugh (or cry)

MagneticWombats
Aug 19, 2004
JUMP!
I was bored. On a friday night. Oh god.

code:
x = [1..999] :: [Int]
ones = ["","one","two","three","four","five","six","seven","eight","nine"]
teens = ["","eleven", "twelve", "thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"]
tens = ["","ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"]
hundred = "hundred"

toString :: Int -> [Char]
toString x 
    | (x<10) = ones !! x
    | (x>10 && x<20) = teens !! (mod x 10)
    | (x==10) = tens !! 1
    | (x>=20 && x<100) = let tensPlace = (div x 10) in
                            (tens !! tensPlace)++" "++(toString (mod x 10))
    | (x>=100) = let hunPlace = (div x 100) in
                     (ones !! hunPlace)++" "++
                     hundred++" "++(toString (mod x 100))
                     
nnnbottles =
    sequence_ $ map putStrLn $ map toString [1..999]
LOL fp for the win. Also there is no "and" between hundreds and tens in America.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

Chain Chomp posted:

Is this going to become another fizzbuzz? As with that, anyone who posts a solution is probably not fit to do so.
And for anyone who is...

OneEightHundred fucked around with this message at 09:33 on Jul 12, 2008

MrMoo
Sep 14, 2000

mofmog posted:

I was bored. On a friday night. Oh god.

Oh dear, difficult to be so concise in C:

code:
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
atostr (char* dest, const char* src)
{
	static const char* digit[] = { "zero", "one", "two", "three", "four", 
  "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", 
  "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", 
  "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
	long val;
	char* endptr;

	val = strtol (src, &endptr, 10);

	if (	(errno == ERANGE && (val == LONG_MAX || val == LONG_MIN) )
	     ||	(errno != 0 && val == 0)	)
	{
		perror ("strtol");
		return EXIT_FAILURE;
	}

	if ( endptr == src ) {
		fprintf (stderr, "No digits were found\n");
		return EXIT_FAILURE;
	}

	if ( val > 999 ) {
		fprintf (stderr, "Number out of range\n");
		return EXIT_FAILURE;
	}

	*dest = 0;

	do {
		if ( val > 99 ) {
			strcat (dest, digit[ val / 100 ]);
			strcat (dest, " hundred");
			if ( val %= 100 ) {
				strcat (dest, " and ");
			} else {
				break;
			}
		}

		if ( val > 19 ) {
			strcat (dest, digit[ val / 10 + 18 ]);
			if ( val %= 10 ) {
				strcat (dest, "-");
			} else {
				break;
			}
		}

		strcat (dest, digit[ val ]);
		break;

	} while (val);

	*dest = toupper (*dest);

	return EXIT_SUCCESS;
}

int
main (int argc, char* argv[])
{
	char buff[1024];

	if (argc != 2 || atostr( buff, argv[1] ) == EXIT_FAILURE) {
		fprintf (stderr, "Usage: %s [NUMBER]\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	puts (buff);

	return EXIT_SUCCESS;
}

chips
Dec 25, 2004
Mein Führer! I can walk!
For some reason when I did problem 17 on eulerproject, I decided to do this for teens:

code:
if($n == 11) $output .=  "eleven\n";
else if($n == 12) $output .=  "twelve\n";
else if($n == 13) $output .=  "thirteen\n";
else if($n == 15) $output .=  "fifteen\n";
else if($n > 12 && $n < 20) $output .=  str_replace("tt", "t", $numbers[$n % 10] . "teen") . "\n";
else $output .=  $tens[$n / 10] . " " . $numbers[$n % 10] . "\n"; 
I'm sure it made sense at the time, except it takes up more space.

To contribute something other than my lovely code - the Fortran code I'm seeing as a vacation student in a physics department makes me cringe. Maybe I'm just too dumb to understand what the indecipherable variable names are for (given that all the code is in a single function anyway, all 12 pages or so), or understand the flow given the complete lack of comments.

6174
Dec 4, 2004

chips posted:

To contribute something other than my lovely code - the Fortran code I'm seeing as a vacation student in a physics department makes me cringe. Maybe I'm just too dumb to understand what the indecipherable variable names are for (given that all the code is in a single function anyway, all 12 pages or so), or understand the flow given the complete lack of comments.

Nope, that is how physicists program in Fortran. Most of the ones I've known see programing as that unfortunate necessity of doing research and therefore learn just enough to hack together spaghetti code and leave it at that.

One of my friends who is a physics grad student was handed a program by a professor written by the professor and told to set it up on a small cluster the university just bought. He was instructed that he was not allowed to make any changes, despite the fact that the program doesn't compile on the cluster due to different compilers. Yet he is still somehow supposed to make this work.

grapesmoker
Apr 19, 2003

This moon-cheese will make me very rich... very rich indeed!

chips posted:

To contribute something other than my lovely code - the Fortran code I'm seeing as a vacation student in a physics department makes me cringe. Maybe I'm just too dumb to understand what the indecipherable variable names are for (given that all the code is in a single function anyway, all 12 pages or so), or understand the flow given the complete lack of comments.

See my story on the previous page! With a younger generation of physicists rising in academia, the programming standards are improving by a lot, but much of the older stuff is truly horrendous. The worst are old codes that can't possibly be changed because every useful piece of software depends on them.

N.Z.'s Champion
Jun 8, 2003

Yam Slacker

sarehu posted:

I wrote one in XSLT :(

How did you do that? Wouldn't the nesting of call-templates cause a stack overflow?

Or did you <xsl:for-each select="//node()[position() &lt; 999999]"><xsl:value-of select="position()"/></xsl:for-each> or something?

I want to see this abomination

N.Z.'s Champion fucked around with this message at 00:28 on Jul 14, 2008

sarehu
Apr 20, 2007

(call/cc call/cc)

N.Z.'s Champion posted:

How did you do that? Wouldn't the nesting of call-templates cause a stack overflow?

Or did you <xsl:for-each select="//node()[position() &lt; 999999]"><xsl:value-of select="position()"/></xsl:for-each> or something?

I want to see this abomination

There really aren't that many levels of recursion needed, I don't know what kind of crazy algorithm you're thinking of.

sarehu fucked around with this message at 04:27 on Jul 14, 2008

gold brick
Jun 19, 2001

no he isn't
code:
Try
  foo1 = table.Rows(0).Item("foo1")
Catch ex As Exception
  foo1 = False
End Try

Try
  foo2 = thisdt.Rows(0).Item("foo2")
Catch ex As Exception
  foo2 = False
End Try

Try
  foo3 = thisdt.Rows(0).Item("foo3")
Catch ex As Exception
  foo3 = False
End Try

[ etc ]
This Function's common case throws away about 7 stack traces.

gold brick
Jun 19, 2001

no he isn't
code:
 If SomeCondition.IsTrue _
   If Not SomeCondition.IsTrue _
   [...]
code:
If ViewState("UploadedFile") Is Nothing Then ViewState("UploadedFile") = Nothing
Return ViewState("UploadedFile")
Maintaining this program is a zen exercise.

Reformed Pissboy
Nov 6, 2003

Save the whales posted:

Jesus. Settle down.

I may be misinterpreting this whole chain of events, but I'm pretty sure Chain Chomp is not insulting this thread itself, but referencing the fact that the blog on which the whole fizzbuzz thing occurred was named Coding Horror and using the thread title as a hint to its name.

Tetrad
Nov 3, 2002
I don't remember the exact code syntax, but one engineer who no longer works with us essentially wrote something like this:

code:
void Screen::SetActiveButton( Button& button ) {
     m_activeButton = &button;
}

// meanwhile, in client code...

void SomeScreen::Foo() {
    ...
    Button* activeButton = NULL;
    SetActiveButton( *activeButton );
    ...
}
Sure, it worked, but...

This same person obviously wasn't terribly familiar with C or C++, because I caught one bug that was caused by him C-style casting a pointer to a different type that wasn't related by inheritance. He was literally getting an int out of this class where the address of an int would be in some other class.

Also a header for a function I wrote when I was in my "templates and boost are awesome" phase (which I'm still in).
code:
template< typename VALUE_TYPE >
void AddValue( const std::string& key, VALUE_TYPE* value, boost::function< bool( typename boost::call_traits< VALUE_TYPE >::param_type ) > validationFunc, bool isRequired );

Volte
Oct 4, 2004

woosh woosh
I came across the original version of the Ken's Labyrinth source code by Ken Silverman of BUILD engine fame (which powered Duke3D) here. It's 8000 LOC in one single C file.

It's pasted here for the time being:
http://rafb.net/p/mrXyPD73.html

:psyduck:

Zombywuf
Mar 29, 2008

Tetrad posted:

He was literally getting an int out of this class where the address of an int would be in some other class.

I've seen strcpy used on std::string, and it worked. The strcpy prototype was brought into scope from gcc header files copied into the project directory tree. With date stamps in the early 90s; this was in 2005.

quote:

Also a header for a function I wrote when I was in my "templates and boost are awesome" phase (which I'm still in).
code:
template< typename VALUE_TYPE >
void AddValue( const std::string& key, VALUE_TYPE* value, boost::function< bool( typename boost::call_traits< VALUE_TYPE >::param_type ) > validationFunc, bool isRequired );

Nothing wrong that :-)

HIERARCHY OF WEEDZ
Aug 1, 2005

I just discovered about 120 lines of code in an application that were ripped wholesale from EX-DESIGNZ.NET (totally radical). It's also code that I have to debug and fix. The best part is you can tell it was stolen from a website because it's the only code in our 150,000 line codebase that has comments. :suicide:

Zombywuf
Mar 29, 2008

code:
namespace Core.Framework.DataType.BooleanUtils
{
	public static class BooleanFormatter
	{
		/// <summary>
		/// returns string representation of boolean value based on passed definitions of <value>true</value> and <value>false</value>
		/// </summary>
		/// <param name="value"></param>
		/// <param name="trueValue"></param>
		/// <param name="falseValue"></param>
		/// <returns></returns>
		public static string Format(bool value, string trueValue, string falseValue)
		{
			return value ? trueValue : falseValue;
		}
	}
}
Words fail me.

_aaron
Jul 24, 2007
The underscore is silent.

Zombywuf posted:

Words fail me.
No, see, this is great, because then you can do things like:
code:
string boolString = BooleanFormatter.Format(true, "false", "true");
MessageBox.Show(true.ToString() + " is " + boolString);
You don't see the utility here!? Not to mention the deep philosophical implications of subjectively defining "true" and "false"...

Vanadium
Jan 8, 2005

As posted in ##c++ on freenode:
code:
iteration_begin:
std::vector<CGameEvent*>::iterator lIterator = mEvents.begin();
for(lIterator; lIterator != mEvents.end(); lIterator++)
{
	if((*lIterator)->Dirty())
	{
		DestroyEvent(*lIterator);
		//Yes this is a shame, but once we remove an element the iterator is invalidated
		// there is for sure a better way to handle this, we do not want to only break
		// as this would keep the remaining event from being iterated
		goto iteration_begin;
	}
	(*lIterator)->OnIterate(inDeltaT);
}

chocojosh
Jun 9, 2007

D00D.

Vanadium posted:

As posted in ##c++ on freenode:
code:
iteration_begin:
std::vector<CGameEvent*>::iterator lIterator = mEvents.begin();
for(lIterator; lIterator != mEvents.end(); lIterator++)
{
	if((*lIterator)->Dirty())
	{
		DestroyEvent(*lIterator);
		//Yes this is a shame, but once we remove an element the iterator is invalidated
		// there is for sure a better way to handle this, we do not want to only break
		// as this would keep the remaining event from being iterated
		goto iteration_begin;
	}
	(*lIterator)->OnIterate(inDeltaT);
}

Would it have been so hard to keep a second vector of invalid nodes and then invalidate those after the for loop?

Vanadium
Jan 8, 2005

chocojosh posted:

Would it have been so hard to keep a second vector of invalid nodes and then invalidate those after the for loop?

Keeping a vector of invalid nodes does not solve the problem at all because that just replaces the Dirty() check with a check against the vector of invalid nodes. :(

The proper solution (edit: which is not directly compatible with the guy's architecture, yeah) looks like
code:
for (iterator it = v.begin(); it != v.end(); ) {
  if (condition)
    it = v.erase(it);
  else
    ++it;
}
or, more functionally, v.erase(std::remove_if(v.begin(), v.end(), conditionfunctor), v.end()); (both from ##c++'s handy bot).

Vanadium fucked around with this message at 20:04 on Jul 31, 2008

chocojosh
Jun 9, 2007

D00D.
Sorry, I wasn't clear, I meant:

code:
std::vector<CGameEvent*>::iterator lIterator = mEvents.begin(); 
std::vector<CGameEvent*> invalidEvents;

for(lIterator; lIterator != mEvents.end(); lIterator++) { 
    if((*lIterator)->Dirty()) { 
        invalidEvents.push_back(*lIterator);
    } 
    (*lIterator)->OnIterate(inDeltaT); 
}

//Starting at last node in case vector size changes
for(int i = invalidEvents.size(); i >= 0; i--) {
    DestroyEvent(invalidEvents[i]);
}
I haven't touched the STL in over two years though -- your code makes much more sense.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
You're both missing the real problem. DestroyEvent() takes a CGameEvent* (or CGameEvent*&); it's not invalidating any iterators. So, that comment is ironic, because the remaining events won't be iterated. mEvents.begin() isn't going to change, so re-accessing or deleting that element that got destroyed on the first iteration will probably crash the program.

edit: What's an "lIterator" supposed to be, anyhow? Loser Iterator?

Mustach fucked around with this message at 21:17 on Jul 31, 2008

Vanadium
Jan 8, 2005

Mustach posted:

You're both missing the real problem. DestroyEvent() takes a CGameEvent* (or CGameEvent*&); it's not invalidating any iterators. So, that comment is ironic, because the remaining events won't be iterated. mEvents.begin() isn't going to change, so re-accessing or deleting that element that got destroyed on the first iteration will probably crash the program.

I assumed that DestroyEvent was going to modify the vector on its own, looking up the element being destroyed by value.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Oh man, that would make that segment of code a lot worse.

Zombywuf
Mar 29, 2008

_aaron posted:

No, see, this is great, because then you can do things like:
code:
string boolString = BooleanFormatter.Format(true, "false", "true");
MessageBox.Show(true.ToString() + " is " + boolString);
You don't see the utility here!? Not to mention the deep philosophical implications of subjectively defining "true" and "false"...

I can't help but feel you've missed everything that's wrong with the code I posted.

tef
May 30, 2004

-> some l-system crap ->

Zombywuf posted:

I can't help but feel you've missed everything that's wrong with the code I posted.

You didn't post it all either, the Boolean Utilities class has four methods. Only one of which uses the Formatter method, the other two use the ternary operator.

A method so useful he couldn't be bothered to use it.

Xenopax
Sep 27, 2002

Get pregnant using Xenopax® brand bottled semen. Trust no substitutes.
Oh god I wish I had the space to paste all the bad code I've seen. Here's a list of some of the worst:

#1 Worst
I once inherited an ASP site that pushed everything it did through a generic page called something like "functions.asp" that had about a bazillion if statements to handle every possible posting from any page on the site. For instance if you changed the name of someone then changename.asp would post to functions.asp to make the change and then redirect to whatever.asp. Also there were many many many cases where the difference between two things was one line, with 100+ lines copied and pasted, so functions.asp was like 30,000 lines long. I'm not even joking about that. Needless to say I was very happy that project was rarely used and no one ever requested changing anything large in it otherwise I would have had to recode the entire thing.

#2 Worst
The current website I'm working on is half written in .NET and half in vanilla ASP. The ASP side uses Mysql, and the .NET side works with SQL Server. Both sides represent half of each of our products, and there is hardly any sharing of information across the two. When I say half of our products I don't mean half of our store is one one side and the other half is on the other, I mean each product has half of its information in MySQL and the other half in SQL Server and each site's product pages just cross-link to each other. If that sounds confusing that's because it is, people here get lost on our site so our customers really have no hope and I'm pretty sure we make sales purely on luck. My project for the last few months has been to scrap both sites and rewrite the entire thing.

If that wasn't bad enough, the .NET side is a rather complex online-book system. This system uses a completely different DAL for the user side as opposed the admin side, and neither DAL maps tables or views to objects, they merely map queries to datareaders and have very static insert/update functions that need to be adjusted or created whenever you want to do something different. We're currently converting everything to be based on extended SubSonic objects.

#3 Worst
Regrettably this happened on a project where I was leading the development. A programmer we hired because he was very experienced (20 years) but never wrote any .NET decided the best way to handle database results was to load everything into parallel arrays. Parallel arrays that existed in the default page. So in Default.aspx.cs you would have an array for each field that was returned, for every query. These arrays were also where information that was to be inserted and updated were stored and that was handled by many many many specialized functions that made absolutely no sense to me. Luckily this was limited to just the sign-up section and didn't effect the main application and was easily rewritten. Note this happened after I walked him through our DAL as well. It certainly explained why it took him 3 weeks to create a couple of registration pages.

HIERARCHY OF WEEDZ
Aug 1, 2005

code:
SELECT thecolumn, thevalue
FROM tblRevenue
No, I didn't anonymize that. Those are the actual column names.

Adbot
ADBOT LOVES YOU

MoNsTeR
Jun 29, 2002

code:
select some_crap
from some_table@devl2
Yes, let's push code all the way out to production that depends on a database link back to development! What could possibly go wrong?

code:
exception
  when others then
    null;
Yes! Trap those pesky errors and throw them away! No need to bother even logging them I mean who looks at that poo poo anyway. loving SWEET.

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