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
Zamujasa
Oct 27, 2010



Bread Liar
This was for a "pre-exam" or whatever they wanted to call it, but it had multiple choice, the answer for one of them was this:

code:
foreach ($arr as ?????????????????) {
  print "<font color=$val>$key</font>";
}
Had they used any other variable names this would have not been a problem, but having to answer "$val => $key" made my stomach turn. Most of the examples were like this, actually; code that was completely flawed in some way but had a very specific issue that was also wrong and being asked about.

quote:

There is trailing whitespace after one of the }s.
I would've just guessed it was something like what Firefox does whenever I copy-paste something. If it just happens to be at the end of a line, it adds an ever-so-useful trailing space for no apparent reason.

This is really fun when I need to copy-paste something like a password and the extra space fucks everything up.

Adbot
ADBOT LOVES YOU

Innocent Bystander
May 8, 2007
Born in the LOLbarn.

Zamujasa posted:

This was for a "pre-exam" or whatever they wanted to call it, but it had multiple choice, the answer for one of them was this:

code:
foreach ($arr as ?????????????????) {
  print "<font color=$val>$key</font>";
}
Had they used any other variable names this would have not been a problem, but having to answer "$val => $key" made my stomach turn.

I guess I don't mind key,val especially in a one line foreach statement when you can see the declaration immediately above you. Its kind of close to the pseudo you might right down.

This isn't exactly a horror, but its from some code I wrote a while back. Who cares about what exception happened? I DON'T!

code:
def establish_thresholds( threshString ):
	try:
		at 		= False
		container = ( '' , '' )
		if not threshString:
			return container
		elif ':' in threshString:
			if '@' in threshString:
				threshString = threshString[1:]
				at = True
			newStr = threshString.split(':')
			if '~' in newStr[0]:
				container = ( '' , int(newStr[1]) )
			elif not newStr[1]:
				container = ( float(newStr[0]) , '' )
			else:
				container = ( float(newStr[0]) , float(newStr[1]) )
				if at:
					container = ( container[1] - .01 , container[0] + .01 )
		else:
			container = ( 0 , int(threshString) )
		return container
	except:
		return 1

NotShadowStar
Sep 20, 2000

Innocent Bystander posted:

I guess I don't mind key,val especially in a one line foreach statement when you can see the declaration immediately above you. Its kind of close to the pseudo you might right down.

The horror is that $val => $key is backwards

posting smiling
Jun 22, 2008

NotShadowStar posted:

The horror is that $val => $key is backwards

As far as I can tell it's mapping a color's name to its hex code. The names appear in reverse order in the code, but logically it's perfectly consistent.

Opinion Haver
Apr 9, 2007

Nobody's pointed out the real horror of using <font> tags?

Innocent Bystander
May 8, 2007
Born in the LOLbarn.

yaoi prophet posted:

Nobody's pointed out the real horror of using <font> tags?

Heh, PHP is a magnet for horrors so I just assumed it was in the PHP code, but you're absolutely right xD

Plorkyeran
Mar 22, 2007

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

yaoi prophet posted:

Nobody's pointed out the real horror of using <font> tags?
<span style="..."> is no better than a font tag and the given code does not imply any sensible semantic class names

NotShadowStar
Sep 20, 2000

Classicist posted:

As far as I can tell it's mapping a color's name to its hex code. The names appear in reverse order in the code, but logically it's perfectly consistent.

He said this was for a multiple choice exam and the only answer that made sense was foreach($arr as $val => $key) which is completely backwards.

Innocent Bystander
May 8, 2007
Born in the LOLbarn.

NotShadowStar posted:

He said this was for a multiple choice exam and the only answer that made sense was foreach($arr as $val => $key) which is completely backwards.

Hmm, he was taking a multiple choice test on programming. Perhaps the test authors were trying to make an obscenely saracastic self-commentary?

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Fren posted:

"No subclassing in Javascript? Oh well :("

The worst thing to happen to JavaScript was being born with a C-family syntax.

Opinion Haver
Apr 9, 2007

Coffeescript!


vvv so do I, it's an unironic recommendation :shobon:

Opinion Haver fucked around with this message at 07:38 on Sep 14, 2011

kalleth
Jan 28, 2006

C'mon, just give it a shot
Fun Shoe

yaoi prophet posted:

Coffeescript!

I like CS :(

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Monkeyseesaw posted:

The worst thing to happen to JavaScript was being born with a C-family syntax.

I've seen it argued that its C-like syntax helped it (or was necessary, even, to) get adopted everywhere, and it turns out it's not at all a bad language. I would've said the same thing as you a year ago, but I've changed my mind.

Zamujasa
Oct 27, 2010



Bread Liar

Innocent Bystander posted:

Heh, PHP is a magnet for horrors so I just assumed it was in the PHP code, but you're absolutely right xD

It was, because the foreach thing was meant to be the focus; the font tag was used for simplicity (I didn't feel like writing out a span or the original's <option>s)


quote:

quote:

The horror is that $val => $key is backwards
As far as I can tell it's mapping a color's name to its hex code. The names appear in reverse order in the code, but logically it's perfectly consistent.
The original array was this, more or less:

code:
$arr = array( 'orange' => 'The Color Orange', 'red' => 'Red Colored' );
The big issue is the completely misnamed variables; $val => $key is totally backwards and, while the example was only three lines inside of the foreach, any larger than that and you'd have a good cause to rewrite the function to fix it. (Personally I would use something like $colorCode and $colorName, but...)

To put it another way, $key=>$val is a lot like calling a deadbolt a key and calling a key a deadbolt. It's completely backwards for no real reason other than to try to trick people who are taking the exam; while I give them some points for being creative, using an answer that is so obviously backwards really isn't helping.

blorpy
Jan 5, 2005

pokeyman posted:

I've seen it argued that its C-like syntax helped it (or was necessary, even, to) get adopted everywhere, and it turns out it's not at all a bad language. I would've said the same thing as you a year ago, but I've changed my mind.

javascript is a terrible language and youre only giving it the benfit of a doubt because it becomes ok once you bolt 3 frameworks on top of it

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Markov Chain Chomp posted:

javascript is a terrible language and youre only giving it the benfit of a doubt because it becomes ok once you bolt 3 frameworks on top of it

Which three frameworks did you have in mind?

It's a decent language if you change the syntax a bit. I'll happily concede that it's too easy to do stupid things in straight JavaScript.

Apok
Jul 22, 2005
I have a title now!
My cousin owns a small business consulting company. I came to work for him as the IT/tech guy who does all of the tech work, graphics design, video editing, and website making.

The websites they had I would link would provide a good laugh to CoC but that would be unprofessional. Sorry. Anyways, the guy who made them still works here and is currently throwing a fit that 1: he isn't responsible for all of this anymore, and 2: I'm changing up his "masterpieces".

-The websites were made in Microsoft Word. He added a banner and some links and put it in tables.
-The homepage to each of the websites that I now control is around 17 printed pages long.
-Autostarting videos "PODs" on nearly every page. I get annoyed and close them. I'd hate to think we're losing customers who also get annoyed and close them.
-Images are all resized and with borders made in Word. Yes, it is a lo-res image with a pink highlight border around it. My eyes are not deceiving me.
-Testimonial pages with nearly 50 YouTube iframe embeds per page. Some of them are Flash-based as well so they don't load on iOS devices.
-Pages are not concise, there are spelling errors, and its written like a speech. 17 pages of stream-of-conscious first person narrative voice inviting you to the latest conference.
-FTP sites are messy with all of the old pages from 2-8 years ago which were never cataloged.

I come in and redesign the pages using proper coding (basic compared to a lot of stuff you all do, I know) and constantly get bitched at because "tables are easier and quicker to edit than CSS" although the real reason is "I made this why are you changing it". The most recent rant I have received is "what you're doing is taking too long, just paste the Word document straight into Dreamweaver with the markup".

In short, it annoys me and forces me to keep my mouth shut since the job is quite nice otherwise.

I have to start working for the day though. While updating the horrendous webpages I accidentally messed up a JavaScript form which just so happens to be the end of the world to some people. Must fix.

Apok fucked around with this message at 14:09 on Sep 14, 2011

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.
We got some new equipment in at work that you communicate with by sending/receiving strings over RS-232. After having some trouble getting the thing to function consistently I called the manufacturer and an engineer explained how their 'send a string response' system works:

The device's firmware creates a set of char arrays for each possible string response, plus a set of pointers to those arrays. When it's time to send a string the code grabs the appropriate pointer, puts the value at the memory location being pointed to into the RS-232 buffer, and then increments the pointer itself (not pointer + an offset value) and returns the next character until a termination character is reached (which is 0x0D, or carriage return, because hey why not). This means that by the end of a string read the pointer is aimed at the termination character, not at the base of the char array.

So, if you read a value you'll get the correct response once but then subsequent reads just return the termination character because the pointer is in the wrong place. How do you reset the pointer to the beginning of the array? You don't. Instead, a hardware timer on the microcontroller goes off every 500 ms and triggers some code that resets all the char array pointers to their default positions. As long as you only read any particular string less often than once per 500 ms you are reasonably safe, unless of course the pointer happens to get reset midway through a read in which case you could get a partial duplicate string like 12312345 instead of 12345.

Part of me wants to believe that I just didn't understand the engineer's explanation properly and that things really don't work that way, but the model he described matches up pretty well with how the system behaves in the lab.

Zombywuf
Mar 29, 2008

Hardware is the worst.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

PDP-1 posted:

We got some new equipment in at work that you communicate with by sending/receiving strings over RS-232. After having some trouble getting the thing to function consistently I called the manufacturer and an engineer explained how their 'send a string response' system works:

The device's firmware creates a set of char arrays for each possible string response, plus a set of pointers to those arrays. When it's time to send a string the code grabs the appropriate pointer, puts the value at the memory location being pointed to into the RS-232 buffer, and then increments the pointer itself (not pointer + an offset value) and returns the next character until a termination character is reached (which is 0x0D, or carriage return, because hey why not). This means that by the end of a string read the pointer is aimed at the termination character, not at the base of the char array.

So, if you read a value you'll get the correct response once but then subsequent reads just return the termination character because the pointer is in the wrong place. How do you reset the pointer to the beginning of the array? You don't. Instead, a hardware timer on the microcontroller goes off every 500 ms and triggers some code that resets all the char array pointers to their default positions. As long as you only read any particular string less often than once per 500 ms you are reasonably safe, unless of course the pointer happens to get reset midway through a read in which case you could get a partial duplicate string like 12312345 instead of 12345.

Part of me wants to believe that I just didn't understand the engineer's explanation properly and that things really don't work that way, but the model he described matches up pretty well with how the system behaves in the lab.

This seems more like an elaborate troll than the actions of a legitimate hardware firm

TasteMyHouse
Dec 21, 2006
that does not at all fall outside of my expectations for "EE code".

ReelBigLizard
Feb 27, 2003

Fallen Rib
Shocking tales of Redundancy:
code:
#############################
#                           #
#    PAGE FOOTER FUNCTION   #
#                           #
#############################

pageFooter();
WHAT IS THE IMPLODE FUNCTION? I'M NOT GOOD WITH ARRAYS
code:
$sql = 'SELECT blah FROM wibble WHERE ';

foreach($whereClauses as $clause)
{
	$sql .= $clause . " AND";
}

$sql .= "1=1";

Plorkyeran
Mar 22, 2007

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

Otto Skorzeny posted:

This seems more like an elaborate troll than the actions of a legitimate hardware firm
I'm not convinced there's a difference.

Munkeymon
Aug 14, 2003

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



PDP-1 posted:

We got some new equipment in at work that you communicate with by sending/receiving strings over RS-232. After having some trouble getting the thing to function consistently I called the manufacturer and an engineer explained how their 'send a string response' system works:

:stare:

blorpy
Jan 5, 2005

pokeyman posted:

Which three frameworks did you have in mind?

It's a decent language if you change the syntax a bit. I'll happily concede that it's too easy to do stupid things in straight JavaScript.

Sorry, I was just using a bit of hyperbole, there's no specific 3. But, IMO, JS ranks up there with PHP in terms of "lets you do stupid things".

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.

Otto Skorzeny posted:

This seems more like an elaborate troll than the actions of a legitimate hardware firm

Agilent and Keithley seem to be the only measurement hardware companies in existence who can produce an I/O spec that doesn't feel like an elaborate troll. Once you get down into the second and third tier of equipment vendors you'll always be interfacing with a coding horror of some type. The only reason this one stood out was that the support engineer flat out admitted that they were using hardware timers to reset variables and you usually don't get that kind of detailed description - you typically just have to guess at what is going on then write an interface object to hide the WTF from the rest of your program.

TasteMyHouse posted:

that does not at all fall outside of my expectations for "EE code".

I'm an EE myself and can attest that as a group we are extremely poo poo coders, but we aren't the absolute worst. The true Vogon Poets of the coding universe are PhD physicists who decide that since they are very smart and Boolean logic is very simple they should be able to figure out how to program a control system on their own within a day or two. They grab a copy of LabVIEW and a fistful of GPIB cables and go create something with lots of motors, lasers, and power high-voltage supplies that doesn't work, damages the equipment, or poses a severe danger to themselves and other members of the lab staff. Possibly all three things at once.

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

Markov Chain Chomp posted:

Sorry, I was just using a bit of hyperbole, there's no specific 3. But, IMO, JS ranks up there with PHP in terms of "lets you do stupid things".

I like JS, but I'm of the opinion that if you can't use coffescript at least use underscore.js http://documentcloud.github.com/underscore/

It makes dealing with the weakass collections in JS way better.

TasteMyHouse
Dec 21, 2006

PDP-1 posted:

I'm an EE myself
*dap* I'm an E(C)E (student), I'm raggin' on my own kind :)

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal

PDP-1 posted:

I'm an EE myself and can attest that as a group we are extremely poo poo coders, but we aren't the absolute worst. The true Vogon Poets of the coding universe are PhD physicists who decide that since they are very smart and Boolean logic is very simple they should be able to figure out how to program a control system on their own within a day or two. They grab a copy of LabVIEW and a fistful of GPIB cables and go create something with lots of motors, lasers, and power high-voltage supplies that doesn't work, damages the equipment, or poses a severe danger to themselves and other members of the lab staff. Possibly all three things at once.

It never actually occurred to me that the sort of skills required to make the insane simulations written in FORTRAN77 I've seen coming from physicists might also be applied to control systems. Chilling.

Though to be fair, physicists are dangerous to everyone in their lab even when they're not using computers. The school I went to kept radiation sources on a table under a big pile of lead blocks. Like, a big pile of bricks made out of lead. There was a hole on one side in order to have a beam for exposing samples, and a sign on the table telling you about said beam and suggesting that you might want to go around the other way. The other end of the beam was the concrete wall a couple of meters from the table.

Zamujasa
Oct 27, 2010



Bread Liar

Apok posted:

My cousin owns a small business consulting company. I came to work for him as the IT/tech guy who does all of the tech work, graphics design, video editing, and website making.

The websites they had I would link would provide a good laugh to CoC but that would be unprofessional. Sorry. Anyways, the guy who made them still works here and is currently throwing a fit that 1: he isn't responsible for all of this anymore, and 2: I'm changing up his "masterpieces".

Do the websites have any sort of analytics on them? Especially if the place is your cousin, if you can provide some evidence that your redesigned sites are much more effective then it should be trivial to make the guy shut up -- especially if his works of art are actually driving away customers.

NotShadowStar
Sep 20, 2000

Markov Chain Chomp posted:

Sorry, I was just using a bit of hyperbole, there's no specific 3. But, IMO, JS ranks up there with PHP in terms of "lets you do stupid things".

JS went from conception to implementation to production in a manner of eight days (4realz), but it's clever enough that you have more than enough tools to get over the deficiencies of the language. PHP, as of 5.3, is only now starting to give you enough tools to get over the totally poo poo aspects of the language, and even then good luck requiring 5.3 for your project and have it be generally released as lots of lovely $5 web hosts still run PHP 4.2

People have been mad as hell that Wordpress 3.2 requires PHP >5.2 because they can't upgrade. This is the state of PHP, damned if you do damned if you don't.

NotShadowStar fucked around with this message at 02:47 on Sep 15, 2011

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
URL a = new URL("http://stackoverflow.com");
URL b = new URL("http://stackexchange.com");
System.out.println(a.equals(b));
true


whose brilliant idea was this

Opinion Haver
Apr 9, 2007

Aleksei Vasiliev posted:

URL a = new URL("http://stackoverflow.com");
URL b = new URL("http://stackexchange.com");
System.out.println(a.equals(b));
true


whose brilliant idea was this

Oh my god that's fantastic.

quote:

Note: The defined behavior for equals is known to be inconsistent with virtual hosting in HTTP.
You don't say.

beuges
Jul 4, 2005
fluffy bunny butterfly broomstick

PDP-1 posted:

The true Vogon Poets of the coding universe are PhD physicists who decide that since they are very smart and Boolean logic is very simple they should be able to figure out how to program a control system on their own within a day or two.

I had a physics PhD join my team about 6 years ago. The company standard was still VC6, but he insisted that he was going to use VS2005 (which had only been out for a few months). I told him he could dev in notepad if he wanted, but all the builds were still going to be done on VC6 so his stuff better still work there.
Since the VS2005 C++ compiler was a bit stricter than the VC6 one, he ended up with a whole bunch of warnings. So he "fixed" the code to make the warnings go away. One that I recall was something like
code:
str += '0' + intval;
clearly meant to give a printable representation of a number, which was giving some sort of warning.
I got a random report from the tester that there was rubbish data coming thru to the DB. After a bunch of investigation, it turned out that this PhD dude had "fixed" his warnings by changing the code to
code:
str += '0';
str += intval;
Never tested cos it would be immediately obvious that it wasn't working. Checked into source control, so it went into the next build. And all this while I was trying to fix the last bug that was holding back a signoff from testing.

Luckily he was on a contract rather than permanent, so we didn't renew his contract.

In his interview he also rated himself a 10/10 as a C++ programmer (which to me means you should be working for EDG or sitting on the C++0x committee), but couldn't answer straightforward questions about stack unwinding etc.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Aleksei Vasiliev posted:

URL a = new URL("http://stackoverflow.com");
URL b = new URL("http://stackexchange.com");
System.out.println(a.equals(b));
true


whose brilliant idea was this

You know what's awesome about this?

If the machine you're running on has no DNS, your calls to equals will hang the thread for a second or two while the name lookups time out.

Clavius
Oct 21, 2007

Howdy!
code:
        </td>
    </tr>
</table>
Hey friend who is still living in 2002 web design land, you should consider a few more modern techniques. *Many links and hours of advice*

code:
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
:stare:

gold brick
Jun 19, 2001

no he isn't

Clavius posted:

Hey friend who is still living in 2002 web design land, you should consider a few more modern techniques. *Many links and hours of advice*
That reminds me of a coworker I used to have. He (still) prefers table layouts, but asked me once how I would lay out a simple form using divs, etc. I looked it over without saying anything for about 5-6 seconds before he said "Well, if we were doing tables, I know I wouldn't have to think this hard".

TOO MUCH THINKING

Clavius
Oct 21, 2007

Howdy!

gold brick posted:

That reminds me of a coworker I used to have. He (still) prefers table layouts, but asked me once how I would lay out a simple form using divs, etc. I looked it over without saying anything for about 5-6 seconds before he said "Well, if we were doing tables, I know I wouldn't have to think this hard".

TOO MUCH THINKING

It could be worse, he could get on board and move onto the next phase: Replacing table tr and td tags with div tags and floating goddamn everything instead of actually learning how to separate layout and content properly. That poo poo is impossible to fix. I can at least see what the incompetent gently caress has broken in a table layout.

Fubear
Jan 2, 2005
Smarter Than The Average Bear
We just found this beauty in the administration area of one of our websites:

code:
/csv_download.php?query=SELECT%20*%20FROM%20m_users%20ORDER%20BY%20u_id%20ASC
Further investigation of the source reveals:

code:
$query = addslashes($_GET['query']);
$result = mysql_query($query);
The addslashes is a nice touch, it's like he knew he ought to be doing something with the input but doesn't quite understand why.

If the guy still worked here, I would be kicking his rear end so hard right now.

Adbot
ADBOT LOVES YOU

Zhentar
Sep 28, 2003

Brilliant Master Genius
I just realized that in MUMPS, since '+' and '-' are also unary operators, this is legal syntax.

code:
>write 2++++++++++++++++2
4

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