As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
Options

PA Programming Thread :: PAdev.net - Need hosting for a service of yours? Check it out.

24567100

Posts

  • Options
    admanbadmanb unionize your workplace Seattle, WARegistered User regular
    The alternative was that they, the developers, would have to talk to mere users to figure out how to develop their product. What other option did they have???

  • Options
    bowenbowen How you doin'? Registered User regular
    Ahaha that's grand.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    The AnonymousThe Anonymous Uh, uh, uhhhhhh... Uh, uh.Registered User regular
    Excuse me while I go write a BASIC knock-off that will revolutionise the industry!

    In fact, it's practically done right now!

  • Options
    Lux782Lux782 Registered User regular
    edited September 2011
    So I have been writing some unit tests of a UnitVector class I have been writing. Super simple class but I have come to a bit of a problem when dealing with doubles and Math.Sin / Math.Cos / Math.Tan. For testing thus far I have used rounding an that has worked well enough for Asserting. However I have a method to create a unit vector from x y components.

    Behold the class (All written by TDD so some special cases aren't taken into account because I haven't reached that point in my tests)
    namespace LunarLander.GameLogic {
    	public struct UnitVector {
    		public Angle Direction;
    		public double XComponent;
    		public double YComponent;
    		
    		public static UnitVector FromAngle(Angle direction) {
    			return new UnitVector {
    				Direction = direction,
    				XComponent = Math.Cos(direction.Radians),
    				YComponent = Math.Sin(direction.Radians)
    			};
    		}
    		
    		public static UnitVector FromComponent(double x, double y) {
    			if (x == 0)
    				return FromAngle(Angle.FromDegrees(90));
    			
    			if (y < 0) 
    				return FromAngle(Angle.FromRadians(-Math.Tanh(-y / x) + Math.PI));
    			
    			return FromAngle(Angle.FromRadians(Math.Tanh(y / x)));
    		}
    	}
    }
    

    Now for the tests in question.
    		[Test()]
    		public void HandleComponentsFor0Degrees() {
    			Validate(0, UnitVector.FromComponent(1, 0).Direction.Degrees);
    		}
    		
    		[Test()]
    		public void HandleComponentsFor30Degrees() {
    			Validate(30, UnitVector.FromComponent(Math.Sqrt(3) / 2.0, 0.5).Direction.Degrees, 0);
    		}
    		
    		[Test()]
    		public void HandleComponentsFor90Degrees() {
    			Validate(90, UnitVector.FromComponent(0, 1).Direction.Degrees, 0);
    		}
    		
    		[Test()]
    		public void HandleComponentsFor150Degrees() {
    			Validate(150, UnitVector.FromComponent(-Math.Sqrt(3) / 2.0, 0.5).Direction.Degrees, 0);	
    		}
    		
    		[Test()]
    		public void HandleComponentsFor180Degrees() {
    			Validate(180, UnitVector.FromComponent(-1, 0).Direction.Degrees, 0);
    		}
    		
    		[Test()]
    		public void HandleComponentsFor225Degrees() {
    			Validate(225, UnitVector.FromComponent(-Math.Sqrt(2) / 2.0, -Math.Sqrt(2) / 2.0).Direction.Degrees, 0);
    		}
    		
    		[Test()]
    		public void HandleComponentsFor240Degrees() {
    			Validate(240, UnitVector.FromComponent(-0.5, -Math.Sqrt(3) / 2.0).Direction.Degrees, 0);
    		}
    
    		private void Validate(double expected, double actual, int percision) {
    			Assert.AreEqual(
    				Math.Round(expected, percision),
    				Math.Round(actual, percision)
    			);
    		}
    

    So the tests for degrees 0 to 180 pass. 225 and 240 fail. The output for 225 is 224 and the output for 240 is 234. I am convinced its due to doubles but I am not sure if there is anything I can actually do about it. Any advice? I wrote the 240 unit test to see if the different between the actual and expected was the same as the 225 test.

    Lux782 on
  • Options
    ecco the dolphinecco the dolphin Registered User regular
    edited September 2011
    I can see 224/225 being due to rounding errors, but 240/234 is just crazy.

    If 240/234 is due to rounding errors, then there is a serious problem somewhere.

    Edit: I'll follow it through when I get home in a few hours.

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • Options
    DehumanizedDehumanized Registered User regular
    EvilMonkey wrote:
    Incindium wrote:
    Productivity Power Tools adds some of that enhanced scroll bar functionality(plus a ton of other awesome stuff).
    http://visualstudiogallery.msdn.microsoft.com/d0d33361-18e2-46c0-8ff2-4adea1e34fef
    Looks promising, thank you good sir!

    By the way, these are integrated into stock Visual Studio for the next release. I like them a lot!

  • Options
    InfidelInfidel Heretic Registered User regular
    First off, rounding is not how you test for equal floating point values, you check the difference is within a small range (an epsilon).

    x = 0 at 90 and 270 degrees, not just 90.

    Possibly more issues dunno that was just looking quick.

    OrokosPA.png
  • Options
    ASimPersonASimPerson Cold... and hard.Registered User regular
    seabass wrote:
    So this semester they've got me TA'ing for the algorithms. This means I need to write in C. There isn't anything wrong with C, it's a lovely language (that I barely know how to use). The students hate that I make liberal use of function pointers, and I hate that I can't curry away arguments.

    What's a good guide to idiomatically programming C? I keep the bible (K&R) on my desk, but that's more of a "what does this function do" sort of thing, not "here is the way C wants you to design an iteration function".

    I don't know about everyone else, but I'm one of the C guys in this thread and my mind is just reeling that you would use something like C in an algorithms course. Assuming that's what you meant, as I'm also confused by what you mean by "iteration function" and "curry away arguments".

  • Options
    ecco the dolphinecco the dolphin Registered User regular
    edited September 2011
    Infidel wrote:
    First off, rounding is not how you test for equal floating point values, you check the difference is within a small range (an epsilon).

    x = 0 at 90 and 270 degrees, not just 90.

    Possibly more issues dunno that was just looking quick.

    There's something deeper, but I can't seem to find it. 6 degrees is just over 0.1 radians - which is just far too large for rounding error using doubles.
    ASimPerson wrote:
    seabass wrote:
    So this semester they've got me TA'ing for the algorithms. This means I need to write in C. There isn't anything wrong with C, it's a lovely language (that I barely know how to use). The students hate that I make liberal use of function pointers, and I hate that I can't curry away arguments.

    What's a good guide to idiomatically programming C? I keep the bible (K&R) on my desk, but that's more of a "what does this function do" sort of thing, not "here is the way C wants you to design an iteration function".

    I don't know about everyone else, but I'm one of the C guys in this thread and my mind is just reeling that you would use something like C in an algorithms course. Assuming that's what you meant, as I'm also confused by what you mean by "iteration function" and "curry away arguments".

    [strike]Maybe "curry away" means go away like default arguments in C++?[/strike]

    Edit: Garthor wins!

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • Options
    GarthorGarthor Registered User regular
    ASimPerson wrote:
    seabass wrote:
    So this semester they've got me TA'ing for the algorithms. This means I need to write in C. There isn't anything wrong with C, it's a lovely language (that I barely know how to use). The students hate that I make liberal use of function pointers, and I hate that I can't curry away arguments.

    What's a good guide to idiomatically programming C? I keep the bible (K&R) on my desk, but that's more of a "what does this function do" sort of thing, not "here is the way C wants you to design an iteration function".

    I don't know about everyone else, but I'm one of the C guys in this thread and my mind is just reeling that you would use something like C in an algorithms course. Assuming that's what you meant, as I'm also confused by what you mean by "iteration function" and "curry away arguments".

    "Iteration function" is not one I've heard before, but looking it up it sounds like, essentially, f(f(f(f(x)))). Not sure exactly how the language would modify how you would define such a function, so I'm going to guess that I have that wrong.

    "Currying away arguments" I'm fairly sure is currying a function, whereby some function f(x,y)->z is changed to f(x)->g(y)->z. A function of two arguments (x,y) is turned into a function of one argument (x) which returns a function of one argument (y) which will return the final value. This is a Big Thing with functional ("functional" languages do all sorts of things with functions? Crazy!) languages like Haskell. Actually, there's even a function called curry in Haskell, of type ((a,b) -> c) -> a -> b -> c. Whee!

  • Options
    bowenbowen How you doin'? Registered User regular
    I remember when my friend was using C for data structures. It confused the shit out of me why they would do that to a student.

    Doubly linked list in C how fun!

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    seabassseabass Doctor MassachusettsRegistered User regular
    edited September 2011
    ASimPerson wrote:
    seabass wrote:
    So this semester they've got me TA'ing for the algorithms. This means I need to write in C. There isn't anything wrong with C, it's a lovely language (that I barely know how to use). The students hate that I make liberal use of function pointers, and I hate that I can't curry away arguments.

    What's a good guide to idiomatically programming C? I keep the bible (K&R) on my desk, but that's more of a "what does this function do" sort of thing, not "here is the way C wants you to design an iteration function".

    I don't know about everyone else, but I'm one of the C guys in this thread and my mind is just reeling that you would use something like C in an algorithms course. Assuming that's what you meant, as I'm also confused by what you mean by "iteration function" and "curry away arguments".

    I'm not exactly sure why we picked C for an algorithms course either. I would have picked... well anything with managed memory honestly. I think the language was dictated by the department chair.

    For currying, Garthor is basically spot on.

    As for iterating, I just suck at communicating I guess. Don't you ever feel like applying a function once to every member of a collection? Like say... I dunno, printing out every member of a list or a hashtable. Basically I'm asking, "Hey, if you have a hashtable that you're providing to people, and you want to give them a way to iterate through the elements of that table, what's the best way to do it? Do you write an iterator that accepts a function to be applied to each element, or do you write a function that allows you to sequentially access the members of the data structure using something like next, previous, and reset?" Both are obviously possible, but which is more C-ish?

    seabass on
    Run you pigeons, it's Robert Frost!
  • Options
    bowenbowen How you doin'? Registered User regular
    for(int i = 0; i < hashTable.Length; g(f(h(i++));
    

    I mean we could make it more complex than that, but you get the idea. This is probably the one situation where bodyless for loops are preferred.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    TomantaTomanta Registered User regular
    Just about all my important CS classes were done in C, or C++ pretending to be C.

    But I also didn't go to a very good school.

  • Options
    seabassseabass Doctor MassachusettsRegistered User regular
    Tomanta wrote:
    Just about all my important CS classes were done in C, or C++ pretending to be C.

    But I also didn't go to a very good school.

    We had an unspoken rule that every class (outside of the intro series) used a new language. So... I've seen a little bit of everything, but I'm not particularly great with any of them.

    Run you pigeons, it's Robert Frost!
  • Options
    bowenbowen How you doin'? Registered User regular
    That's silly. It'd be better if you just picked a language and stuck to it.

    My classes were in C++ and Java. I'd wished it focused more on C++ than Java though. But pointers confuse the shit out of some people.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    In my experience pointers confused the shit out of most people

  • Options
    jackaljackal Fuck Yes. That is an orderly anal warehouse. Registered User regular
    The professor teaching the class should pick whatever language is best for teaching the concepts. In the real world you probably won't be able to stick with the same language and it helps show that the world of programming isn't just static types imperative languages. A few classes they let us pick whatever language we wanted and as long as it ran and the code looked reasonable they didn't give a fuck.

  • Options
    bowenbowen How you doin'? Registered User regular
    Phyphor wrote:
    In my experience pointers confused the shit out of most people

    It's surprising really, that someone that's in comp-sci can be confused by the concept of what pointers are. The concept isn't sufficiently difficult but there are just some people that can't make sense of it.

    Then there's the difference between reference, pointer, and all that shit that just adds fuel to the fire.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    EtheaEthea Registered User regular
    I have to slow down when I see something like int **& foo

  • Options
    bowenbowen How you doin'? Registered User regular
    edited September 2011
    Ethea wrote:
    I have to slow down when I see something like int **& foo

    I obviously haven't run across where that would be applicable before. That would be semi-confusing, do you guys write your own GC @Ethea?

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    templewulftemplewulf The Team Chump USARegistered User regular
    edited September 2011
    bowen wrote:
    Phyphor wrote:
    In my experience pointers confused the shit out of most people

    It's surprising really, that someone that's in comp-sci can be confused by the concept of what pointers are. The concept isn't sufficiently difficult but there are just some people that can't make sense of it.

    Then there's the difference between reference, pointer, and all that shit that just adds fuel to the fire.

    Sometimes I miss pointers, because the kind of implicit reference assignment you see in Java / C# is confusing to me. Will this assign as a value or a reference? If it's a reference, is it COW? Or is it just a smart pointer now and everything gets my changes? What happens if garbage gets collected while the object that contains this reference is still in scope?

    These are all easy questions if I just stop to think about them, but I think C++ made me into a control freak. I love highly explicit coding. :winky:

    templewulf on
    Twitch.tv/FiercePunchStudios | PSN | Steam | Discord | SFV CFN: templewulf
  • Options
    bowenbowen How you doin'? Registered User regular
    Yeah those questions worry me in C#. I just try to program in such a way I'm not really passing things that can't be references. Classes, great, you're a reference type, everything else (usually the case) I just assume is a value type.

    C++ has its bonuses though, but that's what unsafe is for!

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    amnesiasoftamnesiasoft Thick Creamy Furry Registered User regular
    seabass wrote:
    We had an unspoken rule that every class (outside of the intro series) used a new language.
    Hm, thus far most of my high level classes have been "use whatever language you want."

    Except Principles of Programming Languages, we have to use Java for the professor's convenience.

    steam_sig.png
  • Options
    EtheaEthea Registered User regular
    bowen wrote:
    Ethea wrote:
    I have to slow down when I see something like int **& foo

    I obviously haven't run across where that would be applicable before. That would be semi-confusing, do you guys write your own GC @Ethea?

    We have our own reference counting to warn of object leaking, we have multiple types of pointers (smart,weak,scoped) but we don't have a full GC. We use *& in numerous locations when you need to assign a pointer to a new location, mainly from NULL to some internal storage location, and I have seen **& when you want to do the same with an array of pointers.

  • Options
    seabassseabass Doctor MassachusettsRegistered User regular
    seabass wrote:
    We had an unspoken rule that every class (outside of the intro series) used a new language.
    Hm, thus far most of my high level classes have been "use whatever language you want."

    Except Principles of Programming Languages, we have to use Java for the professor's convenience.

    Our senior year was project based. So, it had more to do with what the client wanted than anything else. Where I work now, most senior courses are, as you say, "use whatever you want, here's the output spec."

    Run you pigeons, it's Robert Frost!
  • Options
    bowenbowen How you doin'? Registered User regular
    Ethea wrote:
    bowen wrote:
    Ethea wrote:
    I have to slow down when I see something like int **& foo

    I obviously haven't run across where that would be applicable before. That would be semi-confusing, do you guys write your own GC @Ethea?

    We have our own reference counting to warn of object leaking, we have multiple types of pointers (smart,weak,scoped) but we don't have a full GC. We use *& in numerous locations when you need to assign a pointer to a new location, mainly from NULL to some internal storage location, and I have seen **& when you want to do the same with an array of pointers.

    Ah that's what I figured you were doing with the reference to pointers ninja programming. I'm surprised no one's gone the extra half step to finish it to be a full gc.

    The only place I could think of for **& in practical terms was for memory management or garbage collection. Still pretty rare I bet.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    The AnonymousThe Anonymous Uh, uh, uhhhhhh... Uh, uh.Registered User regular
    So I spent half of today trying to write a math parser, then the other half adding a dice roll operator to a pre-existing parser only to expose strange bugs in the parser that only crop up when an operator just happens to be a single alphabetic character.

    In short: fuck math parsers. :x

  • Options
    Jimmy KingJimmy King Registered User regular
    Anyone have any experience with and tips on (or links with good info) for layout of a large Django project which will likely have multiple sites that need their own settings plus some shared settings and some app sharing between the sites?

    I've only done stuff where there's really just one site, one settings.py, etc. The main project here at work has multiple sites with shared and overridden settings, but it doesn't use virtualenv, requires hosing $PYTHONPATH for anything else, etc. so I don't want to follow that if I can avoid it.

  • Options
    seabassseabass Doctor MassachusettsRegistered User regular
    So I spent half of today trying to write a math parser, then the other half adding a dice roll operator to a pre-existing parser only to expose strange bugs in the parser that only crop up when an operator just happens to be a single alphabetic character.

    In short: fuck math parsers. :x

    Is there a reason not to use a parser generator like yacc?

    Run you pigeons, it's Robert Frost!
  • Options
    InfidelInfidel Heretic Registered User regular
    Learning experience, and simplicity if you're dealing with limited grammar.

    Such as a dice roller! :winky:

    OrokosPA.png
  • Options
    bowenbowen How you doin'? Registered User regular
    Ah simplistic programmer websites. They calm me.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    InfidelInfidel Heretic Registered User regular
    It's not black on white! Amazing, no?

    OrokosPA.png
  • Options
    PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    seabass wrote:
    So I spent half of today trying to write a math parser, then the other half adding a dice roll operator to a pre-existing parser only to expose strange bugs in the parser that only crop up when an operator just happens to be a single alphabetic character.

    In short: fuck math parsers. :x

    Is there a reason not to use a parser generator like yacc?

    It looks like he's using Java/C# from that library. Besides, Real Programmers do a manual recursive descent parser!

  • Options
    bowenbowen How you doin'? Registered User regular
    Infidel wrote:
    It's not black on white! Amazing, no?

    It's not designed around using images for layout, just text, I like text.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    InfidelInfidel Heretic Registered User regular
    bowen wrote:
    Infidel wrote:
    It's not black on white! Amazing, no?

    It's not designed around using images for layout, just text, I like text.

    Well yeah, just use some CSS, what the hell would I have images for!

    Something that is actually done up would be the character sheets, and that only has the one image pretty much. Well, that and the d6 icon.

    OrokosPA.png
  • Options
    templewulftemplewulf The Team Chump USARegistered User regular
    Infidel wrote:
    bowen wrote:
    Infidel wrote:
    It's not black on white! Amazing, no?

    It's not designed around using images for layout, just text, I like text.

    Well yeah, just use some CSS, what the hell would I have images for!

    Something that is actually done up would be the character sheets, and that only has the one image pretty much. Well, that and the d6 icon.

    I <3 CSS positioning. A local MMA studio uses honest to god Angelfire circa 1998 tables and frames. I want to donate my services to them just to get that site off the Internet.

    Twitch.tv/FiercePunchStudios | PSN | Steam | Discord | SFV CFN: templewulf
  • Options
    jackaljackal Fuck Yes. That is an orderly anal warehouse. Registered User regular
    Infidel wrote:
    Learning experience, and simplicity if you're dealing with limited grammar.

    Such as a dice roller! :winky:

    Pro-est online dice roller.

    http://www.youtube.com/watch?v=7n8LNxGbZbs

  • Options
    bowenbowen How you doin'? Registered User regular
    I wonder if those are fair dice.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    InfidelInfidel Heretic Registered User regular
    I need more than d6!

    OrokosPA.png
This discussion has been closed.