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
QuarkJets
Sep 8, 2008

M31 posted:

It's seems like a good fit, but in the real world it doesn't work. You can make an Orc class, but then you get an PlayableOrc and a NonPlayableOrc, and the NonPlayableOrc has a friendly version and a non friendly version, etc.. And C# does not have multiple inheritance.

Composition is much more maintainable and having a standard class with all character attributes seems pretty logical to me in that context, even if you have a gazillion attributes.

Wouldn't you want to use some combination? An Orc Wizard doesn't need to be split up into Playable and Nonplayable, it'd just have a flag for friendly vs hostile, and it could have a Background object for individual named Orcs with backstories. Ignoring that C# does not have multiple inheritance for a moment

And this example doesn't even appear to be using Composition. There aren't hardly any objects inside of this class, it's just a bunch of attributes, methods, and enums

QuarkJets fucked around with this message at 10:54 on Sep 22, 2014

Adbot
ADBOT LOVES YOU

M31
Jun 12, 2012
Whoops, I meant component based instead of composition.

hobbesmaster
Jan 28, 2008

QuarkJets posted:

Ignoring that C# does not have multiple inheritance for a moment

This is why you would say fuckit and put all the attributes in one class.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
Tough times on the road to Starcraft is a great read, and the "game engine architecture" section is relevant to this discussion.

Workaday Wizard
Oct 23, 2009

by Pragmatica
Required reading for all game engine programmers:
http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/

It's by one of the people working on the Tony Hawk games. It describes the challenges they faced with big blob objects and how their stuff into components ease the pain.

NickPlowswell
Sep 14, 2014

The exoplanet has failed :qq:
I recently looked through one of my old projects that scraped a game's forums general discussion and ran it through a Markov chain.

It was in Python using Django and god some of this crap I wrote is awful.
code:
def clean_phrase(phrase):
	"""
	Input badly formatted phrase and it'll output a better formated phrase!
	"""
	# Captialize first word of every sentence.  Fix unneeded spaces 
	n = ""
	newSent = True
	periodLast = False
	spaceLast = False
	for i in phrase:
		if newSent == True and i.lower() not in string.lowercase:
			pass
		elif newSent == True and i != " ":
			n += i.upper()
			newSent = False
		elif periodLast == True and i != " ":
			n += i.upper()
			periodLast = False
		elif spaceLast == True and i == " ":
			pass
		elif i == " ":
			spaceLast = True
			n += i
		elif i == "." or i == "?" or i == "!":
			periodLast = True
			n += i
		else:
			n += i
			spaceLast = False
	quoteCount = 0
	left_pCount = 0
	right_pCount = 0
	left_bCount = 0
	right_bCount = 0
	left_cCount = 0
	right_cCount = 0
	for i in n:
		if i == "\"":
			quoteCount += 1
		elif i == "(":
			left_pCount += 1
		elif i == ")":
			right_pCount += 1
		elif i == "[":
			left_bCount += 1
		elif i == "]":
			right_bCount += 1
		elif i == "{":
			left_cCount += 1
		elif i == "}":
			right_cCount += 1
	return n + "."
I feel ashamed of this.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Edison was a dick posted:

The video http://vimeo.com/9270320 makes a lot of points and actually has researched them. One of the conclusions that lines of code is the best metric that actually works, the more you have, the more bugs you have, and humans can't really manage more than 200 lines of code at once.
The fellow who wrote that class is the only person who can possibly understand it.

What can't be more than 200 lines of code? The whole class? A single method? The template that expands repeatedly into the boilerplate for serialization? The total compilation unit with includes?

That having more code means having more bugs seems uncontroversial, or does it mean more bugs per KLOC? My spidey sense has learned to prefer clear-but-verbose in terms of reducing bug habitat.

(The video has crashed every browser on my phone, but I might try it later.)

FamDav
Mar 29, 2008

Subjunctive posted:

What can't be more than 200 lines of code? The whole class? A single method? The template that expands repeatedly into the boilerplate for serialization? The total compilation unit with includes

i think its 200 loc that the average developer can internalize and think about at the same time.

sarehu
Apr 20, 2007

(call/cc call/cc)
That is bogus, because how easy something to internalize is depends on how complicated it is. Multi-threaded problems vs. single-threaded problems is one example, but really in general, the ability to understand something is related more closely to the size of the state space and not how many lines of code it takes.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

FamDav posted:

i think its 200 loc that the average developer can internalize and think about at the same time.

I'm not sure what that means. If I'm working on a block of code that manipulates 20 types, each with 10 fields, do I have zero left for the code itself?

hobbesmaster
Jan 28, 2008

Subjunctive posted:

I'm not sure what that means. If I'm working on a block of code that manipulates 20 types, each with 10 fields, do I have zero left for the code itself?

Well yeah, you've run out of stack space at that point.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

hobbesmaster posted:

Well yeah, you've run out of stack space at that point.

Seems unlikely. It's not uncommon for a single line in Java to reference 5 types, through property chaining and so forth.

Java code:

ret = obj.getInner().makeButt(otherObj.buttSize());

1337JiveTurkey
Feb 17, 2005

Shinku ABOOKEN posted:

Required reading for all game engine programmers:
http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/

It's by one of the people working on the Tony Hawk games. It describes the challenges they faced with big blob objects and how their stuff into components ease the pain.

Blob objects include functionality that's ill-defined and covers large parts of the game that aren't necessarily related in the first place. If the class also controls the lifecycle of the character in the world, their position, scheduling, saving and loading etc. then it's definitely a blob. This includes the stats related to a single character plus derived stats and related methods. It feels disorganized and has a lot of stuff in there, but there is a very defined focus of what the class is and what it does.

Giving a concrete alternative rather than saying just "refactor it" makes unexamined assumptions more clear. How expensive is having a separate object per basic character stat in the big scheme of things? How much logic can actually be stuck into such a class? Are some calculations dependent on enough factors that we're just going to end up passing the rest of the object into the supposedly independent functions in the first place? Would pulling backgrounds, classes, races, cultures and the like into separate objects add flexibility that we have the resources to take advantage of?

silvergoose
Mar 18, 2006

IT IS SAID THE TEARS OF THE BWEENIX CAN HEAL ALL WOUNDS




Subjunctive posted:

Seems unlikely. It's not uncommon for a single line in Java to reference 5 types, through property chaining and so forth.

Java code:
ret = obj.getInner().makeButt(otherObj.buttSize());

No no. ret = ButtBuilder.buttSize(10).buttDepth(DEFAULT_BUTT_DEPTH).buttHeight(10).build();

Literally Elvis
Oct 21, 2013

The world's first cryptocurrency written in PHP

Space Kablooey
May 6, 2009



http://dcoinforum.org/index.php?topic=9.0 posted:

3rd year

January

DC-network accounts for 1.5 billion users.
The amount of promises reaches $1 trillion.
The amount of DUSD is 1.2 trillion.
Rate on the exchanges is $3.1 per 1 DUSD.
The stores indicate two prices – $ and DUSD, and the price in $ is constantly growing. Inflation of U.S. dollar reaches 30% per year. Inflation of DUSD does not exceed 3% per year.
Google acquires Visa and MasterCard on the verge of their bankruptcy and changes them into full support for DC-currencies

April

Inflation of the Russian ruble reaches 70% per year.
The government, after repeated and failed attempts to ban the use of DRUB, decides to switch off the Internet. This leads to mass protests, uprising, revolution and change of power. Putin runs away to Cuba.


August

All companies, which have switched to work with the DUSD in advance, now thrive and develop.
The banks go bankrupt one after the other; the spontaneous exchanges emerge where large companies and billionaires sell USD for a mere song to convert at least part of their capital into DUSD.
Since DUSD is created in the amount sufficient for the functioning of the U.S. economy, the redistribution of capital occurs. In other words, if Fannie Mae sells $10 billion for one billion of DUSD, it means that DUSD can be multiplied for another 9 billion, which will be accrued in the form of the interest to everyone who has DUSD.

The exchange mechanism of DUSD into USD, built into the DC-network, ceases to be relevant, because nobody needs USD, everyone wants to buy DUSD.
Those who trusted the DC from the very beginning, become millionaires. Those who refused to believe until recently, now just get paid in DC-currency.

My bolding

Westie
May 30, 2013



Baboon Simulator

David Wynn: Miner

Paul MaudDib
May 3, 2006

TEAM NVIDIA:
FORUM POLICE

ErIog posted:

Most of the ire toward Unity in the game dev community is somewhat recent, though. So I wouldn't really blame anyone for having picked it for their project that's been in development for a long time. If a dude's got time to decompile and bitch about what he finds online then the Unity engine itself a much more target-rich environment for horrors.

Honestly it's still great for what it is. It's My First Game Studio, and it does a pretty OK job of balancing user friendliness with capability.

Pretty much every product has some rough corners, the question is total time relative to the alternative. My understanding is that building your game on something like Unreal is going to involve a lot more effort and up-front investment.

Paul MaudDib fucked around with this message at 23:29 on Sep 22, 2014

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

Paul MaudDib posted:

Honestly it's still great for what it is. It's My First Game Studio, and it does a pretty OK job of balancing user friendliness with capability.

The reality is there is nothing wrong with a framework, engine, environment, or whatever that makes it easy for people to get started. When you reach the limits of that system, it's a sign that you need to move on to something deeper.

I don't think I'd want to tackle Unreal with my first game project.

Trammel
Dec 31, 2007
.
Database horror, also kind of funny. The columns in a Contract_SpecialPricing table. The database has 280+ tables, and is generally normalized, I'm hoping this is just an outlier.

code:
CoSp_Id
CoSp_CreatedBy
CoSp_CreatedDate
CoSp_UpdatedBy
CoSp_UpdatedDate
CoSp_TimeStamp
CoSp_Deleted
CoSp_Secterr
cosp_MonthlyAmt_CID
cosp_MonthlyAmt
cosp_StartDate
cosp_EndDate
cosp_MonthlyAmt2_CID
cosp_MonthlyAmt2
cosp_MonthlyAmt3_CID
cosp_MonthlyAmt3
cosp_MonthlyAmt4_CID
cosp_MonthlyAmt4
cosp_StartDate2
cosp_EndDate2
cosp_StartDate3
cosp_EndDate3
cosp_StartDate4
cosp_EndDate4
cosp_ContractId
cosp_monthlyamt5_CID
cosp_monthlyamt5
cosp_monthlyamt6_CID
cosp_monthlyamt6
cosp_startdate5
cosp_startdate6
cosp_enddate5
cosp_enddate6

Pythagoras a trois
Feb 19, 2004

I have a lot of points to make and I will make them later.

Edison was a dick posted:

The video http://vimeo.com/9270320 makes a lot of points and actually has researched them. One of the conclusions that lines of code is the best metric that actually works, the more you have, the more bugs you have, and humans can't really manage more than 200 lines of code at once.
The fellow who wrote that class is the only person who can possibly understand it.

Got any more links to talks you recommend? I put that video on while I was working yesterday and by the time it was over I'd already purchased a copy of the guy's book.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
How to Multiply in C Programming
Looking through his other videos this doesn't actually look like a troll.

Soricidus
Oct 21, 2010
freedom-hating statist shill

Aleksei Vasiliev posted:

How to Multiply in C Programming
Looking through his other videos this doesn't actually look like a troll.
His name is Butt.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Soricidus posted:

His name is Butt.
https://en.wikipedia.org/wiki/Butt_%28name%29

Meat Beat Agent
Aug 5, 2007

felonious assault with a sproinging boner
Why did his name change to Dave Andrews in the live version of the page

substitute
Aug 30, 2003

you for my mum
php:
<?
// prints message to page
function trace($msg){
    echo $msg.'<br />';
}
?>

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

daft punk railroad posted:

Why did his name change to Dave Andrews in the live version of the page
They redirect deleted guides to similar guides.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

substitute posted:

php:
<?
// prints message to pagefunction trace($msg){    echo $msg.'<br />';}?>

I do poo poo like that so I can easily turn tracing off or redirect it or reformat it, though sometimes I find I don't need to and just leave the minimal function in place instead of inlining it everywhere.

Unless I'm missing something. Or maybe I'm the horror.

Space Kablooey
May 6, 2009


I mean I don't PHP, but there really isn't any other way to trace stuff in a file or something? Anything else than dumping in the page?

Munkeymon
Aug 14, 2003

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



Subjunctive posted:

I do poo poo like that so I can easily turn tracing off or redirect it or reformat it, though sometimes I find I don't need to and just leave the minimal function in place instead of inlining it everywhere.

Unless I'm missing something. Or maybe I'm the horror.

If you're gonna be lazy about it at least put them in comment nodes just in case that laziness creeps into production accidentally.

HardDisk posted:

I mean I don't PHP, but there really isn't any other way to trace stuff in a file or something? Anything else than dumping in the page?

Better? Sure. Easier? Nope.

Haystack
Jan 23, 2005





So, this looks fun:

quote:

Stephane Chazelas discovered a vulnerability in bash, related to how
environment variables are processed: trailing code in function
definitions was executed, independent of the variable name.

In many common configurations, this vulnerability is exploitable over
the network.

http://seclists.org/oss-sec/2014/q3/649

tef
May 30, 2004

-> some l-system crap ->
See also XSA-108 :v:

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

tef posted:

See also XSA-108 :v:

Is it bash-related? An embargoed Xen vuln I assumed was some escape-to-dom0 shenanigans.

tef
May 30, 2004

-> some l-system crap ->

Subjunctive posted:

Is it bash-related? An embargoed Xen vuln I assumed was some escape-to-dom0 shenanigans.

It's not bash related, it's just a high impact vuln coming out soon: I don't have any details beyond a) it's happening, and b) good luck with AWS this weekend

Vanadium
Jan 8, 2005

What does bash parse functions out of environment variables in the first place? :ohdear:

Marsol0
Jun 6, 2004
No avatar. I just saved you some load time. You're welcome.

Vanadium posted:

What does bash parse functions out of environment variables in the first place? :ohdear:

CGI, I believe. Request headers to a CGI program are parsed into environment variables and you can configure a request header to exploit the bash vulnerability. Here's a list of header variables: http://www.cgi101.com/book/ch3/text.html

That's my understanding, at least.

Vanadium
Jan 8, 2005

I think I get how people end up injecting environment variables, but who thought it would be a good idea to interpret random strings found at arbitrary places in the environment as functions at startup?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Sometimes you just want to pass a callback to some program.

Then your options are:
- send a string and have the receiving program eval() it
- create a function and send it somehow

If it were implemented correctly, being able to pass functions in environment variables wouldn't actually be a problem.

Jewel
May 2, 2009

So. Robert Penner made the easing functions that pretty much everyone uses when making games, or if they use an easing library it's probably using these equations behind the scenes.
The typical lerping equation is, or at least, should be, mathematically this:

C# code:
value = start + (change * percent) //Where change is end - start
If you take a look at those equations, you can probably see something massively wrong straight away. They're all wrong.
Let's take the easeOutElastic as an example, this is the basic easeOutElastic function (I'm gonna be reducing most of this to C#-y psuedocode/just math)

C# code:
float easeOutElastic(float t, float b, float c, float d)
{
	if (t==0) return b;
	if ((t/=d)==1) return b+c; //Note how t is now a ratio from 0 - 1
	
	float p = d * .3;
	float s = p / 4;
	
	return c * Math.pow(2,-10*t) * Math.Sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
}
So already there's just a load of crap all over the place.
t is "Current Time", d is "Duration", b is "Start", c is "Change"
Notice how t and d are on the opposite side of the function, yet they're related? Also the horrible naming in general? I'll get to that later.

So now we have the one line to resolve at the bottom. What's it doing?
Replacing the math that doesn't involve b or c with num1/num2/etc for each equation, we get:

C# code:
c * num1 * num2 + c + b
->
change * somenumber + change + start
->
change * somenumber + end
This is pretty close to start + (change * percent)! Let's seperate it first.

C# code:
float easeOutElastic(float t, float b, float c, float d)
{
	if (t==0) return b;
	if ((t/=d)==1) return b+c;
	
	float p = d * .3;
	float s = p / 4;
	
	float percent = Math.pow(2,-10*t) * Math.Sin( (t*d-s)*(2*Math.PI)/p );
	
	return c * percent + c + b;
}
So what's wrong with it? Well, it seems it's going from end, then adding change * percent. That means change * percent is negative if it wants to lerp from start-end

When t is 0, percent is -1. When t is 1, percent is 0. Normally it should be 0 to 1 both ways, because the percent is just a mapping function to map 0 to 1 to a special "bouncing" ease.

So we just add 1 to percent to turn it into a 0 to 1 range. Now we have the classic formula!

C# code:
float easeOutElastic(float t, float b, float c, float d)
{
	if (t==0) return b;
	if ((t/=d)==1) return b+c;
	
	float p = d * .3;
	float s = p / 4;
	
	float percent = 1 + Math.pow(2,-10*t) * Math.Sin( (t*d-s)*(2*Math.PI)/p );
	
	return b + (c * percent);
}
And to make that even simpler we can wrap up the percent calculation into it's own implementation (and fix the variable names)

C# code:
float easeOutElasticImpl(float percent)
{
	return 1 + Math.pow(2,-10 * percent) * Math.Sin((percent - 0.075) * (2*Math.PI) / 0.3);
}

float easeOutElastic(float currentTime, float duration, float start, float change)
{
	if (t==0) return start;
	if (t==d) return start+change;
	
	float percent = easeOutElasticImpl(currentTime / duration);
	
	return start + (change * percent);
}
One of the biggest advantage of this other than formatting is that now we can even use the easeOutElasticImpl in a premade lerping function for any value; like vectors, not just floats. Plus we can even make the function entirely generic.

I was really confused as to why, and even how they were written so bad, so I tweeted at the original author of the equations and got back some real fun answers :allears:



There's also a secondary reason it's in the coding horrors thread, not just for Robert's code but for actionscript's interpreter:


And best for last; my personal favorite reasoning is the parameter order!


Edit: vvv Yeah but it's widely used in everything to this day. Also age doesn't mean the math should have been so messed up, it's not like the concept of math is as new as programming.

Jewel fucked around with this message at 15:14 on Sep 25, 2014

Adbot
ADBOT LOVES YOU

Polio Vax Scene
Apr 5, 2009



Thing written 13 years ago was written poorly, news at 11

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