|
Plorkyeran posted:"Most" is a bit of an understatement. A short-circuiting bitwise operator would be like short-circuiting multiplication. You could do it if the first operand were 0, mind you (assuming it's not floating-point, of course). That would work for multiplication and bitwise AND, I believe. The all-1s case would be the equivalent for bitwise OR. Whether it's useful or wise to do this is another matter altogether. EDIT: Not division, since 0/0 could occur even in integer division. PT6A fucked around with this message at 05:23 on Apr 16, 2010 |
# ? Apr 16, 2010 05:18 |
|
|
# ? May 18, 2024 10:56 |
|
In Java | and & are the non-short-circuiting versions of || and &&.
|
# ? Apr 16, 2010 05:31 |
|
Nippashish posted:In Java | and & are the non-short-circuiting versions of || and &&.
|
# ? Apr 16, 2010 05:55 |
|
Plorkyeran posted:Compare 1 && 2 and 1 & 2. They're also bitwise operators when the operands are integral types. Maybe you should try them with boolean operands.
|
# ? Apr 16, 2010 06:21 |
|
Nippashish posted:In Java | and & are the non-short-circuiting versions of || and &&. The same behavior is exhibited in, like, every language, not just Java. So I don't get what you're getting at. Nippashish posted:They're also bitwise operators when the operands are integral types. Maybe you should try them with boolean operands. They're bitwise operators for boolean types in Java too.
|
# ? Apr 16, 2010 06:27 |
|
Help what is boolean logic it is very confusing to me with all those 1's and 0's.
|
# ? Apr 16, 2010 06:54 |
|
How would I create a function that prints its own definition? I've been given the problem in Haskell, but I can't figure how I would do it in any language, short of opening the file and printing from there.
|
# ? Apr 16, 2010 11:12 |
|
Nippashish posted:They're also bitwise operators when the operands are integral types. Maybe you should try them with boolean operands.
|
# ? Apr 16, 2010 13:45 |
|
Pantsmaster Bill posted:How would I create a function that prints its own definition? I've been given the problem in Haskell, but I can't figure how I would do it in any language, short of opening the file and printing from there. What you're looking for is a quine
|
# ? Apr 16, 2010 14:31 |
|
Pantsmaster Bill posted:How would I create a function that prints its own definition? I've been given the problem in Haskell, but I can't figure how I would do it in any language, short of opening the file and printing from there. Depends very much on the language's implementation, both in terms of whether it's even possible, and in terms of the specific methodology you'd use to obtain the source code. Here's a Python example, though it only appears to work if defined in an actual on-disk file -- won't work in the interpreter. I assume this is because it's actually reading the file to get the source; this ain't exactly something one does in daily coding (unless you work in Lisp a lot I guess) vv code:
|
# ? Apr 16, 2010 14:33 |
|
bitprophet posted:Depends very much on the language's implementation, both in terms of whether it's even possible, and in terms of the specific methodology you'd use to obtain the source code. This is the lame cop out way. You want a quine like csammis suggested.
|
# ? Apr 16, 2010 16:32 |
|
edit: nvm, got it!
Montalvo fucked around with this message at 18:08 on Apr 16, 2010 |
# ? Apr 16, 2010 17:24 |
|
I have a hashing question that first came up in the C++ programming thread, but after thinking about it I think this is a general problem. I was using boost's unordered_map to do a ton of hashing it is a lot slower than the Java equivalent from which I was porting as an experiment. I ran gprof on it and got a huge templated mess that I posted in the C++ thread, but after a day I think I sorted it out. It looks like 50% of the run time is split between rearrange items in buckets and my equals operator. Does this imply I'm having a ton of hash collisions? I increased the default bucket size to about 1.25x the final number of entries I would store and it still ran rear end slow. I looked at my hash code output for some example data and originally it was kind of bad. Say, it would look something like: 849000xxxxxx Where the last few digits were the only thing really changing. I modified the hashing routine so that from increment to increment all sides appears to be the same. I suppose I could do a scatter plot of some sample data to see if it groups in places. Anyways I updated that and it still ran slow. WTH...
|
# ? Apr 16, 2010 18:11 |
|
Pantsmaster Bill posted:How would I create a function that prints its own definition? I've been given the problem in Haskell, but I can't figure how I would do it in any language, short of opening the file and printing from there. The easy way out I used to write a quine (as pointed by csammis) was usually some play on printf-like function. Basically, you have the function that can take a string representation of itself twice as argument and then output it. Here's the Erlang version I had written for rosettacode E: removed for breaking tables. See http://rosettacode.org/wiki/Quine#Erlang Here the list of integers is actually a string to Erlang. The first ~s interprets the list as a string and ~w interprets it as a list. In languages that do not require the whole module structure Erlang needs, quines can actually get much shorter because you can basically just print the argument string into itself. There are differences in every languages depending on different string representations or concepts like homoiconicity, but the basic easy way is always to have a function printing a string representation of itself + the string. E: sorry for table breakage and also csammis' link had it all explained. Here, have a quine page: http://rosettacode.org/wiki/Quine instead to make this post more worthy
|
# ? Apr 16, 2010 18:17 |
|
Rocko Bonaparte posted:It looks like 50% of the run time is split between rearrange items in buckets and my equals operator. Does this imply I'm having a ton of hash collisions?
|
# ? Apr 16, 2010 18:33 |
|
Mustach posted:Yes. Post your hash function. I will send it through pastebin so I can attach on an example of how it hashes a year worth of dates w/o a wall of text: http://pastebin.com/V5v3diSj
|
# ? Apr 17, 2010 01:22 |
|
Rocko Bonaparte posted:I will send it through pastebin so I can attach on an example of how it hashes a year worth of dates w/o a wall of text: The amount of collisions you have in that hash is absolutely ridiculous (to the point that I saw a few before I even sorted the lines by hash). You have a total of 42 unique hashes in that entire list. EDIT: first things first, I'm going to assume that you think a + b << c == a + (b << c). It doesn't, in general. + has higher precedence than <<. EDITx2: Oh wow. When you take the modulo of that with just about any reasonably-sized power of 2, they all fall in the same bucket. So basically you might as well have just written "return 0;" Avenging Dentist fucked around with this message at 01:58 on Apr 17, 2010 |
# ? Apr 17, 2010 01:32 |
|
Avenging Dentist posted:The amount of collisions you have in that hash is absolutely ridiculous (to the point that I saw a few before I even sorted the lines by hash). You have a total of 42 unique hashes in that entire list. Yes I had my order of operations wrong on the shift operators. I'll just work on the hash code for a little bit before getting into anything more fancy. Boost's method for handling dates and times is really starting to annoy the hell out of me. I wrote that code as a first attempt at trying to make something from what the API could give me. You'd think they had made hash operators for the objects they support. I suppose if I get it worked out I should send something off to boost. Since I first looked into it I found it can give me a julian date which I think is how the days are stored internally, so I think I'll just smash that with the time of day in nanoseconds and then try some things to make it collide less.
|
# ? Apr 17, 2010 06:43 |
|
Rocko Bonaparte posted:I found it can give me a julian date which I think is how the days are stored internally, so I think I'll just smash that with the time of day in nanoseconds and then try some things to make it collide less.
|
# ? Apr 17, 2010 19:37 |
|
Scaevolus posted:Why not just take the seconds since the epoch plus the time of day in nanoseconds?
|
# ? Apr 17, 2010 19:58 |
|
Scaevolus posted:Why not just take the seconds since the epoch plus the time of day in nanoseconds? Unless he's actually likely to have keys whose only difference is in nanoseconds, this is unnecessary and would probably just increase the chance of collisions. Since he appears to be using 64-bit values, he has enough space to have a unique hash for every 23 milliseconds since the beginning of the universe. He could just store the number of microseconds since some minimum date and be fine. Also this method has the benefit of making sure that relatively nearby times won't be congruent modulo N for most N (i.e. they won't fall into the same buckets). Also Rocko, if by "an additional hashing step", you're referring to the fact that you hash the integers you get from the date and time, that does literally nothing (at basically zero performance cost) since boost's hash function for integral values is the identity function. Avenging Dentist fucked around with this message at 23:43 on Apr 17, 2010 |
# ? Apr 17, 2010 23:41 |
|
Avenging Dentist posted:Also Rocko, if by "an additional hashing step", you're referring to the fact that you hash the integers you get from the date and time, that does literally nothing (at basically zero performance cost) since boost's hash function for integral values is the identity function. Since I'm writing my own, I could probably make use of the fact that the dates I'm dealing with will probably only span back to the last decade. However, right now I'm not seeing much of a collision problem anymore so I'm letting that be. I got my old Ubuntu setup working again and I think I want to try the slew of profiling tools that I can finally run (curse gentoo and it's qt4 zealotry among other things). As you said boost's foreach is the devil and I'm curious if in using it I'm incurring some nasty overhead. If I can start pegging events to locations in the code I think I'll know better what's really happening.
|
# ? Apr 18, 2010 00:18 |
|
Rocko Bonaparte posted:As you said boost's foreach is the devil and I'm curious if in using it I'm incurring some nasty overhead. If I can start pegging events to locations in the code I think I'll know better what's really happening. Performance should be pretty close if not the same when you optimize, but there's a lot happening under the hood.
|
# ? Apr 18, 2010 00:21 |
|
So I did some really good tutorials that taught me a ton (link), but the guy who wrote them is working on other things and there won't be more lessons for quite awhile. I have a good grasp of what's going on with programming, but I can't find any good resources to help me push forward and teach myself more because either what I'm reading is: A) Too Technical B) Poorly written and not thorough at explaining concepts C) Just plain terrible I'm sure you've read books like what's above, or online tutorials. I really just cannot find anything good. I have a clear goal of what I want to be doing with programming in the near future: Making a HL2 mod (I have friends who want to learn with me, except they're doing art). Obviously there is a lot of work in between programming a very complicated game engine like that and where I'm at making dos applications, but I really don't know where to start. I just want a resource that can explain what I need to learn effectively without trying to be too technical, or not technical enough (as in merely teaching syntax and not explaining). I'm open to any kind of learning process with a relatively low barrier of entry (i.e. doesn't cost thousands of dollars) If anybody's been in a similar situation and is now doing some more high-end programming, I'd be very interested to know how you got to where you are now.
|
# ? Apr 18, 2010 22:02 |
|
TheGopher posted:So I did some really good tutorials that taught me a ton (link), but So you wait, what? What are you talking about? So you're reading tutorials. Doing them. Okay. Tutorials about what? Okay, tutorials written by a redditor. Ugh. TheGopher posted:the guy who wrote them is working on other things and there won't be more lessons for quite awhile. I have a good grasp of what's going on with programming, but I can't find any good resources to help me push forward and teach myself more because either what I'm reading is: Hold on, what the hell. You haven't told us what you know, who you are, what you know, or what you know. How much do you know about programming? You have a good grasp of what's going on with programming? What does that even mean? I have no idea whether you could write a C++ compiler in your sleep or whether you'd have trouble writing the simplest of XML scrapers. TheGopher posted:A) Too Technical How can something be too technical? Programming is a technical subject, is it not? Does the thing-that-is-too-technical assume knowledge you don't have? If so, you can get that knowledge, and so it's not too technical. If not, then it's not too technical. TheGopher posted:B) Poorly written and not thorough at explaining concepts Show me something (other than CarlH's stuff) that's poorly written and not thorough. Maybe you're dumb and lazy. (Maybe you're not, I'm not saying you are, and I'm not even "asking" in the Fox News sense -- it's just that I don't know you.) TheGopher posted:C) Just plain terrible Yeah, there are a lot of these. But communication is a double-ended process so you can't go blaming the authors without blaming yourself. quote:I'm sure you've read books like what's above, or online tutorials. I really just cannot find anything good. You want to learn programming? Start by reading The Python Tutorial. How much do you know. Is that too beginner for you? I don't know. TheGopher posted:I have a clear goal of what I want to be doing with programming in the near future: Making a HL2 mod (I have friends who want to learn with me, except they're doing art). Obviously there is a lot of work in between programming Yeah, there's a lot of work, and a lot of what-do-I-do-next. You start by asking "how do I make an HL2 mod?" And then you type that into google. Maybe you'll get some clues on some game dev forum. Maybe you'll find an open source HL2 mod. Then you go and look at that code. See how it works. Modify it. Fiddle with it. Never once should you say, "I don't get this" and stop, because that's loving retarded. If you don't get it (and there are lots of times when you don't) you just need to ask yourself what information you need in order to get it. If you can't find that information, you need to figure out the information yourself, experimentally. TheGopher posted:a very complicated game engine like that and where I'm at making dos applications, but I really don't know where to start. I just want a resource that can explain what I need to learn effectively without trying to be too technical, or not technical enough (as in merely teaching syntax and not explaining). I'm open to any kind of learning process with a relatively low barrier of entry (i.e. doesn't cost thousands of dollars) If you want to make an HL2 mod, the barriers to entry are high and numerous. Deal with it.
|
# ? Apr 19, 2010 01:05 |
|
shrughes posted:multiquote reply that makes the post difficult to address CarlH (the author of those tutorials) wrote some pretty comprehensive information about programming. Maybe you could have taken 1 minute to click on the link and look at the most recently published lessons (which were from awhile ago) to see what I've been learning. The fact you'll bash him just because he's a Redditor without even reading what he's written really says a lot. (Maybe you have read his stuff, you didn't make that clear, in which case, please explain why I'm wrong about his writing being good) I know basic C concepts. Stuff like pointers, arrays, defining classes, typecasting, etc. Basic stuff. I have no idea where to go from here. To be clear, C is the only language I'm familiar with. I could probably get to the same point with another language with minimal effort because I really understand what I've been taught. The resources I've looked at read like a 5th grader's explanation of fractions, or read like any unix "man" entry. That is what I meant by "too technical" or "poorly written". I want something in between, something I can follow with a reasonable amount of effort. In terms of HL2 mods, I'm going through the Valve developer wiki, which is poo poo because most of the info on there is out of date and vague. I had to bash my head trying to get VSE2010's debugger to launch properly because of the complete lack of documentation. I figured out how to modify existing entities to the game and how the game revolves around them. I can figure out things on my own, I just need a better knowledge of C/C++ because I don't know what half of the functions I'm looking at are trying to accomplish or why they're needed. I've done a good amount of searching but there doesn't seem to be any good starting point for a new programmer trying to work with HL2. Let me put it this way, I can probably do problems 1-10 of project Euler, but after that I'm pretty much lost. How do I learn the programming methodology to progress further? TheGopher fucked around with this message at 01:35 on Apr 19, 2010 |
# ? Apr 19, 2010 01:32 |
|
TheGopher posted:CarlH (the author of those tutorials) wrote some pretty comprehensive information about programming. Maybe you could have taken 1 minute to click on the link and look at the most recently published lessons (which were from awhile ago) to see what I've been learning. You are the one asking for help. It is not shrughes' responsibility to try to decipher what it is you've learned. TheGopher posted:The fact you'll bash him just because he's a Redditor without even reading what he's written really says a lot. I skimmed over his tutorials and, lo and behold, it looks like shrughes' skepticism was totally merited. Teaching gotos before conditionals? Check. Asserting that arrays are pointers? Check. Asserting that all non-primitives are pointers? Ch-- wait what?? For those playing the home game: Reddit Idiot posted:As I stated in an earlier lesson, any time you are working with any type of data more complex than a single variable of a given data type, you are working with a pointer. Granted, this is probably just lovely phrasing, but why would you read a tutorial with such lovely phrasing to begin with? TheGopher posted:I know basic C concepts. Stuff like pointers, arrays, defining classes, typecasting, etc. https://www.youtube.com/watch?v=0WhuikFY1Pg TheGopher posted:The resources I've looked at read like a 5th grader's explanation of fractions, or read like any unix "man" entry. That is what I meant by "too technical" or "poorly written". I want something in between, something I can follow with a reasonable amount of effort. Go program. (This is the serious part of my post. Listen to it.) Avenging Dentist fucked around with this message at 01:51 on Apr 19, 2010 |
# ? Apr 19, 2010 01:48 |
|
TheGopher posted:I know basic C concepts. Stuff like pointers, arrays, defining classes, typecasting, etc. Basic stuff. I have no idea where to go from here. To be clear, C is the only language I'm familiar with. I could probably get to the same point with another language with minimal effort because I really understand what I've been taught. Okay. If I asked you to make a stack datatype in C, would you be able to do it? How about a binary search tree? I don't know what you mean by methodology, but it seems to me like it would be inefficient to continue progressing only knowing C. I'm not sure whether to say, "Learn C++, and go with that for a while," or to say "Learn Python, and go with that for a while." I think right now you need some general experience in two areas: dealing with data structures, and writing useful programs that don't just talk on standard I/O. I get the feeling that Python will be quicker to learn and get you there faster, and when you go to C++ later, you'll progress through it more quickly. That's because there are far fewer landmines in Python than in C++. I feel it's better to learn C++ in the context of knowledge and experience that one would have, having used garbage collected, dynamically typed languages, such as Python.
|
# ? Apr 19, 2010 01:53 |
|
Avenging Dentist posted:troll post So all I got out of your post is: A) The lessons I went through are lovely B) I didn't explain myself properly, and I should have C) Explaining myself warrants a sesame st. video to boost your ego because you think I'm being self-congratulatory D) Programming more will solve my problems. If I'm learning from a lovely resource, how is doing more programming going to teach me to be a better programmer? While you're getting off on being so smart and being such a great programmer maybe you could actually help me instead of trying to troll me out of this topic for not knowing enough. Between those two posts, all I've found out is that I'm doing it wrong and I should go bash my head against a concrete wall until I figure it out. I thought the point of this topic was to ask questions and get answers and not get trolled to hell and back.
|
# ? Apr 19, 2010 01:57 |
|
shrughes posted:Okay. If I asked you to make a stack datatype in C, would you be able to do it? How about a binary search tree? Yeah I have no idea how do do either of those first two things. So if Python is a good starting point, what lessons or site do you recommend I use to get the most out of my time investment?
|
# ? Apr 19, 2010 02:00 |
|
So, I think it's worth pointing out that "I want to become better at programming" is pretty much orthogonal to "what do I need to do to be able to make a mod". Growing up, I was in the latter camp, and never really enjoyed programming because I always bit off far more than I could ever chew, and only in order to serve some end rather than for the pleasure of actually doing it. Having trouble with VS2010's debugger? Play around with it! You'll learn a hell of a lot in the process. Is some piece of documentation too dense? Take a step back, branch off and figure out what it's talking about one unfamiliar term at a time. These digressions (which may send you off off a totally different adventure) are how you get stronger. TheGopher posted:The fact you'll bash him just because he's a Redditor without even reading what he's written really says a lot. edit: also, a valuable CoC guideline is "AD can be blunt but he's often right, so it's best to listen to what he says instead of summarily rejecting it because he doesn't mince words". Dijkstracula fucked around with this message at 02:04 on Apr 19, 2010 |
# ? Apr 19, 2010 02:01 |
|
TheGopher posted:If I'm learning from a lovely resource, how is doing more programming going to teach me to be a better programmer? While you're getting off on being so smart and being such a great programmer maybe you could actually help me instead of trying to troll me out of this topic for not knowing enough. Do you want to know how I and nearly everyone in this subforum learned to program? We programmed. Period. There's no magic elixir, no spellbook that just grants you the skills derived from actual experience. Stop expecting that something like this exists. By the time you know enough to benefit from halfway decent resources you will already know where they are. Go. Figure out some stuff you want to program. Try to do it. Fail. Learn from your failures. Repeat. Programming is hard work, but the process by which you learn is not complicated.
|
# ? Apr 19, 2010 02:03 |
|
Edit: Just listen to what AD said. I've decided to start trolling you instead of being helpful.TheGopher posted:So all I got out of your post is: They are. I remember when he first decided to make that subreddit. He didn't know anything. It's a noob trying to write a programming tutorial, with no perspective of what's important. And so it goes. quote:B) I didn't explain myself properly, and I should have quote:C) Explaining myself warrants a sesame st. video to boost your ego because you think I'm being self-congratulatory You said "defining classes." There's no such thing as classes in C. Hence the cookie monster song. quote:D) Programming more will solve my problems. That's right. You get better at programming by programming more. quote:If I'm learning from a lovely resource, how is doing more programming going to teach me to be a better programmer? Experience. quote:While you're getting off on being so smart and being such a great programmer maybe you could actually help me instead of trying to troll me out of this topic for not knowing enough. He's not trolling. quote:Between those two posts, all I've found out is that I'm doing it wrong and I should go bash my head against a concrete wall until I figure it out. That's pretty much how learning works. If you want to know X, find something that explains X. If it doesn't make sense, it's because it uses information you don't understand. So ask what you don't understand, and then learn that. If you want to learn about a whole general topic, there's the problem of known unknowns versus unknown unknowns. The problem with CarlH's tutorials are the unknown unknowns that CarlH is basically ignorant of. Guides that walk you through things are helpful for the unknown unknowns, and reference documentation will help you with the known unknowns. Here's the man page for strlen. What is too technical about this manpage? code:
code:
quote:I thought the point of this topic was to ask questions and get answers and not get trolled to hell and back. Nobody's trolling you.
|
# ? Apr 19, 2010 02:09 |
|
TheGopher posted:So if Python is a good starting point, what lessons or site do you recommend I use to get the most out of my time investment? http://python.org/download/
|
# ? Apr 19, 2010 02:25 |
|
Also, I've always had great help in the Python megathread/ (also also, let me reiterate that thinking about learning how to program in terms of "time investments" is going to ultimately leave you a bitter, twisted, unhappy person.)
|
# ? Apr 19, 2010 02:30 |
|
Here's what I learned from reading reddit for a couple of months: To stop reading reddit.
|
# ? Apr 19, 2010 02:50 |
|
Mustach posted:Here's what I learned from reading reddit for a couple of months: To stop reading reddit. Sometimes being right isn't everything, otherwise I'd read SomethingAwful all the time.
|
# ? Apr 19, 2010 02:56 |
|
TheGopher posted:Sometimes being right isn't everything, otherwise I'd read SomethingAwful all the time. CoC doesn't help your ego, but it does help your programming. Have a thicker skin, you're getting some good advice here.
|
# ? Apr 19, 2010 04:15 |
|
Lets say i have a random set of 40->50 points x,y points. Distributed throughout the screen. Is there an easy way to split this single group of points into two distinct node sets?
|
# ? Apr 19, 2010 05:14 |
|
|
# ? May 18, 2024 10:56 |
|
UberJumper posted:Lets say i have a random set of 40->50 points x,y points. Distributed throughout the screen. Yep. Declare node set A to be the set of all the points you have, and set B to be the empty set. Edit: If it's not obvious, you need to better explain how you want to split the group, and consequently what problem you are actually trying to solve. Splitting a group of things into two groups of things is so trivial that you aren't likely to get a useful answer out of us without some more information. ShoulderDaemon fucked around with this message at 05:47 on Apr 19, 2010 |
# ? Apr 19, 2010 05:20 |