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
Optimus Prime Ribs
Jul 25, 2007

hieronymus posted:

Another good example is the code for the std::vector class itself, which gets my vote for the most difficult to read widely-used class ever.

I find pretty much everything in the C++ STL to be hard as hell to read.

Adbot
ADBOT LOVES YOU

Amarkov
Jun 21, 2010

Golbez posted:

Can you elaborate on this please?

Yeah it's simple, his thing is named <span id='">



(I want a sparklee CSS attribute so bad)

Amarkov fucked around with this message at 15:17 on Sep 21, 2012

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Golbez posted:

Can you elaborate on this please?
Our web UI that used to just do stuff like
JavaScript code:
someElement.innerHTML = this.name
//or even 
var elementhtml = '<span title="' + this.name + '">whatever</span>';
element.innerHTML = elementhtml;
where this.name is that string in my previous message. That would break the HTML in the page and so the UI.

Now, that name has been in our development DB for a while. We just updated our data fetching to using JSON and the guy who wrote the server component probably just hand-rolled his JSON encoder, because the quotation marks in the name are not escaped, so the json fragment looks like
JavaScript code:
{
	"name": "'"><span style="font-size:x-large; color:red;">BROKEN</span>"
}
when it should look like this:
code:
{
    "name": "'\"><span style=\"font-size:x-large; color:red;\">BROKEN</span>"
}

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Amarkov posted:

It's just a standard injection vulnerability check? If you do not sanitize inputs, your webpage is




(I want a sparklee CSS attribute so bad)

CSS code:
.injected {
	background:lime;
	color:magenta;
	text-decoration:blink;
	font-size:100pt;
	-ms-transform:rotate(-17deg);
	-moz-transform:rotate(-17deg);
	-webkit-transform:rotate(-17deg);
	-o-transform:rotate(-17deg);
	transform:rotate(-17deg);
	position:fixed;
	top:25%;
	left:25%;
	content:"owned owned owned owned owned";
}
Close enough

Plorkyeran
Mar 22, 2007

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

Optimus Prime Ribs posted:

I find pretty much everything in the C++ STL to be hard as hell to read.
It doesn't help that dinkumware's implementation (used by visual c++) is written in a really weird style that I've never seen anywhere else.

Optimus Prime Ribs
Jul 25, 2007

Plorkyeran posted:

It doesn't help that dinkumware's implementation (used by visual c++) is written in a really weird style that I've never seen anywhere else.

Yeah I don't really get it:

C++ code:
template<class _Iter>
		void _Insert(const_iterator _Where,
			_Iter _First, _Iter _Last,
			forward_iterator_tag)
		{	// insert [_First, _Last) at _Where, forward iterators

 #if _HAS_ITERATOR_DEBUGGING
		_DEBUG_RANGE(_First, _Last);
 #endif /* _HAS_ITERATOR_DEBUGGING */

		size_type _Count = 0;
		_Distance(_First, _Last, _Count);

		size_type _Off = _Insert_x(_Where, _Count);
		std::copy(_First, _Last, begin() + _Off);
		}
Who indents code that way?

Toady
Jan 12, 2009

It looks like some Whitesmiths variant.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





plashy posted:

long post

Is this an Asian-based company with offices in the Bay Area? (That may be all of them though)

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Strong Sauce posted:

Is this an Asian-based company with offices in the Bay Area? (That may be all of them though)
I'd assume it's in South Korea, since he's living there.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

plashy posted:

I was taking an interview for a potential new company, mobile games stuff, nothing too complicated. I've been a lead/senior engineer on games for some time now and already have a year of experience at a company in S. Korea where I'm living.

If you didn't realize already, they probably stole your code and are using it in their next mobile game.

The whole point of the point deduction thing was to turn you off of the company, so you wouldn't try to press more for a job if you needed one badly.

plashy
Apr 13, 2012

Thern posted:

This is the part where I would have walked out. If they can't respect you before they hire you, you can bet they won't respect you while working there.

Being a white guy I don't have much to get upset about culturally, I decided to give them something trickier after that though, the position did require a decent amount of authority.

Suspicious Dish posted:

If you didn't realize already, they probably stole your code and are using it in their next mobile game.

The whole point of the point deduction thing was to turn you off of the company, so you wouldn't try to press more for a job if you needed one badly.

I'll go with Hanlon's razor on this one I think.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

plashy posted:

I'll go with Hanlon's razor on this one I think.

I usually would too, but why else would they ask him to code an entire minesweeper game for a work sample? That raises a red flag. Minesweeper is a simple game to code, but not as simple as of tic tac toe or pong.

The issue about berating him specifically for bad code rather than just ignoring someone not worth your time also is a red flag.

That Turkey Story
Mar 30, 2003

Suspicious Dish posted:

I usually would too, but why else would they ask him to code an entire minesweeper game for a work sample? That raises a red flag. Minesweeper is a simple game to code, but not as simple as of tic tac toe or pong.

The issue about berating him specifically for bad code rather than just ignoring someone not worth your time also is a red flag.

If that's true, he could always keep watch on the company and see if they release some kind of minesweeper-like game and then take some kind of legal action.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





That Turkey Story posted:

If that's true, he could always keep watch on the company and see if they release some kind of minesweeper-like game and then take some kind of legal action.
Seems exactly like the kind of case that would waste his time and resources. I mean if you can somehow get millions then I guess it would be worth it...

plashy
Apr 13, 2012

Suspicious Dish posted:

I usually would too, but why else would they ask him to code an entire minesweeper game for a work sample? That raises a red flag. Minesweeper is a simple game to code, but not as simple as of tic tac toe or pong.

The issue about berating him specifically for bad code rather than just ignoring someone not worth your time also is a red flag.

While it would be trivial to make it complete, it's not much to look at honestly, there's no effort made to alert you if you won for example. Also I didn't make graphics for numbers greater than four but they didn't notice that.

Could brush it up and dump it on the app-store myself I guess.

http://goo.gl/0FWZq

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.

Plorkyeran posted:

It doesn't help that dinkumware's implementation (used by visual c++) is written in a really weird style that I've never seen anywhere else.
This, plus "we have to avoid user-defined macros breaking the code so let's try to take advantage of the implementation-reserved 'namespace' of underscore-prefixed identifiers and put underscores everywhere," makes anybody's (even the nicest, libc++) a pain to read.

FamDav
Mar 29, 2008
This guy is just all kinds of craziness. He implements a customized version of LISP that, upon his departure from Naughty Dog, is essentially unmaintainable.

FamDav fucked around with this message at 08:18 on Sep 24, 2012

Progressive JPEG
Feb 19, 2003

FamDav posted:

guy is just all kinds of craziness. He implements a customized version of LISP that, upon his departure from Naughty Dog, is essentially unmaintainable.

While it's interesting from an outsider's perspective, his pattern of doing everything from scratch -- particularly to the point of writing a custom language for things that one wouldn't expect it to be necessary -- strikes me as "I'm difficult to work with and can't reasonably function in a team environment".

In my limited experience, I've found that to be a fairly common issue among sperglords.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
The people that founded Naughty Dog were very big into LISP (they came from the MIT labs). The issue was that current LISP implementations at the time didn't meet their requirements, the biggest one was performance on a specialized embedded system.

Even EA wrote their own STL replacements because the ones included were causing real performance issues on the hardware they were supposed to run on.

Designing a new LISP implementation that fit the very specific requirements in a time when there weren't a lot around doesn't seem like that much of a horror.

Suspicious Dish fucked around with this message at 08:38 on Sep 24, 2012

Progressive JPEG
Feb 19, 2003

Yeah I suppose it depends on the context. I myself once hit an issue with the fstream implementation in libstdc++ where it decided to completely ignore any buffering that one had set whenever it received a write >= 1024 bytes. Ended up sidestepping the issue by just using the somewhat lower-level fopen/setvbuf instead, which worked as intended.

This wasn't even trying to get things to work on a system with restrictive hardware like what a console game company would've had to deal with -- the production hardware was quite fancy, but it regardless choked on the dozens of inefficient small writes it was being handed as a result of the following "optimization" from xsputn() in fstream.tcc:

libstdc++ : fstream.tcc posted:

// Optimization in the always_noconv() case, to be generalized in the
// future: when __n is sufficiently large we write directly instead of
// using the buffer.

("sufficiently large", as defined by __chunk a few lines down, is 1024B)

After experiencing that particular little gem and others like it, I'm definitely no longer of the opinion that general libraries are necessarily the best solution to specialized problems. Sometimes they really are just doing things inefficiently to support auxiliary functionality that you don't want or need. But that said, I think it's still best to go with them by default until they're actually causing noticeable problems.

But if LISP was too slow, perhaps they should've considered other languages? Smells of eg Facebook deciding to solve their PHP scalability problems by writing a new PHP interpreter from scratch rather than by just switching to a more suitable language.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
With game dev, rapid iteration is important. So switching to a "fast" language with slow turnaround isn't necessarily a win.

You don't really need "fast" for coding game logic, all you need is "fast enough".

tef
May 30, 2004

-> some l-system crap ->

FamDav posted:

This guy is just all kinds of craziness. He implements a customized version of LISP that, upon his departure from Naughty Dog, is essentially unmaintainable.

This is what happened to yahoo! stores, they replaced paul graham's unmaintainable lisp for perl.

Zombywuf
Mar 29, 2008

Ah HFTs: http://www.economicpopulist.org/content/chicago-fed-study-blasts-lid-high-frequency-trading

o.m. 94
Nov 23, 2009

Don't know C++, but I hope to god this isn't an idiom (from the Dungeon Crawl source).

code:
string bookname = (prayertype == RECITE_CHAOTIC)  ?  "Abominations"  :	
                  (prayertype == RECITE_IMPURE)   ?  "Ablutions"     :	
                  (prayertype == RECITE_HERETIC)  ?  "Apostates"     :	
                  (prayertype == RECITE_UNHOLY)   ?  "Anathema"      :	
                  (prayertype == RECITE_ALLY)     ?  "Alliances"     :	
                                                     "Bugginess";

MarsMattel
May 25, 2001

God, I've heard about those cults Ted. People dressing up in black and saying Our Lord's going to come back and save us all.
That's a pretty standard way of doing an if else-if chain, though perhaps a lookup table would be a neater solution there.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
That code is perfectly readable, and a lookup table wouldn't be any simpler or meaningfully faster unless the table could easily be cached.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

oiseaux morts 1994 posted:

Don't know C++, but I hope to god this isn't an idiom (from the Dungeon Crawl source).

code:
string bookname = (prayertype == RECITE_CHAOTIC)  ?  "Abominations"  :	
                  (prayertype == RECITE_IMPURE)   ?  "Ablutions"     :	
                  (prayertype == RECITE_HERETIC)  ?  "Apostates"     :	
                  (prayertype == RECITE_UNHOLY)   ?  "Anathema"      :	
                  (prayertype == RECITE_ALLY)     ?  "Alliances"     :	
                                                     "Bugginess";

I think code written like that is far less readable and would much rather expand it to a switch. But some people love conditional operators. I've become okay with it in simple scenarios, like var result = a > b ? x : y;, but anything more complex than that and it drives me batty.

MarsMattel
May 25, 2001

God, I've heard about those cults Ted. People dressing up in black and saying Our Lord's going to come back and save us all.
Yeah, its a style thing. An advantage that version (or the bookname = table[prayertype] version) has is that you can declare bookname as const.

Scaevolus
Apr 16, 2007

Ithaqua posted:

I think code written like that is far less readable and would much rather expand it to a switch. But some people love conditional operators. I've become okay with it in simple scenarios, like var result = a > b ? x : y;, but anything more complex than that and it drives me batty.
It's an idiom that takes a bit of getting used to, but it's very concise, which is useful for this sort of work. Look at the linked code -- if they used a switch/if-else instead of ternary statements, that long file would be even longer.

That Turkey Story
Mar 30, 2003

MarsMattel posted:

Yeah, its a style thing. An advantage that version (or the bookname = table[prayertype] version) has is that you can declare bookname as const.

This. You usually use the ternary operator like that when you need to get the result in a single expression, such as for initialization of a const object. An alternative is to put the logic into a separate function that returns the result, and then call that function, but that implies... creating another function. You could use lambdas for that now to get it all in one place, but using the ternary operator works fine too.

E: I did this once on a project and was asked why I did it and after explaining it, I was told to never do it again and just don't use const in those situations. I can't say I agree with that at all, but it happens! It seems as though only half the team wrote const-correct code anyway, so working with const objects tended to have you run into compilation issues because people didn't label member function as const.

That Turkey Story fucked around with this message at 18:00 on Sep 24, 2012

UraniumAnchor
May 21, 2006

Not a walrus.

As interesting as this article is, why does he keep spouting AMERICA? :patriot: Being from the US doesn't somehow make you immune to being a terrible programmer. Or an idiot. Or an idiot terrible programmer.

Zombywuf
Mar 29, 2008

UraniumAnchor posted:

As interesting as this article is, why does he keep spouting AMERICA? :patriot: Being from the US doesn't somehow make you immune to being a terrible programmer. Or an idiot. Or an idiot terrible programmer.

I dunno, force of habit? They're like that over there.

Munkeymon
Aug 14, 2003

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



UraniumAnchor posted:

As interesting as this article is, why does he keep spouting AMERICA? :patriot: Being from the US doesn't somehow make you immune to being a terrible programmer. Or an idiot. Or an idiot terrible programmer.

'populist' is right there in the site name but it's still really silly and off-putting, even to an American. how-to-undermine-an-article.txt

raminasi
Jan 25, 2005

a last drink with no ice

Ithaqua posted:

I think code written like that is far less readable and would much rather expand it to a switch. But some people love conditional operators. I've become okay with it in simple scenarios, like var result = a > b ? x : y;, but anything more complex than that and it drives me batty.

I'm always baffled when people claim that idiom is anything less than perfectly readable. What's confusing about it?

qntm
Jun 17, 2009

oiseaux morts 1994 posted:

Don't know C++, but I hope to god this isn't an idiom (from the Dungeon Crawl source).

code:
string bookname = (prayertype == RECITE_CHAOTIC)  ?  "Abominations"  :	
                  (prayertype == RECITE_IMPURE)   ?  "Ablutions"     :	
                  (prayertype == RECITE_HERETIC)  ?  "Apostates"     :	
                  (prayertype == RECITE_UNHOLY)   ?  "Anathema"      :	
                  (prayertype == RECITE_ALLY)     ?  "Alliances"     :	
                                                     "Bugginess";

This is only a horror if you try it in PHP.

That Turkey Story
Mar 30, 2003

GrumpyDoctor posted:

I'm always baffled when people claim that idiom is anything less than perfectly readable. What's confusing about it?

Same. It's pretty much immediately clear what's going on. I think the problem is probably just that a lot of people don't use ?: so it is therefore intrinsically weird to them.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

GrumpyDoctor posted:

I'm always baffled when people claim that idiom is anything less than perfectly readable. What's confusing about it?

There's nothing confusing about it, it's just less readable, and the second you start stacking them it turns into a mess. I submit for your consideration: http://stackoverflow.com/questions/9101719/im-looking-for-a-free-tool-stand-alone-or-add-in-that-can-decompose-ternary-ex/

That Turkey Story
Mar 30, 2003

Ithaqua posted:

There's nothing confusing about it, it's just less readable, and the second you start stacking them it turns into a mess. I submit for your consideration: http://stackoverflow.com/questions/9101719/im-looking-for-a-free-tool-stand-alone-or-add-in-that-can-decompose-ternary-ex/

That is a very different usage than what we are talking about.

shrughes
Oct 11, 2008

(call/cc call/cc)
It's because some people are afraid of functional programming.

Adbot
ADBOT LOVES YOU

Zamujasa
Oct 27, 2010



Bread Liar

qntm posted:

This is only a horror if you try it in PHP.

That was my first thought. :ohdear: I've gotten used to just wrapping all of those expressions in their own set of parenthesis just to make sure the chances of something unintended cropping up is minimized, e.g. $xxx = ($yyy == true ? "yep" : "nope") .", php.";

It's really not a bad operator as long as you keep it simple. When doing really long, complex poo poo, that's the job of a real if/then or switch.

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