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
gibbed
Apr 10, 2006

bmoyles posted:

code:
while(list($key,$val) = each($_POST)) {
        $$key = $val;
}

while(list($key,$val) = each($_GET)) {
        $$key = $val;
}
I see this all the time and it makes my heart sad :(.

Adbot
ADBOT LOVES YOU

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


gibbed posted:

I see this all the time and it makes my heart sad :(.

It's the `Even tho register_globals is turned off, I want to use them anyways` move

rotor
Jun 11, 2001

classic case of pineapple derangement syndrome

_aaron posted:

No space before the comma? Clearly this person doesn't know how to properly use white space.

they should be using tabs, not spaces. :colbert:

code:
if  (    x    >    0    )    {
    x    +=   y    ;
}
see how tidy that looks? everything lines up in nice columns. Clearly, this is the superior way to write code.

edit: GAH, just turned avatars back on. When did I get that one?

rotor fucked around with this message at 23:44 on Apr 12, 2008

chips
Dec 25, 2004
Mein Führer! I can walk!

Scaevolus posted:





The first part of someone's solution:
code:
#First load the file and sort it.
x = eval( '[' + open( '.../names.txt' ).readlines()[ 0 ] + ']' )
x.sort()
On principle, using eval is always wrong.

I dont think it's really fair to complain about software engineering rights and wrongs in projecteuler answers. I thought it was a reasonable way to get everything in rapidly - not like there was going to be a code injection attack in the middle of it (and maybe he even checked)

npe
Oct 15, 2004
Some of the old perl code I've found here was written by someone who seemed to think entire subroutines had to be on a single line. Lots of

code:

sub foo {my $blah=$_[0];foreach my $item(@_){etc etc etc}return $foo;}

I also found a hash definition that line wraps 14 times in my text editor. :psyduck:

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
Just found this.. not really a horror per say, but WTF:

php:
<?
<style>
<?if(!$_GET['article']){?>

*{
    
}
<?}?>
</style>
?>

fret logic
Mar 8, 2005
roffle
Before now I was on the fence about going and talking to the department head since previous lectures hinted that my professor actually isn't half bad. Well, not after today. I'm going to have nightmares about this I think:

code:
import javax.swing.*;
import java.awt.event.*;

public class BasicCalculator implements ActionListener
{
   private double o1, o2;
   private char operator;
   private JTextField displayBox;
   private JPanel panel;
   private JFrame frame;
   private JButton b0, b1, b2, b3, b4, b5, b6, b7, b8, b9;
   private JButton bdot, badd, bsub, bmul, bdiv, bmod, bcom, bclr;
  
   public BasicCalculator()
   {
       clean();
   }
  
   public void clean()
   {
       o1 = 0;
       o2 = 0;
       operator = ' ';
   }
  
   public static void main(String[] args)
   {
       BasicCalculator calculator;
       calculator = new BasicCalculator();
       calculator.createUserInterface();
   }
  
   public void createUserInterface()
   {
       panel = new JPanel();
       frame = new JFrame("");
       displayBox = new JTextField(20);
       displayBox.setText("");
       b0 = new JButton("0");
       b1 = new JButton("1");
       b2 = new JButton("2");
       b3 = new JButton("3");
       b4 = new JButton("4");
       b5 = new JButton("5");
       b6 = new JButton("6");
       b7 = new JButton("7");
       b8 = new JButton("8");
       b9 = new JButton("9");
       bdot = new JButton(".");
       badd = new JButton("+");
       bsub = new JButton("-");
       bmul = new JButton("*");
       bdiv = new JButton("/");
       bmod = new JButton("%");
       bcom = new JButton("=");
       bclr = new JButton("C");
      
       panel.add(displayBox);
       panel.add(b1);
       panel.add(b2);
       panel.add(b3);
       panel.add(b4);
       panel.add(b5);
       panel.add(b6);
       panel.add(b7);
       panel.add(b8);
       panel.add(b9);
       panel.add(b0);
       panel.add(bdot);
       panel.add(badd);
       panel.add(bsub);
       panel.add(bmul);
       panel.add(bdiv);
       panel.add(bmod);
       panel.add(bcom);
       panel.add(bclr);
      
       b0.addActionListener(this);
       b1.addActionListener(this);
       b2.addActionListener(this);
       b3.addActionListener(this);
       b4.addActionListener(this);
       b5.addActionListener(this);
       b6.addActionListener(this);
       b7.addActionListener(this);
       b8.addActionListener(this);
       b9.addActionListener(this);
       bdot.addActionListener(this);
       badd.addActionListener(this);
       bsub.addActionListener(this);
       bmul.addActionListener(this);
       bdiv.addActionListener(this);
       bmod.addActionListener(this);
       bclr.addActionListener(this);
       bcom.addActionListener(this);
      
       frame.getContentPane().add(panel);
       frame.setSize(250, 300);
       frame.setVisible(true);
   }
   public void actionPerformed(ActionEvent e)
   {
       if(e.getSource() == b0) {displayBox.setText(displayBox.getText() + "0");}
       if(e.getSource() == b1) {displayBox.setText(displayBox.getText() + "1");}
       if(e.getSource() == b2) {displayBox.setText(displayBox.getText() + "2");}
       if(e.getSource() == b3) {displayBox.setText(displayBox.getText() + "3");}
       if(e.getSource() == b4) {displayBox.setText(displayBox.getText() + "4");}
       if(e.getSource() == b5) {displayBox.setText(displayBox.getText() + "5");}
       if(e.getSource() == b6) {displayBox.setText(displayBox.getText() + "6");}
       if(e.getSource() == b7) {displayBox.setText(displayBox.getText() + "7");}
       if(e.getSource() == b8) {displayBox.setText(displayBox.getText() + "8");}
       if(e.getSource() == b9) {displayBox.setText(displayBox.getText() + "9");}
       if(e.getSource() == badd) {
           operator = '+';
           o1 = new Double(displayBox.getText()).doubleValue();
           displayBox.setText("");
       }
       if(e.getSource() == bsub) {
           operator = '-';
           o1 = new Double(displayBox.getText()).doubleValue();
           displayBox.setText("");
       }
       if(e.getSource() == bmul) {
           operator = '*';
           o1 = new Double(displayBox.getText()).doubleValue();
           displayBox.setText("");
       }
       if(e.getSource() == bdiv) {
           operator = '/';
           o1 = new Double(displayBox.getText()).doubleValue();
           displayBox.setText("");
       }
       if(e.getSource() == bmod) {
           operator = '%';
           o1 = new Double(displayBox.getText()).doubleValue();
           displayBox.setText("");
       }
       if(e.getSource() == bclr) {
           clean();
           displayBox.setText("");
       }
       if(e.getSource() == bcom) {
           calculate();
       }
    }
       public void calculate()
       {
           o2 = new Double(displayBox.getText()).doubleValue();
           switch(operator) {
               case '+':displayBox.setText(new Double(o1 + o2).toString()); break;
               case '-':displayBox.setText(new Double(o1 - o2).toString()); break;
               case '*':displayBox.setText(new Double(o1 * o2).toString()); break;
               case '/':displayBox.setText(new Double(o1 / o2).toString()); break;
               case '%':displayBox.setText(new Double(o1 % o2).toString()); break;
       }
          
}
}
Hmmm...

code:
if(guninmouth) {
     while(alive) {
          pullTrigger();
     }
}

fret logic fucked around with this message at 07:54 on Apr 17, 2008

rotor
Jun 11, 2001

classic case of pineapple derangement syndrome

fret logic posted:

Before now I was on the fence about going and talking to the department head since previous lectures hinted that my professor actually isn't half bad. Well, not after today. I'm going to have nightmares about this I think:
[...]

I don't understand how this is supposed to be especially awful for what is, I assume, supposed to be an in-class example or something.

defmacro
Sep 27, 2005
cacio e ping pong

rotor posted:

I don't understand how this is supposed to be especially awful for what is, I assume, supposed to be an in-class example or something.

It's GUI code and no one likes writing GUIs? :hellyeah: <--- (this smiley shows how insanely clever I am, fyi)

Zombywuf
Mar 29, 2008

rotor posted:

I don't understand how this is supposed to be especially awful for what is, I assume, supposed to be an in-class example or something.

for loops, have you heard of them?

narbsy
Jun 2, 2007
if you're doing an in-class example and want to make sure everyone knows what you're doing... then this is better than a for loop due to clarity, at least in my opinion.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

rotor posted:

I don't understand how this is supposed to be especially awful for what is, I assume, supposed to be an in-class example or something.

The horror is obviously Swing itself :colbert:

rotor
Jun 11, 2001

classic case of pineapple derangement syndrome

Zombywuf posted:

for loops, have you heard of them?

-funrolloops

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
I'm not sure what you can do to make that code a lot better. I mean, putting all the JButtons into a hashtable to cut down on variables and allowing you to loop over them to do the repetitive stuff, but if this is a lower level class I'd have second thoughts about even that.

It's sort of crummy code, but it's not a horror or anything.

Zombywuf
Mar 29, 2008

narbsy posted:

if you're doing an in-class example and want to make sure everyone knows what you're doing... then this is better than a for loop due to clarity, at least in my opinion.

/me shudders with horror at the thought that GUI coding should be taught before for loops.

rotor
Jun 11, 2001

classic case of pineapple derangement syndrome

Zombywuf posted:

/me shudders with horror at the thought that GUI coding should be taught before for loops.

I actually agree with narsby. If I was teaching Swing to students, I'd probably keep loops out of the picture as well in a little example like this. I'd be a little :raise: if I saw it in production code, but the new JFrame("Chris Busch's CALCULATOR!!!!!!!!"); probably would be a bigger issue.

edit: Ah, JingleBells in #cobol caught something: he should be using variables for the label names instead of magic values. Nothing happens when you press the '.' button.

doubleedit: oh

rotor fucked around with this message at 19:41 on Apr 14, 2008

JingleBells
Jan 7, 2007

Oh what fun it is to see the Harriers win away!

rotor posted:

I actually agree with narsby. If I was teaching Swing to students, I'd probably keep loops out of the picture as well in a little example like this. I'd be a little :raise: if I saw it in production code, but the new JFrame("Chris Busch's CALCULATOR!!!!!!!!"); probably would be a bigger issue.

The only problems I've found are that nothing happens when you click the decimal point button, and that if you close the window the GUI disappears but the program doesn't exit as no default close action has been specified.

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Decimals are for Chris Busch's CALCULATOR 2.0!!!!!!!!, obviously.

fret logic
Mar 8, 2005
roffle
What's the issue with my excitement over the most amazing CALCULATOR? :)

It's just disgusting looking code, I feel like a for loop statement would be nice to clear it up. I mean, we have learned how to create GUI's, and all of the loops. Why would one of the last programs we write not implement this?

edit: You're probably right though, the entire class was yelling at him to slow down the entire 2 hours we spent doing this, so maybe loops would have been a bad idea.

fret logic fucked around with this message at 20:34 on Apr 14, 2008

Cheesus
Oct 17, 2002

Let us retract the foreskin of ignorance and apply the wirebrush of enlightenment.
Yam Slacker

duz posted:

It's the `Even tho register_globals is turned off, I want to use them anyways` move
Not quite.

That guy wants GET to have more precedence then POST.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Cheesus posted:

Not quite.

That guy wants GET to have more precedence then POST.

So he likes register_globals but finds it too secure?

MasterSlowPoke
Oct 9, 2005

Our courage will pull us through
the language is stackless python, definitions cut off for brevity
code:
/* Clear the data1 and X_k_mag2_2 buffers */
   	CNTR = N;
	do clear until ce;
	dm(I2, M1) = 0;
clear:	dm(I6, M4) = 0;
  
 
main:

/**************** Window multiplication **************************/  
	i7 = window;
	CNTR = N;
	do win until ce;
	mx0 = dm(i2, m0), my0 = pm(I7, m4);
	mr = mx0 * my0(ss);
win: dm(I2, m1) = mr1;

/********* DO DFT *******/

	M6=0;  //start at DC component
	CNTR = N;
	do DFT until CE;
/***** real portion ****/
	i7=wavetable;
	MR=0,mx0=dm(i2,m1), my0=pm(i7,m6);
			CNTR=N-1;
			do cosine until CE;
cosine:	mr=MR+mx0*my0(ss),	mx0=dm(i2,m1), my0=pm(i7,m6);
		mr=MR+mx0*my0(ss);
			sr= lshift mr1 by -8(lo);
			sr= sr or ashift mr2 by -8(hi);
			Mx1=SR0;
	
/****** Imaginary Portion *******/			
	i7=wavetable+64;
	MR=0,mx0=dm(i2,m1), my0=pm(i7,m6);		
			CNTR=N-1;
			do sine until CE;
	sine:	mr=mr+mx0*my0(ss),	mx0=dm(i2,m1), my0=pm(i7,m6);
		mr=mr+mx0*my0(ss);
	 		sr= lshift mr1 by -8(lo);
			sr= sr or ashift mr2 by -8(hi);
			
			
			mr=sr0*sr0(ss);
			mr=mr+mx1*mx1(ss);
			
		dm(i5,m4)=mr1;
		ay0=m6;
		ar=ay0 + 1;
DFT:	m6=ar;
	
		
		
	




	/*Check Loop for Synch */
check:
	ax0 = N;
	ay0 = dm(count);
	ar = ax0 - ay0;
	if NE jump check;
	jump main;

 
/*========================= INTERRUPT SERVICE ROUTINES ==================================*/

/********  receive interrupt used for loopback *********/

input_samples:
	ena sec_reg;			/* use shadow register bank */
		/* CODEC left channel Tx and Rx are NOT USED */

	/* Right input channel for mic and sig gen inputs */ 	
		
	mx0 = dm(rx_buf + 2);	/* get data from codec - Right Channel - load any dreg */
	dm(I4, M4) = mx0;
	si = dm(i6,m4);
	sr= ashift si by 4( hi);
	dm(tx_buf + 2) = sr1;	/* send data to codec - Right Channel - load from any dreg */
	
	ax0 = dm(count);
	ar = ax0 - 1;
	dm(count) = ar;
	
	if EQ jump countres;
		
	rti;

	
countres:
	mx0 = N;
	dm(count) = mx0;
	ax0 = I2;
	I2 = I4;
	I4 = ax0;

	ay1 = i5;
	i5=i6;
	i6=ay1;
	
	mx0 = 0x8000;
	dm(tx_buf + 2) = mx0;
	rti;
	
#include "tx_intrrp_2181_in_out_04.h"

start.end:		/* End of Code */

MasterSlowPoke fucked around with this message at 07:59 on Apr 15, 2008

TSDK
Nov 24, 2003

I got a wooden uploading this one

MasterSlowPoke posted:

the language is stackless python, definitions cut off for brevity
code:
/********* DO DFT *******/
Code for DFTs and suchlike almost always looks like that. It's the same with a lot of academic code too. Because the paper they're working from has got the formulae written out with single letter, subscripted variables then you often find just a straight transcript from paper to code.

It doesn't usually matter too much on self contained mathematical operations like that, because you can prove the correctness of the routine with relatively straightforward regression testing and then leave it alone for years.

The most important thing is: does it have the reference to the original paper in the comments?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
I think the wtf there is rolling a DFT in python when FFTW is free.

MasterSlowPoke
Oct 9, 2005

Our courage will pull us through

TSDK posted:

The most important thing is: does it have the reference to the original paper in the comments?

There are no comments. That c/p is from the source code for Eve Online, and over half of it is fully undocumented.

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!

MasterSlowPoke posted:

There are no comments. That c/p is from the source code for Eve Online, and over half of it is fully undocumented.

That usually happens when you DECOMPILE source. That's not stolen source. I wish people would stop saying this poo poo.


Edit: wait a second, that's not even python.

crazypenguin
Mar 9, 2005
nothing witty here, move along

deimos posted:

That usually happens when you DECOMPILE source. That's not stolen source. I wish people would stop saying this poo poo.

This statement would seem to contradict the half that IS documented, wouldn't it?

MasterSlowPoke
Oct 9, 2005

Our courage will pull us through

deimos posted:

That usually happens when you DECOMPILE source. That's not stolen source. I wish people would stop saying this poo poo.

There was a leak. If this were merely decompiled it'd be out there for a long time now.

deimos posted:

Edit: wait a second, that's not even python.

It's apparently "stackless python", a language pretty much exclusively used by CCP for Eve. I'm unsure how it differs from Python as I've never used it.

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!

MasterSlowPoke posted:

There was a leak. If this were merely decompiled it'd be out there for a long time now.


It's apparently "stackless python", a language pretty much exclusively used by CCP for Eve. I'm unsure how it differs from Python as I've never used it.

That's not stackless python or any kind of python. Stackless and CPython have pretty much the same syntax (but various different behaviours).

That looks like C or delphi.

crazypenguin posted:

This statement would seem to contradict the half that IS documented, wouldn't it?

not if they're docstrings

Allie
Jan 17, 2004

MasterSlowPoke posted:

It's apparently "stackless python", a language pretty much exclusively used by CCP for Eve. I'm unsure how it differs from Python as I've never used it.

Stackless Python has true coroutine support, and allows continuations to be pickled (so you can send them to another machine and resume them, for instance). It also has some other concurrency related features, and I believe it does away with the GIL. I personally haven't used it, but it seems interesting.

Also, whatever you pasted isn't Stackless Python, it looks like a custom language they made. Stackless isn't a different language, it's just a different interpreter.

trashmatic
Jan 27, 2006

MasterSlowPoke posted:

It's apparently "stackless python", a language pretty much exclusively used by CCP for Eve. I'm unsure how it differs from Python as I've never used it.
Nope. It looks like assembly language for some DSP chip or another - from the filename, possibly the ADSP2181?

From the comments, I'm guessing this is code out of a sound card driver or something.

MrMoo
Sep 14, 2000

trashmatic posted:

Nope. It looks like assembly language for some DSP chip

The language looks like the DSP filter assembly language discussed here:

http://www.analog.com/library/analogDialogue/archives/31-2/dsp.html

MrMoo
Sep 14, 2000

Someone just pointed out a great structure in my code:
code:
 for (guint i = 0; i < count; i++)
 {

 } while ( STATE(data_bytes_offset)  < STATE(apdu_length) );
It compiles with no warnings at all, how does it work, is it exactly the same as this?
code:
for (guint i = 0; i < count && STATE(data_bytes_offset) < STATE(apdu_length);
i++)
{
}

crazypenguin
Mar 9, 2005
nothing witty here, move along

MrMoo posted:

Someone just pointed out a great structure in my code:
code:
 for (guint i = 0; i < count; i++)
 {

 } while ( STATE(data_bytes_offset)  < STATE(apdu_length) );
It compiles with no warnings at all, how does it work,

Deceptively simple answer, really:

code:
for (guint i = 0; i < count; i++)
 { }

while ( STATE(data_bytes_offset)  < STATE(apdu_length) )
 { }

crazypenguin fucked around with this message at 03:00 on Apr 19, 2008

rotor
Jun 11, 2001

classic case of pineapple derangement syndrome
a for-while loop, neat. That and a do-switch and I'll be all set.

Zombywuf
Mar 29, 2008

I may have found my new favourite control flow structure, the fordowhile loop:
code:
for (i = 0, j = 0; i < 10; ++i, j = 0) do {
  printf("%i %i\n", i, j++);
} while (j < 10);
Now if I can just find a way to combine this with Duff's device...

standard
Jan 1, 2005
magic
I found this in one of our apps this week.
code:

for (int i = 0; i < collection.getDetails().size(); i++) { 
       SomeObject object = (SomeObject)collection.getDetails().elementAt(i);
       count++; 
} 

if (count < 1 || count> 10) { 
       isValid = false; 
} 
what the hell

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

standard posted:

I found this in one of our apps this week.
code:

for (int i = 0; i < collection.getDetails().size(); i++) { 
       SomeObject object = (SomeObject)collection.getDetails().elementAt(i);
       count++; 
} 

if (count < 1 || count> 10) { 
       isValid = false; 
} 
what the hell
Maybe they don't trust the collection.getDetails().size() method?

_aaron
Jul 24, 2007
The underscore is silent.

Jethro posted:

Maybe they don't trust the collection.getDetails().size() method?
That still doesn't explain why they get the element in each iteration of the loop. That same loop where they use collection.getDetails().size().
What the hell indeed...

Adbot
ADBOT LOVES YOU

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.
Seems to me like it used to test some property of the object and only include some of them in the count, and when they updated it to count all of them they just took the test out.

Or they planned to add a test and never got around to it.

Here's my latest: in the constructor of a QDialog. Note that the only point of giving a dialog a "parent" widget is that it'll be centered on the parent; if none is given it just opens in the center of the screen.

code:
SomeDialog::SomeDialog(QWidget *parent) :
  QDialog(parent)
{
  ...

  // put the dialog in a QScrollView
  sv = QScrollView(parent);
  sv->addChild(this);
  sv->setFocus();
  this->setFocus();
  ...
}
Ok, what's wrong with this:

1. That's a member variable called "sv", which is against the project's naming conventions of starting all member variables with "m" and globals with "g".
2. Why does it set focus to the scrollview and immediately back to the dialog?
3. This doesn't put the scrollview in the parent's layout or anything, so it would just show up in the top left of the parent window, at a default size, and get drawn overtop of other widgets. (And I don't even know what would happen if there was no parent.)
4. If you're trying to change the parent of a widget, addChild() is not the way to do it (and the docs even say so!) In Qt 3, addChild reset the parent of the dialog to sv, so it didn't crash or anything, but that was an undocumented implementation quirk. In Qt 4, this code fucks up event propagation and locks up the entire app.
5. Put the dialog in a scroll view? What the HELL?

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