|
It really is a FuckedString, btw. It uses the dereference operator (prefix *) as a conversion to a const TCHAR* (not to be confused with the previously discussed Windows TCHAR, nor the many T-prefixed template classes), but also, it uses the multiply operator (infix *) for treating the string as a path and appending a path separator (a global #define) between the two strings that are... multiplied. It's horrific by itself, but like... they could have at least used the division operator for that. Oh yeah, and all the comparisons are done by using **this (to get the TCHAR*) then sending it to stricmp Always case insensitive, never checks that the string lengths even match, has to null-terminate the strings to compare them.
|
# ? Jun 28, 2018 14:46 |
|
|
# ? May 31, 2024 00:53 |
|
Mooey Cow posted:Still haven't figured out what the christ the "F" prefix means. "hosed"? Based on the context I'd say the F is for Force.
|
# ? Jun 28, 2018 14:47 |
|
certainly a solution to finding if a number is prime (the array goes to 49999)
|
# ? Jun 28, 2018 17:55 |
|
I know it’s wrong. But I love it. It’s pragmatic. Interviewer: We need to find out if a number is a prime” Dev: How big do our numbers go, and do we need a gofast solution? I: 50k, and sure. D: ok, here. It solves the problem. It’d be better if it knew its constraints and hard errored on >50k. The counterpoint are companies that want everything for twitter scale. “How would you design this?” Uh, web server and Postgres, you told me you hit 1 concurrent user. Revisit it when it’s proven itself to be making money, and beyond the scale of its implementation.
|
# ? Jun 28, 2018 18:34 |
|
Wait, negative numbers aren't prime, though, are they?
|
# ? Jun 28, 2018 18:41 |
|
streetlamp posted:certainly a solution to finding if a number is prime No hire. Should have just had return primes.indexOf(Math.abs(num)) !== -1 instead of that if block...
|
# ? Jun 28, 2018 18:42 |
|
Should have used a bool array of 50k items so you can do an O(1) index operation instead of an O(n) indexOf.
|
# ? Jun 28, 2018 18:48 |
|
streetlamp posted:certainly a solution to finding if a number is prime
|
# ? Jun 28, 2018 18:56 |
|
streetlamp posted:certainly a solution to finding if a number is prime Well, we all remember the classic "check if an integer is a perfect number", right? code:
|
# ? Jun 28, 2018 19:10 |
|
Not checking but I'd love if one of those values was wrong. Hours of fun for everyone!
|
# ? Jun 28, 2018 19:30 |
|
dwazegek posted:Should have used a bool array of 50k items so you can do an O(1) index operation instead of an O(n) indexOf. I know you're joking, but unironically it should have been either a hash table or at least a binary search. Precomputing answers isn't necessarily a bad idea depending on the use case, but there's no reason not to make the search more efficient.
|
# ? Jun 28, 2018 19:46 |
|
Mad Jaqk posted:there's no reason not to make the search more efficient. It's often completely pointless to spend time making something more efficient.
|
# ? Jun 28, 2018 21:52 |
|
Mad Jaqk posted:I know you're joking, but unironically it should have been either a hash table or at least a binary search. Precomputing answers isn't necessarily a bad idea depending on the use case, but there's no reason not to make the search more efficient. Linear searches under 1k items are usually faster than binary or hash table searches.
|
# ? Jun 28, 2018 22:03 |
|
Lumpy posted:No hire. Should have just had return primes.indexOf(Math.abs(num)) !== -1 instead of that if block... Should have had return ~primes.indexOf(Math.abs(num))
|
# ? Jun 28, 2018 22:52 |
|
A bit-vector would be way more efficient in both space and time. Primes are dense at approximately 1 / ln(N), so an array of the primes up to N will have N / ln(N) elements of size log2(N) bits each. There is no N for which N * log2(N) / ln(N) = N * log2(e) is less than N, and that's imagining an optimal bit-packing of the array elements.
rjmccall fucked around with this message at 23:11 on Jun 28, 2018 |
# ? Jun 28, 2018 22:59 |
|
If you use a bit vector, also special case 2 so you can map every N to (N - 1) / 2 and save half the space. You could also take an example from database bitmap indices and compress the vector, letting the compressor figure out that every other bit is 0.
|
# ? Jun 28, 2018 23:43 |
|
Hammerite posted:It's often completely pointless to spend time making something more efficient. Computers are now vastly cheaper than developers in all but the most exceptional of circumstances.
|
# ? Jun 29, 2018 04:15 |
|
repiv posted:F was indeed originally for float: https://forums.unrealengine.com/dev...ructs-stand-for A common misconception. The 'F' is for "Fother"
|
# ? Jun 29, 2018 04:38 |
|
bad post
xtal fucked around with this message at 12:52 on Jun 29, 2018 |
# ? Jun 29, 2018 04:39 |
|
CPColin posted:Wait, negative numbers aren't prime, though, are they? Primes are defined as integers greater than 1 in context of the fundamental theorem of arithmetic, which says that every number > 1 is either prime or can be stated as a product of prime numbers, and that this representation is unique up to the order of the factors. The reason 1 isn't considered a prime number is because if it were, then there wouldn't be a unique representation of prime factors - e.g. if 1 were prime, then 2 could be factored as 2 * 1, 2 * 1 * 1, 2 * 1 * 1, 2 * 1 * 1 * 1. Similarly, if negative numbers were considered prime, then there wouldn't be a unique representation of the factors (e.g. 4 could be 2 * 2, or -2 * -2.)
|
# ? Jun 29, 2018 14:05 |
|
Right, so why is that code taking the absolute value of its input?
|
# ? Jun 29, 2018 14:33 |
|
xtal posted:Should have had return ~primes.indexOf(Math.abs(num)) TIL about the JavaScript bitwise NOT operator. I'll have to put that up on the shelf right next to writing my own sort implementation.
|
# ? Jun 29, 2018 15:23 |
|
Hammerite posted:It's often completely pointless to spend time making something more efficient. this attitude is why electron exists
|
# ? Jun 29, 2018 15:40 |
|
Months ago, I implemented a clever hack to get around a stupid problem. It came with a stern warning that they should fix the actual problem. The clever hack is now considered a "standard" that they copy and paste constantly. I knew it would happen, but I was hoping I'd be surprised for once.
|
# ? Jun 29, 2018 16:08 |
|
Taffer posted:this attitude is why electron exists Unquestioningly applying the principle that "things should be as efficient as possible" might lead us to devote time to making things efficient whose inefficiency is benign, whereas assuming inefficiency never matters might lead us to create software that is much slower and less responsive than it needs to be. It's almost as though there is a need to apply critical thought and to identify when it's worthwhile spending time making things more efficient, and when it isn't.
|
# ? Jun 29, 2018 16:46 |
|
Hammerite posted:It's almost as though there is a need to apply critical thought and to identify when it's worthwhile spending time making things more efficient, and when it isn't. The issue is that people are often unable to identify which is which, or worse, are forced into a situation where they are fundamentally unable to optimize due to poor optimization choices by those who have come before them. See: the entire javascript ecosystem.
|
# ? Jun 29, 2018 16:50 |
|
Going too far either way is equally bad.
|
# ? Jun 29, 2018 17:05 |
|
Taffer posted:The issue is that people are often unable to identify which is which, or worse, are forced into a situation where they are fundamentally unable to optimize due to poor optimization choices by those who have come before them. See: the entire javascript ecosystem. There's also the well established programming culture of being very loud and rude about others' suboptimal code, which quickly whips juniors into hyper-optimizing every tiny thing.
|
# ? Jun 29, 2018 17:06 |
|
If you can't write things in an efficient way the first time, the solution is not optimizing your poorly written code, it's solidifying ideas and rewriting from fundamental concepts. Just throw poo poo out more imo, developers get too infatuated with their abstractions. Anyways thats not how it works at a job, so use pprof and keep eating those low hanging fruits to sustain your salary or w/e.
|
# ? Jun 29, 2018 17:47 |
|
As tef says: write code thats easy to delete.
|
# ? Jun 29, 2018 17:55 |
|
good job on the optimizations mods... we got this argument down to around 10 posts this time. still doesn't meet our metrics though, let's shoot for 3 posts next time.
|
# ? Jun 29, 2018 18:14 |
|
Let's write a unit test that fails when the task doesn't complete in time. Better set the limit to 10x what's normal, so we don't get spurious failures.
|
# ? Jun 29, 2018 18:19 |
|
efficiency: good or bad? The Something Awful goons will get to the bottom of it
|
# ? Jun 29, 2018 19:22 |
|
it's like knuth said: "all optimization is worse than the most depraved murder. if you optimize you should go to jail forever"
|
# ? Jun 29, 2018 19:34 |
|
Jeb Bush 2012 posted:it's like knuth said: "all optimization is worse than the most depraved murder. if you optimize you should go to jail forever" I prefer his aphorism, “goto is the highest expression of the love of Christ the redeemer and to use other flow control constructs is the work of Satan”
|
# ? Jun 29, 2018 19:37 |
|
We implemented a caching layer a few years ago. Certain things got cached. Now, let's leave aside that there are actually like four or five ways one set of data is cached; this is because our code has no standards and everyone uses this data differently. That's a pain but not the end of the world. Legacy code! No, what's bad is that there were pairs of functions written, get and set. There were several of these pairs, but they all worked the same way. Python code:
Python code:
I quit ripping my hair out and rewrote this but god, it felt good to eliminate that. Fixed a few weird bugs too.
|
# ? Jun 29, 2018 22:55 |
|
CPColin posted:Right, so why is that code taking the absolute value of its input? oh yeah that. the joke is that javascript developers code defensively because you never know what could happen in javascript.
|
# ? Jun 30, 2018 14:39 |
|
Hammerite posted:Unquestioningly applying the principle that "things should be as efficient as possible" might lead us to devote time to making things efficient whose inefficiency is benign, whereas assuming inefficiency never matters might lead us to create software that is much slower and less responsive than it needs to be. It's almost as though there is a need to apply critical thought and to identify when it's worthwhile spending time making things more efficient, and when it isn't. Critical thought and also measurement.
|
# ? Jun 30, 2018 21:55 |
|
KernelSlanders posted:Computers are now vastly cheaper than developers in all but the most exceptional of circumstances. 'This software by one developer runs on n hundred thousand computers' is also a thing, though.
|
# ? Jun 30, 2018 22:07 |
|
|
# ? May 31, 2024 00:53 |
|
https://twitter.com/troyhunt/status/1013305478175080448
|
# ? Jul 1, 2018 14:11 |