|
Evil_Greven posted:I hate this: I feel kind of lost. For the purpose the comment is talking about, this should be int64_t instead of int, just to be sure, right? But then for this purpose, just do if (0 < x), because for unsigned that's equivalent to if (0 != x)? Even if something 64-bitish is happening with y later, you could do the conversion inside the if segment instead of before the conditional.
|
# ? Aug 6, 2022 04:32 |
|
|
# ? May 28, 2024 15:26 |
|
You need a really unusual target for int to be 64 bits, because it would mean you didn’t have a standard integer type for at least one of 8/16/32 bits. That’s the sort of poo poo you see on some obscure Cray from the 90’s, probably with a note like “Cray changed this for the next series because of customer complaints that it was too difficult to program.” If int were 64 bits, the code would work; promoting an unsigned type to a wider signed type is value-preserving.
|
# ? Aug 6, 2022 04:49 |
|
int64_t would have been a safer option. They were using the int for some bit shifting and such, and that's not so safe:C++ code:
code:
Evil_Greven fucked around with this message at 05:18 on Aug 6, 2022 |
# ? Aug 6, 2022 04:50 |
|
AFAIK a recently (2019) retired supercomputer also used 64 bit wide plain ints. But in the common case, expecting plain int to be 64 bits is one of those "do you even C++ bro?" things.
|
# ? Aug 6, 2022 09:54 |
|
I only use plain int when the width isn't even something I'm thinking about. If I make a conscious decision that 32 bits is the correct size, I'll call it int32_t
|
# ? Aug 6, 2022 10:02 |
|
Anyway, the real horror is Go. We have a C++ library with Go bindings. One of the things you can ask for is to serialize some internal data structures with precomputed data, so that you can reuse the computations across runs, thus saving time. We naively implemented this using C.GoBytes helper, which you feed a ptr+size pair and it gives you a byte slice that's copy of the data. This worked, until recently, when we got a bug report from external team about the serialization panicking. Turns out, while we properly use size_t type for the size info in C, GoBytes uses C.int. Which is 32 bits (see last few posts), and is signed, thus overflows.
|
# ? Aug 6, 2022 10:11 |
|
Evil_Greven posted:I hate this: How do I know that's not 32 bit unsigned to 32 bit signed?
|
# ? Aug 6, 2022 13:08 |
|
Because it's 32 bit unsigned to a signed type of at least 16 bits
|
# ? Aug 6, 2022 13:25 |
|
I'm not a JS/TS developer, but surely there's a better way.JavaScript code:
|
# ? Aug 6, 2022 15:13 |
|
I think there's an NPM package for that.
|
# ? Aug 6, 2022 15:14 |
|
There's no built-in way to do string formatting? I should add, index is originally an int, and the caller line is JavaScript code:
|
# ? Aug 6, 2022 15:17 |
|
It's a joke about NPM.
|
# ? Aug 6, 2022 15:42 |
|
The non-joke answer is padStart. Also, you can keep "index" as a "number" instead of a "string", it's automatically converted to a string when printed or interpolated.
|
# ? Aug 6, 2022 15:42 |
Deffon posted:The non-joke answer is padStart. But that doesn't work in Internet Explorer!
|
|
# ? Aug 6, 2022 15:54 |
|
nielsm posted:But that doesn't work in Internet Explorer! Luckily the article has a pollyfill! (It's actually slightly more complicated than it seems since it supports multi-char padding and might need to truncate that).
|
# ? Aug 6, 2022 15:57 |
|
Deffon posted:Also, you can keep "index" as a "number" instead of a "string", it's automatically converted to a string when printed or interpolated. But then you don’t know how many characters it is post-conversion. Although I suppose you can padStart based on the length of the entire string.
|
# ? Aug 6, 2022 16:02 |
|
Dross posted:But then you don’t know how many characters it is post-conversion. Although I suppose you can padStart based on the length of the entire string. You don't need the length of the string, the resulting zero-padded number should always be 5 digits according to the code. Forgot that index was supposed to be the thing to call padStart on so an explicit conversion is needed somewhere at least either by the caller or the function. TypeScript code:
|
# ? Aug 6, 2022 16:28 |
|
Deffon posted:The non-joke answer is padStart. That's a really unusual name for the "add N characters to the left of this string" function. I wonder why they couldn't choose a more standard one?
|
# ? Aug 6, 2022 16:57 |
|
Deffon posted:You don't need the length of the string, the resulting zero-padded number should always be 5 digits according to the code. Yeah, if I were writing it I would do that transformation separately and explicitly even though I don’t use typescript, but you mentioned just coercing it to a string implicitly by interpolating it which is what I was responding to
|
# ? Aug 6, 2022 17:26 |
|
NihilCredo posted:That's a really unusual name for the "add N characters to the left of this string" function. I wonder why they couldn't choose a more standard one? "pad" is standard vernacular for "append data to the leading and/or trailing edge of some other data". Other terms like "fill" are used sometimes but "pad" is probably the one I most commonly see
|
# ? Aug 6, 2022 18:40 |
|
QuarkJets posted:"pad" is standard vernacular for "append data to the leading and/or trailing edge of some other data". Other terms like "fill" are used sometimes but "pad" is probably the one I most commonly see (it was a left-pad joke)
|
# ? Aug 6, 2022 18:49 |
|
I guess someone showed up wearing a Unicode hat and informed people that not all scripts go left-to-right.
|
# ? Aug 6, 2022 20:09 |
|
Naming stuff in JavaScript is sometimes hard because there are popular third-party libraries which add functionality which the language designers themselves then later decide to add.
|
# ? Aug 6, 2022 20:37 |
|
If only you could design language in a way where you can tell where the symbol comes from. You could then group names into spaces based on their origin.
|
# ? Aug 7, 2022 10:10 |
|
That’s not quite enough, because people want to add methods that extend existing data types. Like, extending methods. Extendy methods. Something like that.
|
# ? Aug 7, 2022 11:13 |
|
Soricidus posted:That’s not quite enough, because people want to add methods that extend existing data types. Like, extending methods. Extendy methods. Something like that. Just use a function pointer, sounds like what you're after.
|
# ? Aug 7, 2022 14:21 |
|
Xarn was making a joke about namespaces existing. Or, the extra layers of joke indirections in this thread have overflowed my mental stack.
|
# ? Aug 8, 2022 18:16 |
|
Sounds like you should store your jokes on the heap, like I store all my posts
|
# ? Aug 8, 2022 18:22 |
|
a heap of dung
|
# ? Aug 8, 2022 19:55 |
|
And a stack of bodies
|
# ? Aug 8, 2022 20:15 |
|
https://twitter.com/t3dotgg/status/1557987235642822656
|
# ? Aug 13, 2022 06:36 |
|
Someone jokingly suggested yoink and yeet for Swift's upcoming ownership modifiers, so there's a chance!
|
# ? Aug 13, 2022 14:02 |
|
pokeyman posted:Someone jokingly suggested yoink and yeet for Swift's upcoming ownership modifiers, so there's a chance!
|
# ? Aug 13, 2022 14:38 |
|
pokeyman posted:Someone jokingly suggested yoink and yeet for Swift's upcoming ownership modifiers, so there's a chance! I would genuinely be pleased if someone aliased those to new and delete in a codebase I had to touch.
|
# ? Aug 13, 2022 22:08 |
|
code:
|
# ? Aug 15, 2022 21:35 |
|
Fun fact, VB.NET is about old enough to drink in the United States
|
# ? Aug 15, 2022 21:45 |
|
Bruce Hussein Daddy posted:
In VB.NET Booleans convert to -1 for True and 0 for False, and any non-zero value converts to True as a boolean, so basically this is a horror way of writing code:
|
# ? Aug 15, 2022 22:39 |
|
Bruce Hussein Daddy posted:
I'll make the safe bet and say it's life sciences.
|
# ? Aug 16, 2022 21:34 |
|
code:
|
# ? Aug 16, 2022 22:49 |
|
|
# ? May 28, 2024 15:26 |
|
Beef posted:I'll make the safe bet and say it's life sciences. oooh I would've gone boomer electrical engineer
|
# ? Aug 16, 2022 22:57 |