admanbunionize your workplaceSeattle, WARegistered Userregular
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???
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)));
}
}
}
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.
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".
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.
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]
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!
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?
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.
jackalFuck Yes. That is an orderly anal warehouse.Registered Userregular
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.
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
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:
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
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.
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."
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
0
The AnonymousUh, uh, uhhhhhh...Uh, uh.Registered Userregular
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.
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.
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?
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!
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 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.
Posts
In fact, it's practically done right now!
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)
Now for the tests in question.
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.
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.
By the way, these are integrated into stock Visual Studio for the next release. I like them a lot!
x = 0 at 90 and 270 degrees, not just 90.
Possibly more issues dunno that was just looking quick.
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".
SE++ Forum Battle Archive
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.
[strike]Maybe "curry away" means go away like default arguments in C++?[/strike]
Edit: Garthor wins!
"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!
Doubly linked list in C how fun!
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?
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.
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.
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.
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.
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?
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:
C++ has its bonuses though, but that's what unsafe is for!
Except Principles of Programming Languages, we have to use Java for the professor's convenience.
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.
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."
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.
In short: fuck math parsers. :x
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.
Is there a reason not to use a parser generator like yacc?
Such as a dice roller! :winky:
It looks like he's using Java/C# from that library. Besides, Real Programmers do a manual recursive descent parser!
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
Pro-est online dice roller.