|
fritz posted:Why would anybody do this to themselves : Loop unrolling is a legitimate use case for template metaprogramming. Everything else I've seen just feels like someone showing off how smart they are. Yeah, it's kinda cool that you can get the compiler to print an error message for every prime number less than some value, but who really cares?
|
# ? Sep 28, 2018 19:48 |
|
|
# ? May 21, 2024 06:32 |
|
fritz posted:Why would anybody do this to themselves : https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern Can be very useful once you get used to it.
|
# ? Sep 28, 2018 19:50 |
|
OK, but explain the template parameters to B now.
|
# ? Sep 28, 2018 20:04 |
|
Several developers, team leads, and even a lead architect were in an email chain to figure out how to deal with null values in REST api json responses. I stated my case and referenced the json spec for null. They decided that null values for json fields should be represented by the string "NA" going forward.
|
# ? Sep 28, 2018 20:23 |
|
You should make an addendum to their proposal that if someone really wants a field named x to be the string value "NA" instead of a null value, they should also include a boolean field in the json called x_exists set to true.
|
# ? Sep 28, 2018 20:27 |
|
ultrafilter posted:OK, but explain the template parameters to B now. Both are CRTP. There's not enough there to say whether C's additional parameters are appropriate.
|
# ? Sep 28, 2018 20:28 |
|
More of a computers-are-a-horror but I was recently made aware of the fact that given an initial state ofcode:
code:
code:
code:
|
# ? Sep 28, 2018 20:40 |
|
Loezi posted:More of a computers-are-a-horror but I was recently made aware of the fact that given an initial state of Or perhaps in your expectation of the output of that code, because code like that is fine if you are expecting input from either state and there's a guarantee that the MOV is atomic. edit: There's also the obvious that I overlooked, that registers are thread-local. They'll always be "0" or "whatever they are set to not from your threads" if you create two threads to execute your instructions and then check EAX and EBX from the thread that launched those other threads. I was too caught up on the assembly and parallel execution. If you're reading from the threads given, one of the registers should always be zero because you're not setting it in that thread. The register you are setting will either be 0 or 1. Khorne fucked around with this message at 23:06 on Sep 28, 2018 |
# ? Sep 28, 2018 22:36 |
|
The hardware that met your expectation would be far more horrific.
|
# ? Sep 28, 2018 22:42 |
|
Slash posted:Nice tip! didn't know you could do this in Chrome. This will save me literally milliseconds every day. If you want to save even more milliseconds, instead of moving mouse all the way to address bar, right click and move a few pixels to the "search with google" menu item.
|
# ? Sep 28, 2018 22:44 |
|
Loezi posted:on most consumer hardware. I'm not sure I follow what the horror is. I very much hope that's the result for separate hardware threads on all x86 processors. If it were otherwise then you'd be on an x86 implementation where the logical cores share registers which is truly a horrifying concept, and if not strictly physically impossible then at least extremely slow. I sure as poo poo wouldn't want to program against that platform, not to mention try to write a compiler back-end for it. For software threads I guess you could make your own operating system with some sort of "thread" that only stores the instruction pointer for context switching, and not the register state, the stack pointer or any of those other annoying little details that pollute the thread state on other, weaker operating systems. Starting one of those "threads" would be just like making a function call, but a function call that randomly explodes in the presence of interrupts or any form of concurrency.
|
# ? Sep 28, 2018 22:46 |
|
It's not a horror, but yes, x86's "strong" memory model allows a load to be reordered with an earlier store, as long as they reference different locations.
|
# ? Sep 29, 2018 00:08 |
|
I will never understand templates as long as I live.
|
# ? Sep 29, 2018 06:08 |
|
JawnV6 posted:The hardware that met your expectation would be far more horrific. I'm pretty sure they meant "EAX in thread 0 and EBX in thread 1". So they're just talking about sequential consistency, not anything horrific.
|
# ? Sep 29, 2018 06:25 |
|
Presto posted:I will never understand templates as long as I live. What's not to understand? Maybe I'll get an amusing response explaining all the ways that I'm wrong but I think templates are just a faster way of creating overloaded functions/classes for varied input types
|
# ? Sep 29, 2018 06:58 |
|
Dylan16807 posted:I'm pretty sure they meant "EAX in thread 0 and EBX in thread 1". The program as stated requires that register writes in one thread will visible when read in another thread to consistently produce any other output. Maybe that's not the intended read, I dunno. As is I'm going to go out on a limb and say that any thread implementation that successfully guarantees that behavior is going to be real horrific. I guess you could construct an esolang based on coding for concurrent threads in a shared registry space, like a more frustrating TIS-100.
|
# ? Sep 29, 2018 07:19 |
|
Loezi posted:More of a computers-are-a-horror but I was recently made aware of the fact that given an initial state of Everyone needs to learn and understand this example before they're allowed to write multithreaded code.
|
# ? Sep 29, 2018 07:27 |
|
Xerophyte posted:The program as stated requires that register writes in one thread will visible when read in another thread to consistently produce any other output. Maybe that's not the intended read, I dunno. As is I'm going to go out on a limb and say that any thread implementation that successfully guarantees that behavior is going to be real horrific. X and Y are memory locations. If you had a sequentially consistent processor, either thread0:EAX or thread1:EBX would be 1.
|
# ? Sep 29, 2018 07:39 |
|
Dylan16807 posted:I'm pretty sure they meant "EAX in thread 0 and EBX in thread 1". Dylan16807 posted:X and Y are memory locations. If you had a sequentially consistent processor, either thread0:EAX or thread1:EBX would be 1. This, pretty much. Sorry for not making my point more clear. In my defense it was plenty late where I am. Most people I know have been taught and make the assumption that processors are at least sequentially consistent. Under that assumption, in the code posted the only possible results from interleaving the instructions are (T0:EAX = 1, T1:EBX = 0), (T0:EAX = 0, T1:EBX = 1) and (T0:EAX = 1, T1:EBX = 1). Under this fairly standard assuption, it should be guaranteed that the result (T0:EAX = 0, T1:EBX = 0) is not possible. You can easily check this by enumerating the ways the intructions can be interleaved and noticing that they all end with at least one register containing a 1. However, f.ex. modern X86 and AMD64 give no fucks about that kind of logic and are happy to leave you with (T0:EAX = 0, T1:EBX = 0) if you get (un?)lucky. (EDIT: To my understanding, I'm by no means an expert) this is turn means that any mutual exclusion implementations that make the assumption of sequential consistency are not valid on these architectures either. See here for more discussion and examples: https://www.cl.cam.ac.uk/~pes20/weakmemory/cacm.pdf To me, this was a pretty big "the computers are a horror" since it makes it really hard to reason about concurrency at all. But if y'all already knew about this, maybe this is more of an educational horror then, since these kinds of things were definitively not discussed in any of my classes, and many people I've talked with were equally surprised about this. Loezi fucked around with this message at 09:21 on Sep 29, 2018 |
# ? Sep 29, 2018 09:06 |
|
poemdexter posted:Several developers, team leads, and even a lead architect were in an email chain to figure out how to deal with null values in REST api json responses. I stated my case and referenced the json spec for null. They decided that null values for json fields should be represented by the string "NA" going forward.
|
# ? Sep 29, 2018 10:16 |
|
QuarkJets posted:What's not to understand? Maybe I'll get an amusing response explaining all the ways that I'm wrong but I think templates are just a faster way of creating overloaded functions/classes for varied input types Understanding what templates are supposed to do isn't the problem. It's the loving error messages. Take this example: code:
Here's the list of errors you're going to get with gcc (this was a code golf contest winner) code:
You can't really work around this and write idiomatic C++ because the STL is the "standard template library" (you should look through the code in the STL if you really want to gag.) Like if you had a crazy feature that caused super long error messages whenever something went wrong and multiplied your compile time complexity, would you make it the underlying central theme of your standard library? The only solution, I can see, is to just write the code correctly and pray you don't make a typo or misunderstand how something is supposed to work. When I was a new developer I would see poo poo like the above all the time, but as I learned the language, it just stopped happening.
|
# ? Sep 29, 2018 12:04 |
|
Our computer architectures class covered memory consistency and coherence models, I’m surprised to hear programmers expecting sequential consistency from x86.
|
# ? Sep 29, 2018 12:10 |
|
Bruegels Fuckbooks posted:You can't really work around this and write idiomatic C++ because the STL is the "standard template library" (you should look through the code in the STL if you really want to gag.) Like if you had a crazy feature that caused super long error messages whenever something went wrong and multiplied your compile time complexity, would you make it the underlying central theme of your standard library?
|
# ? Sep 29, 2018 12:29 |
|
Loezi posted:This, pretty much. Sorry for not making my point more clear. In my defense it was plenty late where I am. I don't know a single multi-core arch that is sequentially consistent by default. Now, I am not a CPU uarch expert, but from what I know, x86/x64 actually provide some of the strongest guarantees of modern architectures. As for teaching, the course I teach (C++ 101) literally covers this in the same lecture we first tell our students about std::thread and std::atomic as a reason why the should not use anything other than memory_order_seq_cst memory order, until they have much better idea what they are doing.
|
# ? Sep 29, 2018 14:12 |
|
Xarn posted:I don't know a single multi-core arch that is sequentially consistent by default. Now, I am not a CPU uarch expert, but from what I know, x86/x64 actually provide some of the strongest guarantees of modern architectures. Mehhhh https://en.wikipedia.org/wiki/Memory_ordering#In_symmetric_multiprocessing_(SMP)_microprocessor_systems
|
# ? Sep 29, 2018 14:30 |
|
Xarn posted:As for teaching, the course I teach (C++ 101) literally covers this in the same lecture we first tell our students about std::thread and std::atomic as a reason why the should not use anything other than memory_order_seq_cst memory order, until they have much better idea what they are doing. Nobody should be using atomics at all until they have a much better idea of what they’re doing. Once they do, they should never use seq_cst. return0 posted:Mehhhh https://en.wikipedia.org/wiki/Memory_ordering#In_symmetric_multiprocessing_(SMP)_microprocessor_systems x86 absolutely has the strongest memory model of any architecture that anyone actually ever uses. Who gives a gently caress about z/Arch or weird SPARC variants? rjmccall fucked around with this message at 15:58 on Sep 29, 2018 |
# ? Sep 29, 2018 15:55 |
|
Bruegels Fuckbooks posted:Understanding what templates are supposed to do isn't the problem. It's the loving error messages. I agree that templates have really awful error messages, but even the dated RHEL 7 system compiler (g++ 4.8.5) tells you this problem flat-out after only a few lines
|
# ? Sep 29, 2018 16:50 |
|
Winter Stormer posted:I agree that templates have really awful error messages, but even the dated RHEL 7 system compiler (g++ 4.8.5) tells you this problem flat-out after only a few lines Compilers in general are pretty decent at template error diagnostics now, the main thing causing those error messages to be horribly long is because they try to be helpful and list the "potential alternatives that can't be used for this template instation" when outputting the error. Unless you're trying to do something clever with template metaprogramming, in which case, you're asking for it (just use constexpr if instead of SFINAE Edit: if you have a compiler that supports it that is).
|
# ? Sep 29, 2018 17:44 |
|
Bruegels Fuckbooks posted:Understanding what templates are supposed to do isn't the problem. It's the loving error messages.
|
# ? Sep 29, 2018 17:56 |
|
QuarkJets posted:What's not to understand?
|
# ? Sep 29, 2018 19:53 |
|
the simple cases of templates look way more complex than they are since you're not used to the syntax. SFINAE? throw me in an ocean i dont wanna deal with that nonsense
|
# ? Sep 29, 2018 20:18 |
|
What's a language with good generics?
|
# ? Sep 29, 2018 21:00 |
|
Absurd Alhazred posted:What's a language with good generics? Go, where you use a an editor extension to cut and paste code.
|
# ? Sep 29, 2018 21:05 |
|
Absurd Alhazred posted:What's a language with good generics? Haskell.
|
# ? Sep 29, 2018 21:15 |
|
Absurd Alhazred posted:What's a language with good generics? i like generics in C# the best. C#/java create generic objects on runtime and deal with all this poo poo using the best language feature in the history of language features, reflection.
|
# ? Sep 29, 2018 21:16 |
|
Rust has great generics. As easy to use as Java's, but get compiled and optimized like C++ templates. They're modeled after Haskell, but not as flexible.
|
# ? Sep 29, 2018 21:28 |
|
Scala of course. Made to combine the best bits of Haskell with the best bits of Java.
|
# ? Sep 29, 2018 22:09 |
|
Bruegels Fuckbooks posted:Understanding what templates are supposed to do isn't the problem. It's the loving error messages. This is a 7-year-old compiler. Let's take a look at the error with something a bit more recent: code:
|
# ? Sep 29, 2018 22:13 |
Absurd Alhazred posted:What's a language with good generics? Rust.
|
|
# ? Sep 29, 2018 22:27 |
|
|
# ? May 21, 2024 06:32 |
|
I guess I should tRust in the two votes for Rust! Thanks!
|
# ? Sep 29, 2018 22:37 |