|
N.Z.'s Champion posted:This is probably a stupid question but lets say that I've got variables A and B... is there a way to swap their values without using a third variable (Eg, C = A, A = B, B = C) and without meddling with pointers? Do you guys go to the same school?
|
# ? Aug 25, 2008 23:15 |
|
|
# ? May 15, 2024 04:05 |
|
Scaevolus posted:Do you guys go to the same school? Heh, I was just looking at a min/max check where the user was giving the values in the wrong order and so I wanted to swap them if A > B. It's a coincidence and I wasn't following this thread. Sorry everyone for the derail. I'm a loving idiot. N.Z.'s Champion fucked around with this message at 23:28 on Aug 25, 2008 |
# ? Aug 25, 2008 23:23 |
|
Also, why is everyone afraid of these mysterious "temporary variables"?
|
# ? Aug 25, 2008 23:50 |
|
Ugg boots posted:Also, why is everyone afraid of these mysterious "temporary variables"? I guess it just sounds like an easy optimisation that could result in shorter/clearer code. Is it not?
|
# ? Aug 26, 2008 00:12 |
|
N.Z.'s Champion posted:I guess it just sounds like an easy optimisation that could result in shorter/clearer code. Is it not? Could it make your code shorter? Possibly, but this is sometimes in conflict with making it clearer. Could it make your code clearer? Many optimizations don't, and since you don't know how this would be done, it's difficult for you to say. The XOR trick probably works in more languages than tuple-unpacking in Python, but it has a significant effect on code clarity (what the gently caress are all of these ^=s doing in my code), and as an optimization it's fairly negligible.
|
# ? Aug 26, 2008 00:17 |
|
Using a few extra bytes for a temporary variable is almost certainly going to be both clearer and faster than a "clever" xor trick.
|
# ? Aug 26, 2008 00:35 |
|
I'm not a clever illegible hacks kind of programmer, and I'm already well convinced about the value of readable code. The Python unpacking technique seems to be better in almost all ways though. That's the kind of thing I was after, thanks N.Z.'s Champion fucked around with this message at 00:49 on Aug 26, 2008 |
# ? Aug 26, 2008 00:45 |
|
N.Z.'s Champion posted:So unpacking tuples works in Python, but can this be done in PHP? code:
|
# ? Aug 26, 2008 10:59 |
|
Stupid question, I am using ASP and SQL to make a recursive subroutine, at the end it calls itself like this SubroutineName(Value), it works and the code iterates as long as is needed, but I'd like to carry more info over the next iteration than just the value of the parentID, I'd also like it's parents parentID, like eh, grandparentID. How do I add more values because just doing SubroutineName(Value1,Value2) doesn't work but says "Cannot use parentheses when calling a Sub", so yeah I'm not sure how to proceed here, I've learned coding this stuff via trial & error mostly so I bet am missing some simple piece of info here on how to properly work with values in subroutines. EDIT: stupidly easy answer: SubRoutineName(value1),(value2) His Divine Shadow fucked around with this message at 14:04 on Aug 26, 2008 |
# ? Aug 26, 2008 13:55 |
|
Incoherence posted:The XOR trick probably works in more languages than tuple-unpacking in Python, but it has a significant effect on code clarity (what the gently caress are all of these ^=s doing in my code), and as an optimization it's fairly negligible. If everyone knows about the trick then how does that make it unreadable. I think a comment like this would do just fine. code:
|
# ? Aug 26, 2008 15:42 |
|
Incoherence posted:The XOR trick probably works in more languages than tuple-unpacking in Python, but it has a significant effect on code clarity (what the gently caress are all of these ^=s doing in my code), and as an optimization it's fairly negligible. The XOR trick is not an optimization, it's a trick. On modern CPUs it's actually slower because of pipelining. It's a "clever" trick undergrads show off to their friends. swap_xor.c: code:
code:
code:
|
# ? Aug 26, 2008 16:24 |
|
more falafel please posted:The XOR trick is not an optimization, it's a trick. I did this to annoy my tutor in CS1. He retaliated by making me explain it to the rest of the group. The group who were told to chant "public static void main" as he had abandoned all hope of getting them to be able more than one question.
|
# ? Aug 26, 2008 16:30 |
|
tef posted:He retaliated by making me explain it to the rest of the group.
|
# ? Aug 26, 2008 16:34 |
|
Scaevolus posted:How long did it take for them to understand the binary representation of integers? A while, or at least they were good at nodding. Suprisingly enough from first principles most of them were able to follow the explanation -- although I doubt much of it made it's way into their memory. On the other hand, chanting "public static void main" is going to stay with me for a while.
|
# ? Aug 26, 2008 16:38 |
|
more falafel please posted:The XOR trick is not an optimization, it's a trick. On modern CPUs it's actually slower because of pipelining. It's a "clever" trick undergrads show off to their friends. Inline the function and don't use pointers. See if there's still a difference. On the functions you wrote, xor is doing 3 loads and 3 stores, assign is doing 2 loads, 2 stores, and using an extra register. The difference in speed is because of the loads/stores, not 'pipelining'. mov and xor will get through exactly the same.
|
# ? Aug 26, 2008 21:33 |
|
JawnV6 posted:Inline the function and don't use pointers. See if there's still a difference. Making the swap function static will probably cause it to be inlined, if it's not already. Edit: It's probably best to show the optimized generated assembly, instead of speculating as to what the compiler did. floWenoL fucked around with this message at 21:42 on Aug 26, 2008 |
# ? Aug 26, 2008 21:40 |
|
edit: so apparently it completely optimized out the variables it was swapping, because they never did anything
Scaevolus fucked around with this message at 22:18 on Aug 26, 2008 |
# ? Aug 26, 2008 21:54 |
|
Scaevolus posted:-O3 yields the same assembly, and -O uses "movl $0, %eax" instead of "xorl %eax, %eax".
|
# ? Aug 26, 2008 22:04 |
|
inlined, no pointers:code:
code:
code:
edit: partially beaten, mine has the unoptimized assembly
|
# ? Aug 26, 2008 22:11 |
|
more falafel please posted:edit: partially beaten, mine has the unoptimized assembly edit: gently caress Scaevolus fucked around with this message at 22:18 on Aug 26, 2008 |
# ? Aug 26, 2008 22:14 |
|
JawnV6 posted:Ugh what a stupid unreadable hack to zero out a register. I despise this 'xor trick' I used to use xor a on the Z80 because it was only 1 byte and like 2 cycles whereas the immediate move was 2 bytes and like 5 cycles or something. But to be fair that was the Z80.
|
# ? Aug 26, 2008 22:14 |
|
Scaevolus posted:s/partially/completely/; no one cares about unoptimized assembly, the whole point is for it to be savage
|
# ? Aug 26, 2008 22:15 |
|
Scaevolus posted:s/partially/completely/; no one cares about unoptimized assembly, the whole point is for it to be savage It's only 'savage' because it optimized out the swaps altogether :pwn; Triple post woo
|
# ? Aug 26, 2008 22:17 |
|
more falafel please posted:I used to use xor a on the Z80 because it was only 1 byte and like 2 cycles whereas the immediate move was 2 bytes and like 5 cycles or something. On EMT64 (lol) using the 64 bit xor takes an extra byte, the 32 bit xor will zero the upper half of the register anyway
|
# ? Aug 26, 2008 22:29 |
|
Okay, this is how you do the benchmark. First you post the code, making sure to put something in to prevent the compiler from optimizing the whole thing out:code:
code:
code:
code:
code:
code:
floWenoL fucked around with this message at 00:02 on Aug 27, 2008 |
# ? Aug 26, 2008 23:53 |
|
floWenoL posted:Okay, this is how you do the benchmark. First you post the code, making sure to put something in to prevent the compiler from optimizing the whole thing out: Ok, but I think my point still stands, the compiler optimizes out the xor trick because it's not actually an optimization.
|
# ? Aug 27, 2008 00:56 |
|
more falafel please posted:Ok, but I think my point still stands, the compiler optimizes out the xor trick because it's not actually an optimization. Yeah, it's inconclusive. I'd test the xor trick in assembly but . Also, I wonder if gcc actually detects the xor trick or if it just falls out of the data flow analysis.
|
# ? Aug 27, 2008 01:00 |
|
More simple .NET-related questions: Edit: moving these to the .NET thread, if they're not already answered there. minidracula fucked around with this message at 02:24 on Aug 27, 2008 |
# ? Aug 27, 2008 01:48 |
|
mnd posted:More simple .NET-related questions: We have a megathread for .NET, please use it
|
# ? Aug 27, 2008 02:02 |
|
Anyone here done any procedurally generated maps and the like? I want to write some code to procedurally generate a world from the depths of the ocean upward, and I'm looking for a mysterious code ninja to point me in the right direction. I have never done any procedurally generated coding.
|
# ? Aug 27, 2008 04:00 |
|
Arconom posted:Anyone here done any procedurally generated maps and the like? I want to write some code to procedurally generate a world from the depths of the ocean upward, and I'm looking for a mysterious code ninja to point me in the right direction. I have never done any procedurally generated coding.
|
# ? Aug 27, 2008 18:15 |
|
Arconom posted:Anyone here done any procedurally generated maps and the like? I want to write some code to procedurally generate a world from the depths of the ocean upward, and I'm looking for a mysterious code ninja to point me in the right direction. I have never done any procedurally generated coding. This book is pretty awesome: Texturing & Modeling: A Procedural Approach. A lot of the stuff in it isn't necessarily intended for real-time rendering but can be adapted for it, or be used to generate static resources to distribute with your app.
|
# ? Aug 27, 2008 18:33 |
|
Those articles on world building are exactly what I'm looking for. Now I have to learn how to somehow integrate the procedural generation with genetic algorithms to produce ideal results. Ugh. What a tedious hobby.
|
# ? Aug 27, 2008 19:15 |
|
I'm casting about looking for a suitable cross-platform installer. That is, I have some commandline programs to distribute, that have to be installed by non-technical types, and I'd rather work with a single installer type / product, even if I'll have to produce different installers for each platform. Of course, the best examples are commercial and expensive (InstallAnywhere, InstallBuilder etc.) or don't support Macs. izPack looked good, but doesn't seem to have any support for installs that require permissions. That is, if the user wants to install into /usr/local/bin, izPack just complains it can't write to that directory, rather than asking for credentials. (The release refers to a feature called "SudoPanel", but it's completely undocumented.) I've also looked as vainstall, Openjinstaller, jexpress, Advanced installer, Install4J, INstallJammer, Liftoff, Mini, and Innosetup. (Undocumented and buggy, no Mac version & still in dev, commercial, Windows based, Mac support "coming" ...) Any other suggestions, or an I fresh out of luck?
|
# ? Aug 29, 2008 11:29 |
|
outlier posted:I'm casting about looking for a suitable cross-platform installer Mac applications tend to come stand alone - you drag Application.app into /Applications Installers aren't very popular.
|
# ? Aug 29, 2008 12:16 |
|
tef posted:Mac applications tend to come stand alone - you drag Application.app into /Applications outlier posted:I have some commandline programs to distribute, that have to be installed by non-technical types An installer is needed. I can't ask people to drag a binary into /usr/local/bin.
|
# ? Aug 29, 2008 13:09 |
|
On a complete aside: If you are curious about joel atwood and jeff spolsky's latest adventure 'stackoverflow', but not enough of a rockstar to get in the beta, fear not: Go to: http://beta.stackoverflow.com Change your cookies - type this into the address bar: javascript:alert(document.cookie="soba=-9999999"); (any big negative number seems to work) And then go back to: http://beta.stackoverflow.com and refresh! Volia! tef fucked around with this message at 17:57 on Aug 29, 2008 |
# ? Aug 29, 2008 16:55 |
|
tef posted:On a complete aside: Hahahahahahaahahahahahahahahahahahaha I don't know what else to say (other than you typoed the links.)
|
# ? Aug 29, 2008 17:30 |
|
Hah oh god that worked like a charm. I read Jeff Atwood's blog all the time, but I'm starting to think he's not as good as I first thought!
|
# ? Aug 29, 2008 17:33 |
|
|
# ? May 15, 2024 04:05 |
|
Stephen posted:Hah oh god that worked like a charm. I read Jeff Atwood's blog all the time, but I'm starting to think he's not as good as I first thought! Ugh, now I started posting on StackOverflow. It's not bad, but they're going to want to make a better "front page" because just listing off a bunch of seemingly random questions is kind of a clusterfuck. I like the achievement style badges Edit: What the gently caress does reputation represent? Is there some sort of formula based on badges and tags and stuff? Edit 2: Found the formula. POKEMAN SAM fucked around with this message at 19:21 on Aug 29, 2008 |
# ? Aug 29, 2008 17:44 |