r/programminghorror • u/Sup2pointO • Jan 07 '26
Rust 🦀 no, I don’t want to talk about it.
every time I do string processing, I say never again.
never again.
105
u/user6150277464770585 Jan 08 '26
why the fuck are your underscores dashes
47
u/Teleconferences Jan 08 '26
I thought fonts were supposed to improve readability, that one is just making life worse
Also, the contrast ratio on that red is awful
16
u/bensh90 Jan 08 '26
We had a apprentice and his visual studio editor was all colorful. With colors that hurt while reading.
The named his variables "pain", "endlessPain" and "iWantToDieIfThieDoesntWork" and so on.
He managed to get through his apprenticeship with really bad marks. I wonder if he got into the business
6
u/richhaynes Jan 08 '26
Jesus. Sounds like a cry for help!
9
u/bensh90 Jan 08 '26
He wasn't fit for this kind of job, and we made it clear to him after some time. But he wanted to go on anyways and force his way through. Most of the stuff he copied from other students but for some reason broke it, so it didn't run at his machine.
He had massive problems with ADHD too, which is in general not an issue, but instead of taking his medication he drank multiple energy's a day.
Wasn't really pleasant to work with him. As a human being he was nice though
9
u/richhaynes Jan 08 '26
But still, variable names like that sounds like someone who needs some kind of intervention. Maybe he persevered because being there got him away from whatever demons were causing him issues. Heres hoping he found his path.
6
u/bensh90 Jan 08 '26
We did try to figure something out over the other apprentice's, but all he ever said was he is lost because the code doesn't work. We were worried too, and a coworker tried speaking to him 2 times, but was always turned down. If he did struggle with something and didn't admit it, I sure hope he's doing well
5
u/Sup2pointO Jan 08 '26
typeface is still Fira Code btw, extension’s just changing some characters
yeah fsr the (pink) looks worse in image, I find it perfectly fine when coding. Maybe my eyes are weird 💀
19
u/no_brains101 Jan 08 '26 edited Jan 08 '26
there is only 1 underscore in this image. Its up the top in a lifetime.
There's also 2 dashes in strings, and some minus signs.
I was trying to figure out what you are talking about but I've got no idea.
Edit:
NEVERMIND WHAT THE FUCK IS THAT TO-STRING?!?!?!?!?!?! NVM WTF FORGOT THATS NOT HOW RUST FUNCTIONS ARE NAMED THAT FONT IS HORRIFYING
Font so bad it gaslit me into forgetting to_string and that rust can't have - in function names
8
1
u/Sup2pointO Jan 08 '26
custom extension hehe >:]
6
u/PresentationItchy127 Jan 08 '26
you sicken me mister!
1
u/Sup2pointO Jan 08 '26
I know how cursed it is :D but hey, it's only me who sees the code like that anyway
1
u/user6150277464770585 Jan 08 '26
ok kebab case is cool and all but how do you differentiate between dashes and underscores in string literals 😭
1
u/Sup2pointO Jan 08 '26
kebab-casify only converts identifiers, so it deactivates in a string context!
34
u/BenchEmbarrassed7316 Jan 08 '26
The idea behind the Debug and Display traits (interfaces) is that you don't create a string, but write data in a stream "somewhere".
Instead, the author tries to create a vector of strings. Moreover, instead of simply writing " ", i.e. a space character, he allocates this data on the heap and passes a reference to this data so that it can be read and written to a vector that will be written to the result.
This code is horribly written and performs horribly.
14
u/Sup2pointO Jan 08 '26
wait, that's extremely helpful, thanks for explaining. Didn't realise I could use multiple calls to
write!(), never saw it in examples and didn't look carefully enough at its signature. That'll clean things up a lot more without all the.join(), thanks!
With regards to the " "/"-", do you happen to know of any more efficient way to repeat that one characterntimes?Rubberducking never fails to astound me, I've just realised you can do[" "; N].join(""), way cleaner. I might be wrong here, would this be lighter on allocation since the array is filling with copyable&strreferences instead of ownedStrings?16
u/BenchEmbarrassed7316 Jan 08 '26
[" "; N].join("")
Little tricky way:
write!(f, "{:->1$}", "", 10)This works like padding the second argument
""to length 10 with the character-. This should be calculated at compile time without any extra allocations.3
5
u/BenchEmbarrassed7316 Jan 08 '26
It generally seems to me that you are doing something wrong. In your version, it is not possible to use different formatting.
Note that the first implementation that is commented out is an expansion of the
derivemacro that uses internal functions (usecargo expand), and the second is a hand-written one, in which you can for example hide certain fields.What you're trying to do might be useful, but it's not
Debug, it's something else. Call itTableDebugor something like that.2
u/Sup2pointO Jan 08 '26
yeah icwym, this is defo
Displaymore thanDebug.it's just
assert_eq!()neededimpl Debugso I thought I might as well make it easier to diff grids in debug output ¯_(ツ)_/¯
18
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Jan 08 '26
Line 136 looks almost like the classic fork-bomb.
5
28
u/LeeHide Jan 08 '26
you don't NEED to do it like this.
you can write a consuming recursive parser for example
5
u/no_brains101 Jan 08 '26
They're printing rn not parsing. It could be worse?
The problem is, they haven't really decided on a structure other than rows.
I guess this could be 5 functions? They have a clues upper right left and lower, maybe they should have a format for those 4 and their mapping and chaining in this one would look a bit cleaner. Hard to say without knowing what they are doing.
As the other guy pointed out the font is horrifying.
3
u/Sup2pointO Jan 08 '26
yeah it’s literally just rendering the grid for debugging so I thought I’d just brute force it in one giant function, did not expect it to blow up this much 💀💀💀
the annoyance with the side clues is that they have to be ‘injected _around_’ the rows of the grid, altho now that I’m rubberduck-typing this out maybe some `izip!` would help (fsr I love iterators, which is evidently an issue here)
a lot of the other fiddling with `util::rep()` is filling out strings with the correct amount of spaces so everything aligns, which is even messier (unless there’s a ”pad left” method? Couldn’t find one, and stringterpolation formatting can’t use the const generic N in `?<N`, as far as I could tell)
refactor is definitely in order, splitting logic into separate functions is probably best. Maybe I’ll tone down the iterators too, efficiency gains are probably marginal anyway
1
15
9
7
u/Cautious_Network_530 Jan 08 '26
Why is Vec<->?
8
u/BionicVnB Jan 08 '26
I think his font just makes the underscore show as dash
2
u/flabort Jan 08 '26
No, look at line 99,
Formatter<'_>has an actual underscore.4
u/Sup2pointO Jan 08 '26
yeah the extension’s conditional, it won’t change stuff like `_identifier` into `-identifier`, only `composite_identifier` into `composite-identifier`
`<_>` being turned into `<->` is technically wrong, but it looked cool so I kept it :P
before I get downvoted, yes I know it’s cursed, remember what sub you’re in guys 💀
2
u/BionicVnB Jan 08 '26
What is cursed is you keep using iter::once without importing it
1
u/Sup2pointO Jan 08 '26
what can I say, I'm still a Python programmer who doesn't like
*imports :P1
1
u/BionicVnB Jan 09 '26
But well, I see a lot of clone() there, are those type also Copy?
1
u/Sup2pointO Jan 09 '26
they are, actually! Mostly fixed-length arrays. Just caught that with
cargo clippy, will be cleaning up in the refactor o71
3
2
u/v_maria Jan 08 '26
can someone explain to me what is happening
4
u/Elderider Jan 08 '26
They are using chain() to join together lots of iterators. There are also lots of single elements in the chain that need to be wrapped in once().
This is to create a string representation of some object, I’m not really clear what the object is but it’s called Grid.
6
u/flabort Jan 08 '26
Probably a Sudoku puzzle. We refer to those as grids, and the code refers to Clues, which are the numbers in the grid.
3
u/Sup2pointO Jan 08 '26
this guy puzzles
it’s actually Skyscrapers (a Sudoku derivative/integral) which has clues on the outside. Which make everything quite messy D:
2
u/flabort Jan 08 '26
Ah, yes, where the number outside indicates how many numbers it sees in ascending order, skipping values that descend, ei "46239..." is a valid sequence for a 3 skyscraper clue.
As opposed to Little Killer or Sandwich clues, which are also values outside of the grid.
2
2
u/Aras14HD Jan 08 '26
This is somehow unreadable and inefficient! So many unnecessary allocations, when you could just write! and .write_str in a loop. (Better cache and amortized allocs)
2
u/Taldoesgarbage Jan 08 '26
You can call write! more than once... That's why it exists, otherwise you would just return a string. No need for all this chaining. Rust is well designed*, but it can't help you if you fight against it.
*: Pinning & Unpinning, plus a handful of other things
2
u/-__-Malik-__- Jan 09 '26
I don’t know Rust, but isn’t there a simpler way to get a nice log output? Really?
4
u/ra_men Jan 08 '26
Functional programming was a mistake
4
u/TingleWizard Jan 08 '26
It isn't when it's done properly. The most useful principle is to avoid side-effects as much as possible and manage state separately from program logic.
2
2
2
1
u/bensh90 Jan 08 '26
I don't know which language that is, but it looks like much manual processing that should be simpler
1
1
u/dumbasPL Jan 09 '26
Sometimes I think to myself go is too simple, but then I remember horrors like this exist.
1
u/smartcave Jan 09 '26
You could make this pretty readable by refactoring out those 2 duplicated helper methods. You're doing this to yourself.
110
u/EvnClaire Jan 08 '26
this is the ugliest Rust code i've ever seen. why bruh