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
zero knowledge
Apr 27, 2008

NotShadowStar posted:

Uh can't you write if (thefile_counter == 54) { thefile_counter = 0; } on the assignment and give him an F because ffffffffff

I was very frustrated when I was TAing an intro-level programming course because we were given incredibly anal grading schemes that didn't allow us to give Fs or remove more than 2 marks (out of 100) for this kind of thing. The grading scheme stopped just short of actually providing unit tests and as long as it met that spec, they got nearly full marks, even though the code is completely offensive.

Adbot
ADBOT LOVES YOU

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Suspicious Dish posted:

Switch statements are jump tables, so they're faster than if statements!

And with more billable hours, it's truly win-win!.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Spazmo posted:

I was very frustrated when I was TAing an intro-level programming course because we were given incredibly anal grading schemes that didn't allow us to give Fs or remove more than 2 marks (out of 100) for this kind of thing. The grading scheme stopped just short of actually providing unit tests and as long as it met that spec, they got nearly full marks, even though the code is completely offensive.

Well, can't you at least remove those 2 marks and add a note "if (thefile_counter == 54) { thefile_counter = 0; } :milk:"

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.
There's two date fields in this database that I'm working on...

code:
Date_In: decimal(14,0)
Date_Out: decimal(14,0)
That's odd, I think... 14 digit decimals with... no decimal... so like a 14 digit integer?

Surely a unix timestamp should be longer than that... maybe it's only part of the time stamp, because precision isn't that important. Let's see what the data looks like:

code:
mysql> SELECT Date_In, Date_Out FROM `OrderTbl` WHERE 1 LIMIT 5;
+----------------+----------------+
| Date_In        | Date_Out       |
+----------------+----------------+
| 20041022104311 | 20041022114227 |
| 20041022162931 | 20041022171255 |
| 20041022170845 | 20041022171710 |
| 20041025120848 | 20041025163313 |
| 20041025121018 |              0 |
+----------------+----------------+
5 rows in set (0.00 sec)
So they're strings. Stored as integers. In a decimal column. Representing dates.

gently caress.

gonadic io
Feb 16, 2011

>>=

bobthecheese posted:

Storing dates

Why is this such a common mistake? If there is a DATE datatype, can't people see that when they're looking at the other ones (to get the decimal function for example)? I honestly don't get it.

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.

employer posted:

we didn't know of unix timestamps
like, did not know
and we had dates only
but didn't see date time
and had to store seconds
and found this

I found other parts of the code like that which go back another 4+ years further than this one.

Now I'm writing my own horror to deal with it.

code:
SELECT `Order_Num`, `Date_In`, `Date_Out`, 
if(`Date_In` < $dayStart, 0, substr(`Date_In`,9,2)) as hourAdded,
if(`Date_Out` = 0, 24, substr(`Date_Out`,9,2)) as hourShipped
FROM OrderTbl
WHERE `Date_In` < $dayFinish
AND (`Date_Out` > $dayStart OR `Date_Out` = 0)
Uggghhh. I hate myself.

raminasi
Jan 25, 2005

a last drink with no ice

bobthecheese posted:

There's two date fields in this database that I'm working on...

code:
Date_In: decimal(14,0)
Date_Out: decimal(14,0)
That's odd, I think... 14 digit decimals with... no decimal... so like a 14 digit integer?

Surely a unix timestamp should be longer than that... maybe it's only part of the time stamp, because precision isn't that important. Let's see what the data looks like:

code:
mysql> SELECT Date_In, Date_Out FROM `OrderTbl` WHERE 1 LIMIT 5;
+----------------+----------------+
| Date_In        | Date_Out       |
+----------------+----------------+
| 20041022104311 | 20041022114227 |
| 20041022162931 | 20041022171255 |
| 20041022170845 | 20041022171710 |
| 20041025120848 | 20041025163313 |
| 20041025121018 |              0 |
+----------------+----------------+
5 rows in set (0.00 sec)
So they're strings. Stored as integers. In a decimal column. Representing dates.

gently caress.

It's the data modeling version of inception.jpg.doc.pdf.xls.eml!

w00tz0r
Aug 10, 2006

I'm just so god damn happy.

bobthecheese posted:

So they're strings. Stored as integers ... Representing dates.

The GPS devices we use encode date information that way, with 6 digits representing YYMMDD. The fact that someone would think it's a good idea on a large scale makes my head hurt.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
It is extremely bizarre, but it's not the worst thing ever. At least you can still test whether one time is before or after another just using comparison operators. Of course you could do that with unix timestamps too. And you can't easily find the difference between two times. And you have your work cut out for you if you want to express an idea like "one week ago" or... well actually maybe it is the worst thing ever.

Luminous
May 19, 2004

Girls
Games
Gains

Apok posted:

I'd think it has to do with the gigantic tables scattered throughout. If you broke things down to third normal form, you'd have a bunch of smaller tables.

This is kinda meaningless. I was wanting examples of the lack of normalization. Yes, we all can assume that big tables probably means bad normalization, but 1) you can't actually say that with certainty (for all you know, all of those columns are a single unique key (a horrifying thought all on its own)) and 2) it'd be fun to see what sorts of problems their database designer actually created due to not normalizing.

Zamujasa
Oct 27, 2010



Bread Liar
Most of the code at my new job is written by one of four people (Myself included, now) and most of it is pretty terrible, with mine arguably being the last bad (but still bad) and the worst, well.


You know Apache log configuration? The stuff that goes "LogFile /var/logs/apache/access.log combined"?

They had the bright idea to use something nonstandard there (we'll say "all_subdomains_combined"). There was, up until yesterday, hundreds of megabytes worth of rotated and zipped data filled with nothing but hundreds of thousands of lines with just "all_subdomains_combined".


Oh, and most of the actual code is entirely unindented and cargo-culted. It gets worse the more I look at it.

A full list of horrors would probably spawn Cthulhu, honestly. On its own it wouldn't be so bad, but there's just so much of it.

ToxicFrog
Apr 26, 2008


Hammerite posted:

It is extremely bizarre, but it's not the worst thing ever. At least you can still test whether one time is before or after another just using comparison operators. Of course you could do that with unix timestamps too. And you can't easily find the difference between two times. And you have your work cut out for you if you want to express an idea like "one week ago" or... well actually maybe it is the worst thing ever.

No, the worst thing ever would be that, except in US-style MMDDYYHHMMSS format so you can't even use comparison operators to see which date comes first.

NotShadowStar
Sep 20, 2000
What scrub languages are you guys using that doesn't have a nice date library to parse a string?

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

NotShadowStar posted:

What scrub languages are you guys using that doesn't have a nice date library to parse a string?

Why would you want to pull all that data to do range queries if the dbms could have just done it for you if you simply didn't make a piece of poo poo in the first place?

Pangolin Poetry
Jan 1, 2008
a recent horror that I constructed was to have a program calculate integers, then output them to a file as strings, which were then read into a different program as strings, which were then re-converted to integers, then cast as floats inside an array. then, i graphed them.

Scaevolus
Apr 16, 2007

Pangolin Poetry posted:

a recent horror that I constructed was to have a program calculate integers, then output them to a file as strings, which were then read into a different program as strings, which were then re-converted to integers, then cast as floats inside an array. then, i graphed them.

It sounds like you've implemented a poor man's version of UNIX pipes.

kuf
May 12, 2007
aaaaaa

NotShadowStar posted:

Uh can't you write if (thefile_counter == 54) { thefile_counter = 0; } on the assignment and give him an F because ffffffffff
To be fair/make things infinitely worse, this person was going to write different routines for each case: each case being the different positions of records of a csv. But each row was to have 27 records, so the idea was that he was dealing with two rows at a time.

The csv was to have a "special format" with the typical field descriptions being reentered after each row of records (eg: A,B,C\n 1,2,3\n A,B,C\n 4,5,6), and each row needed to end with an extra comma, and the "ID" field needed to be last. When explaining why I was frustrated about this solution, he replied: "Can you just guarantee the files will be this way?"

I decided to just designate a portion of the data we created as his. It's not like he finished with his solution, anyway. I really hope I get to see it when it's done.

Look Around You
Jan 19, 2009

DotFortune posted:

To be fair/make things infinitely worse, this person was going to write different routines for each case: each case being the different positions of records of a csv. But each row was to have 27 records, so the idea was that he was dealing with two rows at a time.

The csv was to have a "special format" with the typical field descriptions being reentered after each row of records (eg: A,B,C\n 1,2,3\n A,B,C\n 4,5,6), and each row needed to end with an extra comma, and the "ID" field needed to be last. When explaining why I was frustrated about this solution, he replied: "Can you just guarantee the files will be this way?"

I decided to just designate a portion of the data we created as his. It's not like he finished with his solution, anyway. I really hope I get to see it when it's done.

What.

I would have just said "no" but maybe I'm kind of a dick?

kuf
May 12, 2007
aaaaaa
We were up against a deadline, I was tired of arguing, he wanted to feel like he contributed to the project - and if he had used a library like I had suggested then all of his hard work on typing fifty-four case statements would have been in vain. It was okay for me to just let it go.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.
I wrote a coding horror today, in stripped down form it worked like this:

code:
    class Program
    {
        static Thread t;
        static event EventHandler AnErrorHappened;
        static bool cancelThread = false;

        static void Main(string[] args)
        {
            AnErrorHappened += AnErrorHappenedEventHandler;
            t = new Thread(DoAThing);
            t.Start();
        }

        static void DoAThing()
        {
            AnErrorHappened(new object(), new EventArgs());
            while (!cancelThread) { }; // do some work
        }

        static void AnErrorHappenedEventHandler(object sender, EventArgs e)
        {
            cancelThread = true;
            t.Join();
        }
    }
It starts a thread that raises an event that attempts to join the thread with itself. This causes the thread to block while waiting for itself to die, but it can't ever die because it's blocked. :toot:

1337JiveTurkey
Feb 17, 2005

Dessert Rose posted:

What underlying language invariants does this violate? You started 100 threads that all call a method on an object that mutates shared state without synchronization.

If you didn't want to have that shared state then don't close over it. Or assign it to a closure-local variable.

Changes to local variables are thread-safe and don't require synchronization. Activation records exist only within the context of a single thread. Activation record lifespans are coterminous with the execution of their associated method. You know, stuff that programmers generally take for granted to the point they don't even think about it any more.

quote:

C# handles this just fine.

What's the scope of a loop variable? Closures over variables introduce a lot of subtle issues as to how a language works which closures over values don't.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

1337JiveTurkey posted:

What's the scope of a loop variable? Closures over variables introduce a lot of subtle issues as to how a language works which closures over values don't.

Sometimes closing over a value is the desired behaviour, but other times you want to close over a variable.

The syntax to close over a value when your closures close over variables is simple and isolated to the point that you create the closure - while the syntax to close over a variable when your closures only close over values is ugly and affects everywhere that variable is used.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
So I mashed this out earlier today and it made me wonder, would it make people in this thread think I am a horror?

http://pastebin.com/LYHQPXMb

I am thinking particularly about lines like

code:
$regions[$row['Region']]['Species'][$row['Species']]['Languages'][$row['Language']] =
    $row['TickCode'];

...

$regions[$row['Region']]['Species'][$row['Species']]['Forms'][$row['Form']]['Seen'] =
    $row['TickCodeOrdinary'];
What this line does seems straightforward to me to work out, but on the other hand from the sheer number of nested []'s I can see why somebody might look at it and want me not to be alive any more.

(Don't bother castigating me over the use of mysqli_query() with variables concatenated in, I know that looks/is awful and IDGAF)

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Hammerite posted:

So I mashed this out earlier today and it made me wonder, would it make people in this thread think I am a horror?

It's PHP, so, yes :v:

Though actually, "grab everything -> munge in PHP" (when you could write a proper query and get it already-munged) probably is a horror.

1337JiveTurkey
Feb 17, 2005

Jabor posted:

Sometimes closing over a value is the desired behaviour, but other times you want to close over a variable.

The syntax to close over a value when your closures close over variables is simple and isolated to the point that you create the closure - while the syntax to close over a variable when your closures only close over values is ugly and affects everywhere that variable is used.

And yet other times you want partial evaluation with pass-by-reference semantics. If there's perfectly serviceable language constructs for doing something like sharing mutable state throughout a program, we don't need to shoehorn that capability into constructs never intended for that purpose.

Beef
Jul 26, 2004
Dear GOD

http://www.daniweb.com/web-development/php/threads/190561

code:
<script type="text/javascript">
function myfunction()
{
a=document.form.objective.value;
b=parseInt(a);
c=document.form.topic.value;
d=parseInt(c);
e=document.form.coordination.value;
f=parseInt(e);
g=document.form.instructor.value;
t=parseInt(g);
h=document.form.audiovisual.value;
i=parseInt(h);
j=document.form.enjoy.value;
k=parseInt(j);
l=document.form.recommend.value;
m=parseInt(l);
n = (b+d+f+t+i+k+m);
document.form.total1.value =n;

a1=document.form.benefit.value;
b1=parseInt(a1);
c1=document.form.learnt.value;
d1=parseInt(c1);
e1=document.form.apply.value;
f1=parseInt(e1);
g1=document.form.aspires.value;
t1=parseInt(g1);
h1=document.form.share.value;
i1=parseInt(h1);
j1=document.form.motivate.value;
k1=parseInt(j1);
l1=document.form.asset.value;
m1=parseInt(l1);
n1 = (b1+d1+f1+t1+i1+k1+m1);
document.form.total2.value =n1;

a2=document.form.trainer2.value;
b2=parseInt(a2);
c2=document.form.trainer3.value;
d2=parseInt(c2);
e2=document.form.trainer4.value;
f2=parseInt(e2);
g2=document.form.trainer5.value;
t2=parseInt(g2);
h2=document.form.trainer6.value;
i2=parseInt(h2);
n2 = (b2+d2+f2+t2+i2);
document.form.total3.value =n2;

a3=document.form.trainer9.value;
b3=parseInt(a3);
c3=document.form.trainer10.value;
d3=parseInt(c3);
e3=document.form.trainer11.value;
f3=parseInt(e3);
g3=document.form.trainer12.value;
t3=parseInt(g3);
h3=document.form.trainer13.value;
i3=parseInt(h3);
n3 = (b3+d3+f3+t3+i3);
document.form.total4.value =n3;

a4=document.form.trainer15.value;
b4=parseInt(a4);
c4=document.form.trainer16.value;
d4=parseInt(c4);
e4=document.form.trainer17.value;
f4=parseInt(e4);
g4=document.form.trainer18.value;
t4=parseInt(g4);
h4=document.form.trainer19.value;
i4=parseInt(h4);
j4=document.form.trainer20.value;
k4=parseInt(j4);
n4= (b4+d4+f4+t4+i4+k4);
document.form.total5.value =n4;
}
</script>

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

Reminds me of VB code I might have written when I was in middle school.

Coffee Mugshot
Jun 26, 2010

by Lowtax

:stare:

The part you quoted is the worst part but jesus christ, everything in that markup is awful. I guess it was a couple years ago, so maybe they've learned their lesson?

Jewel
May 2, 2009

I love how the only reply is "HAHAHAHAH"

Zakath
Mar 22, 2001

Suspicious Dish posted:

Switch statements are jump tables, so they're faster than if statements!
I'm glad I've been following this thread. I've been working on an assembly coding project for a 8051-based microcontroller, and using jump tables will help clear up this mess:
code:
    MOV DPTR, #CASE_NUMBER
    MOVX A, @DPTR

    JNZ CHECK_NEXT_1 
    LJMP CASE_0
    
    CHECK_NEXT_1:
    DEC A
    JNZ CHECK_NEXT_2
    LJMP CASE_1

    CHECK_NEXT_2:
    DEC A
    JNZ CHECK__NEXT_3
    LJMP CASE_2

    ...

    CHECK_NEXT_21:
    DEC A
    JNZ CHECK_NEXT_22
    LJMP CASE_21
    
    CHECK_NEXT_22:
    LJMP CHECK_DONE
It started off as only a few cases, but ballooned as I continued working on the parts of the code that are jumped to. I promised myself I would make it better, but had mostly forgotten about it. It makes me sort of paranoid about what other stupid things I've been doing, with the thought that I would fix them later.

raminasi
Jan 25, 2005

a last drink with no ice
I just found this in my own code:
code:
size_t rot = 0;
auto p = b_area.vertices_begin();
while (*b_area.vertices_begin() != *p) {
	++p;
	++rot;
	assert(p != b->pzbs().area().vertices_end());
}
What...what was I doing :ohdear: That is a no-op, right? (rot is used later...it's added to something.) I'm scared to take it out.

tractor fanatic
Sep 9, 2005

Pillbug
Doesn't it count the number of vertices?

raminasi
Jan 25, 2005

a last drink with no ice
Isn't the while condition going to start false and stay that way?

tractor fanatic
Sep 9, 2005

Pillbug
Oh haha duh

Hughlander
May 11, 2005

It doesn't quite fit in this thread as it's not a coding horror per say, but it did make me laugh and/or cry...

Had a crash in a final build of a project at work, it was kind of like:

code:
Class* pClass = something();
if(pClass)
{
    error_log("NULL class found.");
    return;
}
SomeFunc(pClass, arg2, arg3);
...

void SomeFunc(pClass, arg2, arg3)
{
    SomeValue value = SomeOtherFunc(pClass);
    ....
}

SomeValue SomeOtherFunc(Class* pClass)
{
    SomeValue value = pClass->GetValue();

    if(g_SomeGlobal > 3 &&
       StillSomeOtherFunc() &&
       value < 2 )
    {
        return 2;
    }

    return value;
}

bool StillSomeOtherFunc()
{
#if defined(FINAL_BUILD)
    return false;
#else
...
#endif
}
So, given all that the crash was in the first line of SomeOtherFunc, and here's where I started to laugh and cry...

Looking at the assembly dump, that first line was basically:
code:
li r0, 0xc0(r4)
The entirety of SomeOtherFunc() was inlined into that single statement because the optimizing compiler saw that StillSomeOtherFunc() would always return false and therefore the if block was a no-op and could be removed.

r4 was obviously NULL and the whole thing was a NULL dereference. But the freaky part is that while I had the disassembly open I looked at the call into SomeFunc() and I saw:

code:
stw r0, 0
jmp [SomeFunc]
That's right. The optimizing compiler didn't even bother with the variable pClass because at compile time it saw that the only way to execute the call to SomeFunc() was with pClass already being NULL.

The drat thing had everything it needed to have static code analysis tell me "Dipshit, this is going to be a NULL dereference, it literally can't be anything but." But the compiler isn't quite at that next step yet. Some day soon we're in for an amazing time.

(The problem obviously was if(pClass) instead of if(!pClass) but it was such a rare edge case that it has been in the main code base for over a year without ever being hit until this week.)

Plorkyeran
Mar 22, 2007

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

GrumpyDoctor posted:

Isn't the while condition going to start false and stay that way?
Only if operator != has a sensible definition. The loop could run one or infinite times with non-insane bugs.

I sort of hope that in practice it manages to always run exactly twice.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Plorkyeran posted:

Only if operator != has a sensible definition. The loop could run one or infinite times with non-insane bugs.

I sort of hope that in practice it manages to always run exactly twice.

For all you know vertices_begin() could be unstable and give you a different value when you call it the second time.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Actually, the code would "work" if vertices_begin() removed the element it returned an iterator pointer to, unless the list is empty, in which case it would simply always return end, and dereferencing end works and returns a value equal to only itself.

Clearly you should alter the rest of the code to work this way.

raminasi
Jan 25, 2005

a last drink with no ice
That block is in a weird source file. It's not egregiously or even particularly ugly, but it's full of weird little poo poo like that, and plenty of other ones straight-up break everything when you "fix" them. I've done a number of significant refactorings to make logic more generally usable across the whole program, but that source file can never make use of them without something breaking, and I don't know why. It's not like it was written by someone else; it's all my code. It's like a haunted house. But not the grisly kind of haunted house; rather, the kind that's vaguely creepy that you never, ever want to stay in for too long because you can swear the walls are whispering or something and every family that's moved in next door has moved out within six months. I try to keep it quarantined.

Adbot
ADBOT LOVES YOU

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I know Zope is all sorts of terrible ideas and bonghits, but this is just atrocious: minjson.py. It tries to use Python's tokenizer to parse JSON. It works as well as you think it would. Considering I've made a hand-written JSON parser in an hour to win a bet, there is no excuse for this.

(The bet was related to Prototype's use of regex to validate JSON and then parse it using eval(), which is a horror in and of itself. I bet money that there was no excuse -- the JSON spec was easy enough to hand-write a recursive-descent parser for in an hour. I won.)

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