|
zootm posted:I think either some spacing or avoiding the ternary operation altogether would make the "after" code in that example a lot easier to read, JingleBells. code:
|
# ¿ Apr 10, 2008 14:32 |
|
|
# ¿ Apr 24, 2024 11:11 |
|
MasterSlowPoke posted:the language is stackless python, definitions cut off for brevity It doesn't usually matter too much on self contained mathematical operations like that, because you can prove the correctness of the routine with relatively straightforward regression testing and then leave it alone for years. The most important thing is: does it have the reference to the original paper in the comments?
|
# ¿ Apr 15, 2008 09:26 |
|
JoeNotCharles posted:No, because then you need a whole bit for each individual choice. Once you get past 32 choices it takes more than a word of memory, so it's very space-inefficient. With primes, you can fit 4294967296 different options in a word (well, not that many because not every number is prime, but it's still a hell of a lot more than 32).
|
# ¿ Apr 24, 2008 18:04 |
|
Aredna posted:You could let it overflow and just assume you're doing the math mod 2^32. I haven't looked, but I'd imagine you can go quite a ways before you ran into a collision. Anyone fancy putting the appropriate loading code in and testing?: code:
|
# ¿ Apr 24, 2008 19:27 |
|
Aredna posted:The real question is, what algorithm do you use to decode the number back to base primes? What if you don't know how many or which primes were used other than that they produced no collisions?
|
# ¿ Apr 24, 2008 21:17 |
|
minato posted:Unless you compress the result By my rough calculations, we should be able to store all of the values we're after up to 31610054640417607788145206291543662493274686990, in a little under 33 bits. Then when we want to figure out which values are set, we just multiply up the primes and then factor the number as usual. Job done. minato posted:We're through the looking glass here folks
|
# ¿ Apr 25, 2008 09:24 |
|
floWenoL posted:A simple dataflow analysis pass should enable the compiler to conclude that the copied variable is not used and therefore can be omitted, assuming the copy constructor etc. have no side effects. That's the biggie though, and I'm not sure that's common to a lot of compilers. I'm willing to bet that the same code was generated on each for the vector example because the iterator is a simple typedef to a pointer. What happens with a std::list or std::map?
|
# ¿ May 7, 2008 12:19 |
|
tef posted:They wanted to get rid of warning messages caused by valgrind. tef posted:At this point I think this says it best: EDIT: Yes, I know I've just called Linus Torvalds stupid, but before the usual "Omg, but Linux, waaaaah!" starts up: I don't give a drat what he's done in the past, if he's going to say something stupid then I'll call it stupid. TSDK fucked around with this message at 15:56 on May 13, 2008 |
# ¿ May 13, 2008 15:45 |
|
Smackbilly posted:Well, the admonition not to fix warnings without understanding the code is valid - in fact you shouldn't do anything to code that you don't understand. I also disagree that you need to have a full and complete understanding of anything before coding or bug fixing. Often the only way to get to fully understand systems is when you actually go through it in practice trying to change or implement something. It's also perfectly possible to do an adequate job fixing bugs without understanding all of the surrounding code. Smackbilly posted:For example, consider
|
# ¿ May 13, 2008 16:48 |
|
Mikey-San posted:I think Torvalds means "stupid" in the sense that "it only knows a set of predefined rules". It cannot determine the intent of the programmer, so while it's good at what it does, it can't think. It's "dumb".
|
# ¿ May 13, 2008 17:17 |
|
tef posted:It turns out I'm talking poo poo! 1) Relying on specific, non-guaranteed behaviour from uninitialised memory. 2) Knowing that you get specific warnings about sections of code and failing to comment them appropriately. 3) Making a change to some code you don't fully understand without getting in touch with either the original author, or someone who could explain why it's doing what it is. If you ask me, then the original OpenSSL devs are just as much to blame for that clusterfuck as the guy who put in an incorrect 'fix' for the problem.
|
# ¿ May 14, 2008 10:13 |
|
EssOEss posted:== is generally defined as reference equality, not data equality. Overriding it to perform data comparison would be a Coding Horror. Begone, foul Java demon!
|
# ¿ May 16, 2008 09:08 |
|
Jo posted:Is there a reason someone would write http://aggregate.org/MAGIC/#Is%20Power%20of%202 The second one is testing for an even number, so the tests are not the same.
|
# ¿ Jun 3, 2008 15:33 |
|
In any case, the correct form of the test is:code:
|
# ¿ Jun 4, 2008 09:56 |
|
CeciPipePasPipe posted:Uh, wouldn't *(int*)13 = 3 cause a general protection fault (and possibly a bus error on archs that require aligned memory access), because you're trying to write the value 0x00000003 into memory at location 0x000000D ? I don't see how this has anything to do with interrupt 3. The only disadvantage is that you normally can't hit F5 and continue execution after hitting the latter, as you can with the former. Personally, I use a 'DEBUG_BREAK()' macro which is defined on a per-platform basis.
|
# ¿ Jul 9, 2008 12:30 |
|
CeciPipePasPipe posted:Oh ok, wouldn't it be easier to just do "int breakme=1/0;" or something then?
|
# ¿ Jul 9, 2008 14:16 |
|
Entheogen posted:why couldn't one do this
|
# ¿ Jul 9, 2008 15:05 |
|
Cross_ posted:Ignoring the fact that this betrays bad design- you have to change the type declaration anyway what's the problem with doing search&replace at the same time? Hungarian notation is an old technique that has no place in modern C++ programming, but there are one or two odd exceptions which are either genuinely useful, or are a strange hang-over. The scope of variables is of critical importance in C++, and in OO programming in general. As such, you often see 'g_', 's_' and 'm_' prefixes used widely - or similar conventions for distinguishing member variables. The 'p_' prefix is more of a comfort thing. There's not necessarily any reason why it should be used, but it's a fairly firmly entrenched an widely used habit. It generally doesn't cause as many problems as other types of type prefix though. One of the main arguments against Hungarian is that if you change the type, then you have to hunt out and change everywhere the variable is used for no good reason. Whereas if you change a variable to or from a pointer type, then you will generally have to change all of the places where it's being used anyway, so the negative impact of this particular prefix is relatively light. I've not seen 'r' being used all that often, and I suspect it's a dirty Java habit
|
# ¿ Oct 2, 2008 23:41 |
|
My favourite coding horror side effect of Hungarian notation is little gems like this scattered around here and there:code:
|
# ¿ Oct 3, 2008 11:29 |
|
If he thinks that this:code:
code:
|
# ¿ Nov 20, 2008 18:08 |
|
... and why is a function for reading called 'write' at one point?
|
# ¿ Nov 20, 2008 19:14 |
|
tripwire posted:Ulillillia released the source code for a program he designed in C which converts the sampling rate of PCM wave files. Oh my-o-my. Is that someone on the forums?
|
# ¿ Dec 16, 2008 14:30 |
|
hexadecimal posted:There will never be any other objects other than CVSRevision coming in there. If an object of other types comes through, this will be an error in my program, and will be caught in another place, Then when the thing that should never happen actually does happen, you'll have a head start on tracking it down and fixing the bug.
|
# ¿ Jan 8, 2009 18:31 |
|
Presto posted:Strictly speaking, this:
|
# ¿ Jan 8, 2009 20:47 |
|
I've started seeing this rather sub-optimal anti-pattern in a few places recently:code:
|
# ¿ Jan 27, 2009 21:23 |
|
Otto Skorzeny posted:How many strings are you testing against by the way
|
# ¿ Jan 28, 2009 10:24 |
|
Mill Town posted:Data structure hell, just stuff all the strings into a hash set. 2) They're stricmps, not strcmps, so you'd still need to do some faffing to get the hashing (or sorting if you want to use a std::map) working properly. It's only done once per load, so it's not in a performance critical section, but it is annoying that it'll take longer than it should for want of a few extra keywords. It's sloppy rather than outright terrible.
|
# ¿ Jan 28, 2009 10:57 |
|
ehnus posted:A coworker stumbled across this and forwarded it to me: code:
|
# ¿ Feb 12, 2009 12:44 |
|
Trammel posted:The 'not-invented-here' syndrome strikes again! Mmm, I love me some security.
|
# ¿ Feb 12, 2009 21:49 |
|
quote != edit
|
# ¿ Feb 12, 2009 21:50 |
|
GrumpyDoctor posted:homegrown resizable array that's basically std::vector without bounds checking I know you probably know that, but it is a common myth about the STL.
|
# ¿ Feb 13, 2009 10:35 |
|
Richard Noggin posted:I can certainly understand using descriptive variable names, but you have to be a complete loving moron to require them in loops. Now if you'd have put: code:
|
# ¿ Feb 24, 2009 17:57 |
|
Zombywuf posted:What's you're problem, code:
|
# ¿ Mar 13, 2009 12:18 |
|
Zombywuf posted:I'm assuming the original developer was planning to add more sophisticated code later, like locking, but didn't get the time. Coding for the future can be appropriate, however, there's also a lot to be said for waiting until you have a better idea of what's needed before writing code. That way if you never need it then you've not wasted any time, and if what you actually turn out to need is different to what you thought you'd need, then there's less code that needs changing.
|
# ¿ Mar 13, 2009 14:25 |
|
Mick posted:
|
# ¿ Mar 26, 2009 22:39 |
|
Wheany posted:But also:
|
# ¿ Apr 8, 2009 11:13 |
|
I came across a good one-liner today:code:
|
# ¿ Jun 26, 2009 16:47 |
|
quadreb posted:Hey concurrency, how's it going?
|
# ¿ Jun 30, 2009 18:16 |
|
Vinterstum posted:Something dumb like wanting some of their internal data types to be 16 byte aligned, which the VS STL implementation can't handle (We actually had problems with this at work as well, I remember). Vinterstum posted:Again: Oh, the horror!
|
# ¿ Jul 1, 2009 10:31 |
|
|
# ¿ Apr 24, 2024 11:11 |
|
tef posted:This would explain the response I got to this childish job advert. code:
|
# ¿ Jul 9, 2009 12:14 |