How does that demonstrate that it's not generated? Almost the entire expression is from one commit, and the rest of it is from the same commit author. They absolutely could have used a tool to generate/update it.
Not tryin to devaluate volunteer job (you guys are awesome!), but I strongly believe that even early 2000's OCRs was able to easily convert this screenshot to text with no typing needed.
Well, you'd think so, but here's our bot's attempt, using ocr.space's API, which is one of the best in the world. OCR is not as reliable as you might think.
The result is often clearly better after applying simple image processing first (trying to get a neat black and white picture mostly... This post shows 50 shades of blue-greenish over blue-greyish lol)
It does better with regular prose text, but it's still not perfect, especially if the text has some non-ASCII characters in it. If you're curious, create an account on pgdp.net, it's a site where people proofread books for Project Gutenberg that have been transcribed by OCR (and obviously the images also went through preprocessing, of course).
We, the memb'rs of r/badcode, and all reddit'rs in gen'ral, art extremely erned and feeleth s'rry to learneth yond thee hadst to transcribeth such a humongous piece of code. Thy immense contribution shalt beest highly ch'rish'd f'rev'r, until death doth us parteth. This transcription shalt beest writ using golden lett'rs on the pages of hist'ry so yond, whenev'r the current gen'ration and all future gen'rations turneth though those folk, those gents receiveth incentivis'd and fir'd with enthusiasm. His/h'r highness, although this is nothing did compare to thy contribution, prithee accepteth a token of loveth and gratitude: 💐🍪🍺
Guys, this is fine. It returns false if any of the required pieces aren’t present. That’s it. It’s a simple, albeit initially confusing, pattern repeated over and over. You could make it data driven but then you’d have a performance hit and probably lose compile time checks. You could add a macro to pretty it up but that’s arguably worse. This is ok. There’s no funny business here.
Yeah, I was trying to think of a better way to do it, since it's ugly as hell, but all I can think of is a list with a loop over it, and this is almost certainly a lot faster and not that much harder to read.
I feel like writing something to check if a value exists then using that as a wrapper for each set of ors? I think performance wouldn't be hit since the compiler would likely inline the functions and it would be clearer what you were trying to do. You'd still have a bunch of elementExists() && elementExists() type things, but I'm not sure that would be an issue.
Also, checking if it's true or if it's false, could that just be done by checking if it's null? I'm not familiar with the C++ but my understanding is that it would be null if not set
There aren't any explicit true/false checks in the OP, just &&/||/!. The variables are all booleans already. You could use a function, but it wouldn't really make it that much more clear IMO. It's a bunch of pairings of (a || !b), and they all need to be true.
Yeah i was thinking this could just be some design pattern that could actually be useful that i'm simply not familiar with it. Looks weird to me but its probably pretty readable once you know how it works.
I would have written exactly this code. Check if all features for this GPU are available or not required for (what I presume is) the driver. New GPU gets a new feature? Copy last 2 lines, paste below and modify. Easy peasy.
In a language with reflection, this is very easy to solve, but in C++ I think the only option would be to change the data structures to be maps, and now you'd have to contend with all these variables being strings. That may or may not be acceptable, depending on how these get used elsewhere.
I think that would work assuming they're all bools, but some of them sound like they might be numbers. You could maybe have a corresponding variable to the one in the bitfield, but that definitely feels more complex at the very least
Right, but that's just here, elsewhere the actual value is presumably needed. Converting the actual value to a bit in a bitfield to do this big conditional then requires (possibly) just as much machinery as... this conditional!
But it really depends on the nature of the internal core and feature classes. There may be other member variables we don't want to include in that comparison.
I don't know what Dxvk is or how it relates to the data, but consider that if these are a subgroup of the variables within core.features then consider splitting features up into all of these variables listed here and just calling core.features.Dxvk and calling the == operator on that instead.
It's checking that features are either available or not required. == would check that they're either available and required or unavailable and not required, but would fail when the feature's available but not required.
I think people here (including OP) are misinterpreting this. All those fields are just mirroring the Vulkan API which the programmer(s) have no control over. What this code does is check for the availability of certain features of the API, and there's no real better way to do that in C++ than testing them one by one.
Sure, you could use some macro magic but in the end you're still going to have to list them all in a file and it'll just be less readable. So you may as well write them in plain like this, with standardized newlines and indentation that make git diffs easy to read. It may look ugly, but it's ugly code that's easy to maintain.
DirectX for Windows (because of how most drivers interpret the DX API calls) OpenGL for Linux (if you want ease of development duh)
If you want speed in Linux, you have to use Vulkan anyways. OpenGL is often treated by GPU drivers as a crappy command list without related optimisations (atleast that was avalable few years ago)
Okay yeah totally get it that if condition is bad but with every line the suspense built about what was inside that if (and else) condition and I got to the bottom and was supremely disappointed
51
u/gipp Oct 05 '21
You're sure this isn't generated? It looks generated.
50
u/SensitiveTrap Oct 05 '21
How can you copy and paste so much stuff, change a couple of things, and think "it is okay" lol
17
u/Impossible_Average_1 Oct 05 '21
To answer op's question: it is either true or false.
201
u/[deleted] Oct 05 '21
Hell, basically
83
u/egmono Oct 05 '21
Thanks, I hate it.
240
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Oct 05 '21
Image Transcription: Code (1/2)
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
78
u/shizzy0 Oct 05 '21
Guys, this is fine. It returns false if any of the required pieces aren’t present. That’s it. It’s a simple, albeit initially confusing, pattern repeated over and over. You could make it data driven but then you’d have a performance hit and probably lose compile time checks. You could add a macro to pretty it up but that’s arguably worse. This is ok. There’s no funny business here.
43
u/zed_three Oct 05 '21
In a language with reflection, this is very easy to solve, but in C++ I think the only option would be to change the data structures to be maps, and now you'd have to contend with all these variables being strings. That may or may not be acceptable, depending on how these get used elsewhere.
Any other suggestions on how you'd refactor this?
11
u/lionbryce Oct 05 '21
I get that giant and/or chain bad but how could it be better? Mapping?
8
u/ahlgun Oct 05 '21
Thought it was a stack trace lmao
8
u/OnlineGrab Oct 06 '21
I think people here (including OP) are misinterpreting this. All those fields are just mirroring the Vulkan API which the programmer(s) have no control over. What this code does is check for the availability of certain features of the API, and there's no real better way to do that in C++ than testing them one by one.
Sure, you could use some macro magic but in the end you're still going to have to list them all in a file and it'll just be less readable. So you may as well write them in plain like this, with standardized newlines and indentation that make git diffs easy to read. It may look ugly, but it's ugly code that's easy to maintain.
18
u/Jackarduino Oct 05 '21
You found a part of the yandere sim code
5
u/[deleted] Oct 05 '21
at least it’s logical ands instead of and
2
u/[deleted] Oct 05 '21
I don't think I will ever start using Vulkan
1
u/ellamoosella Oct 05 '21
Machine generated...hopefully
1
u/LordDerptCat123 Oct 06 '21
Is this graphics API related? I’m new but I recognise a couple things
1
u/TheEmeraldFalcon Oct 09 '21
So from the name, DirectX to Vulkan converter of some kind?
2
u/kiwidog8 Oct 05 '21
At first glance I thought it was a very long python stacktrace
5
u/[deleted] Oct 05 '21
This is the first time looking at a conditional made me immediately burst out laughing 🤣
This is the absolute epitome of brittle code
1
u/Useful_Bug_67 Oct 06 '21
Okay yeah totally get it that if condition is bad but with every line the suspense built about what was inside that if (and else) condition and I got to the bottom and was supremely disappointed
1
u/Alone_Frame_4807 Oct 05 '21
A lot of statements.
1
u/deftware Oct 06 '21
That would be your worst nightmare.
1
u/babnabab Oct 06 '21
Well at least Nord makes it look pretty
1
u/Thrasherop Oct 06 '21
Bro did they make a script to write that code
1
u/Hamty_ Oct 06 '21
You know your code is bad when it looks like a stack-trace
1
u/Upset-Variety Oct 06 '21
What the hell is this
1
u/PulseBeat_02 Oct 06 '21
It looks bad when I don’t click on the image.
After I clicked on it and the image expanded, I knew it was gonna look like hell.
1
u/Shantarli Oct 07 '21
As an artist, I find it incredible, it can be easily placed on the wall.
0
u/doitaljosh Oct 05 '21
That's got to be generated by some high level IDE. There's no way a human could deliberately check that many conditions in a single return statement.
0
u/chestera321 Oct 05 '21
I looked full image unfortunately, now I wanna unsee that from my memory
0
u/KDallas_Multipass Oct 05 '21
This screams for a macro
0
u/sohang-3112 Oct 06 '21
If this is C++, then we can use a 32-bit bit field here, where each property takes 1 bit. Then, this function becomes simply:
x == 1<<31 && y == 0where x is all properties of device_features (in a bit field), y is same as above, except for required .
-4
u/richhaynes Oct 05 '21
That is.... a sackable offence.
-1
u/Beentage Oct 06 '21
At least use a karnaugh map to reduce this Boolean expression
-1
u/JonMW Oct 06 '21
I don't know what they are trying to do.
I definitely don't know how to do whatever it is that they're trying to do.
I'm still reasonably certain that that is not the right way to do it.
0
u/[deleted] Oct 05 '21
[deleted] — view deleted comment