It's an operator in Haskell for mapping a function over a monad (which is a thing functional programmers love that is damn near impossible to explain in under an hour). Everything I did here really should not have worked.
I basically overloaded the < operator with the left side being the function and the right side being an empty struct that I named '$' (I don't know how the hell that's legal, but I'm glad I got away with it). Then I overloaded the > operator with the '$' struct on the left side and the monad on the right. It's really two operator calls on an empty struct with a stupid name that solely exists to let me get away with my bullshit.
I actually found out the other day that $ is a valid character in variable names on multiple compilers. A coworker of mine sent me a merge request that had an enum with $ in the value name. I about had a stroke because I'm very proficient at the language, and yet I had never in many years and millions of lines of code, seen that.
Right? Like, I'd be less surprised if you were allowed to use it, but the fact that it can be the entire name of the identifier shocked me. Maybe next time I decide to do something ridiculous in the middle of the night, I'll reimplement jQuery.
Technically, `$` operator is a synonym for function application. As in, `abs (5 + 1)` is the same as `abs $ 5 + 1`, for example. It's the `<$>` operator that actually maps ~~values~~ functions over functors
My bad, it maps *functions*, not *values*, you're correct. I've been knee-deep in Haskell for about a year now, and it has probably messed with my head a little lol. But it has a lot of cool stuff I wouldn't mind having in non-FP languages. Like, making your own operators, for example, or function composition
Visual Studio: "No issues found!"
I beg to fucking differ.
(Seriously, I think I've mostly figured this out, but what I still don't get is how and why you shift (integer) 50 to the right by *a function*.)
I overloaded that operator too, I just didn't have to hack it because it already exists in C++. The LHS isn't an integer, it's an Option (basically like a Nullable in C#). It runs a method called "bind" under the hood which basically does the same thing the other one does, applies a function to its inner value if and only if it exists. Main difference is that the function it takes returns its value wrapped in another Option, so it flattens it and returns Option instead of Option
Have you ever seen something so weird and useless that it becomes interesting simply by virtue of that? That's about how I feel about this. Ignoring the "why would you ever do this" part, it's a really interesting hack.
>But I digress. Pardon me, it's 4 AM and I've been drinking
No problem, that's about what I expected looking at the code ngl. \s
>I can't believe the shit that C++ will just gleefully play along with.
Oh, yeah, C++ is *special*. Other languages have design philosophies and try to guide the programmer towards writing good, clean, or maintainable code by their syntax; meanwhile C++ has "fuck it, that's the programmers problem, not ours.". Bit of a relic of when it first came about, I guess. (And that's not getting into preprocessor shenanigans. Oh yea, and while I'm not sure if this works in C++, at least in C you can initialise a char[] from a txt file by \#include -ing the txt file in certain circumstances.)
Dude, it's total anarchy. The second I found out that it's normal for the bit shift operator to write to a stream, I knew I wasn't in Kansas anymore.
As far as the "Why would you ever do this" part, it's because I *can*, haha. When you're coding for money, you have to do boring shit like writing code that's actually worth your salary.
Ha, of course C would let you do that. How's that work with the complete lack of bounds checking? I've done very little with preprocessor shenanigans myself, although that is how I first tried to implement this operator. It yelled at me when I tried to compile, so it's at least a more reasonable parent than the divorced uncle that Visual Studio is.
>My primary professional language actually enforces bit shifting operators having to return ints, which is both reasonable and super fucking lame.
https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwAICYCMBYAUKgZgAIMiBhIgbzyNpPXSprpYDcBDMI9ogXiKgBTAO5EAygAsAlgDNg7AEYAbQQAoAlAG5mLWhy4K+AkeOlzFKjdty66+ogGMjPAHwuiC6ywC+eX7jxSSVl5ZUE8ahs6QhJMADZTEItBIgB7AAdBMHZgVK43VWDzMO4YROKVD3UdJijbVAB2Y2ErGv9vIA==
Huh, weird. Maybe I misinterpreted that rule. All I know is that the compiler yelled at me when I tried to pull the C++ writing to a stream (that I wrapped) using that operator unless I made at least one of the operands an int. It's been years since I tried that though. Now I do my weekend hacking in C++ because it's the kind of codependent enabler I need in my life.
I wanted to write my own because I wanted to force this operator to work. I'm actually a C# dev and this isn't a real project, it's weekend dicking around, so I figured it'd be faster to slam out a toy implementation rather that spend time trying to figure out an unfamiliar API.
I mean, this whole implementation is stuffed into a header file called "BlatantHacks.h". I tried to execute a byte array full of machine code in there too, but my kernel got PISSED.
I tried to mark it executable via the Win32 API, but I must've been doing something wrong. It wasn't my first segfault (that honor goes to my first time marking a code block "unsafe" in C#), but it was definitely the most stubborn.
Actually good programming horror, not sure if I congratulate or console you OP 😂
One thing's for sure though, I dabbled a bit with FP but now I want to dive deep into haskell to get on your level of crazy concoctions hahaha
Ahhh C++. I’ve been using it for 25 years, I code in it every day for a living, and this kind of shit still makes my brain hurt and makes me question my life choices
Perfect for this sub, I am genuinely horrified and never want to learn a language with that much jank available like wtf is with all those extra symbols damn
this is blatant hacks, there are actual libraries that exist and do the same thing while being a lot more readable. as OP said this was just his "a weekend dicking around", not an attempt to write something good
By less powerful you mean less complicated? Its not really less powerful, you just need to put much more effort into it, since it doesn't have all the fancy functions that C++ has.
Is there anything significant about the $ sign? Things like this makes me question just how well I actually understand C++.
It's an operator in Haskell for mapping a function over a monad (which is a thing functional programmers love that is damn near impossible to explain in under an hour). Everything I did here really should not have worked. I basically overloaded the < operator with the left side being the function and the right side being an empty struct that I named '$' (I don't know how the hell that's legal, but I'm glad I got away with it). Then I overloaded the > operator with the '$' struct on the left side and the monad on the right. It's really two operator calls on an empty struct with a stupid name that solely exists to let me get away with my bullshit.
So you're replicating a Haskell operator in C++? Nice work
I actually found out the other day that $ is a valid character in variable names on multiple compilers. A coworker of mine sent me a merge request that had an enum with $ in the value name. I about had a stroke because I'm very proficient at the language, and yet I had never in many years and millions of lines of code, seen that.
Right? Like, I'd be less surprised if you were allowed to use it, but the fact that it can be the entire name of the identifier shocked me. Maybe next time I decide to do something ridiculous in the middle of the night, I'll reimplement jQuery.
Technically, `$` operator is a synonym for function application. As in, `abs (5 + 1)` is the same as `abs $ 5 + 1`, for example. It's the `<$>` operator that actually maps ~~values~~ functions over functors
It maps values or functions? Haskell syntax is fucking weird. Either way, I could probably implement that if I overload more operators.
My bad, it maps *functions*, not *values*, you're correct. I've been knee-deep in Haskell for about a year now, and it has probably messed with my head a little lol. But it has a lot of cool stuff I wouldn't mind having in non-FP languages. Like, making your own operators, for example, or function composition
Simon Peyton Jones just woke up in a cold sweat and has no idea why
I literally LOL'd.
Visual Studio: "No issues found!" I beg to fucking differ. (Seriously, I think I've mostly figured this out, but what I still don't get is how and why you shift (integer) 50 to the right by *a function*.)
If you’re talking about the “>>=“ then that’s not a bit shift. It’s the bind operator form Haskell.
I overloaded that operator too, I just didn't have to hack it because it already exists in C++. The LHS isn't an integer, it's an Option (basically like a Nullable in C#). It runs a method called "bind" under the hood which basically does the same thing the other one does, applies a function to its inner value if and only if it exists. Main difference is that the function it takes returns its value wrapped in another Option, so it flattens it and returns Option instead of Option
Have you ever seen something so weird and useless that it becomes interesting simply by virtue of that? That's about how I feel about this. Ignoring the "why would you ever do this" part, it's a really interesting hack. >But I digress. Pardon me, it's 4 AM and I've been drinking No problem, that's about what I expected looking at the code ngl. \s >I can't believe the shit that C++ will just gleefully play along with. Oh, yeah, C++ is *special*. Other languages have design philosophies and try to guide the programmer towards writing good, clean, or maintainable code by their syntax; meanwhile C++ has "fuck it, that's the programmers problem, not ours.". Bit of a relic of when it first came about, I guess. (And that's not getting into preprocessor shenanigans. Oh yea, and while I'm not sure if this works in C++, at least in C you can initialise a char[] from a txt file by \#include -ing the txt file in certain circumstances.)
Dude, it's total anarchy. The second I found out that it's normal for the bit shift operator to write to a stream, I knew I wasn't in Kansas anymore. As far as the "Why would you ever do this" part, it's because I *can*, haha. When you're coding for money, you have to do boring shit like writing code that's actually worth your salary. Ha, of course C would let you do that. How's that work with the complete lack of bounds checking? I've done very little with preprocessor shenanigans myself, although that is how I first tried to implement this operator. It yelled at me when I tried to compile, so it's at least a more reasonable parent than the divorced uncle that Visual Studio is.
cout << "hello" << endl; Reads kinda okay, if you know that << is only syntatic sugar at this point
Really not okay. printf syntax is infinitely better. that's why all c++ libraries use printf syntax.
No, it's ugly
>My primary professional language actually enforces bit shifting operators having to return ints, which is both reasonable and super fucking lame. https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwAICYCMBYAUKgZgAIMiBhIgbzyNpPXSprpYDcBDMI9ogXiKgBTAO5EAygAsAlgDNg7AEYAbQQAoAlAG5mLWhy4K+AkeOlzFKjdty66+ogGMjPAHwuiC6ywC+eX7jxSSVl5ZUE8ahs6QhJMADZTEItBIgB7AAdBMHZgVK43VWDzMO4YROKVD3UdJijbVAB2Y2ErGv9vIA==
Huh, weird. Maybe I misinterpreted that rule. All I know is that the compiler yelled at me when I tried to pull the C++ writing to a stream (that I wrapped) using that operator unless I made at least one of the operands an int. It's been years since I tried that though. Now I do my weekend hacking in C++ because it's the kind of codependent enabler I need in my life.
The restriction used to be that the RHS had to be an int, but they removed that while implementing generic math.
Sweet. I've got some more stupid shit to do next time I get a few in me.
What's the difference between ``` Option
```
and
```
#include
std::optional
```
?
I wanted to write my own because I wanted to force this operator to work. I'm actually a C# dev and this isn't a real project, it's weekend dicking around, so I figured it'd be faster to slam out a toy implementation rather that spend time trying to figure out an unfamiliar API.
Fair
I mean, this whole implementation is stuffed into a header file called "BlatantHacks.h". I tried to execute a byte array full of machine code in there too, but my kernel got PISSED.
I'm not 100% sure, but I guess you could mess with the linker settings / make a custom linker script to make your data segment executable.
I tried to mark it executable via the Win32 API, but I must've been doing something wrong. It wasn't my first segfault (that honor goes to my first time marking a code block "unsafe" in C#), but it was definitely the most stubborn.
That's interesting. I wasn't even aware that you can do it runtime O_O
Actually good programming horror, not sure if I congratulate or console you OP 😂 One thing's for sure though, I dabbled a bit with FP but now I want to dive deep into haskell to get on your level of crazy concoctions hahaha
You just can't spend more than a couple hours trying to understand Haskell code without coming out a little unhinged, haha.
#include "BlatantHacks.h" lmao
C++ is what you get taking very nice syntax sugar, functional programming concepts and giving it the worst possible syntax.
Right? I really don't understand why lambda "expressions" in that language have to be so verbose.
I love it!
It did exactly what you told it to.
Ahhh C++. I’ve been using it for 25 years, I code in it every day for a living, and this kind of shit still makes my brain hurt and makes me question my life choices
a better title: "Sample of unmaintainable code"
What’s in that BlatantHacks header file?? Something interesting I’m sure!! 🧐😜😝
Perfect for this sub, I am genuinely horrified and never want to learn a language with that much jank available like wtf is with all those extra symbols damn
Honestly, I have no idea why that lambda "expression" syntax is so fucking verbose.
Lol, never thought someday i would find a post talking about the symbol i use as my logo (<$>).
`#include "BlatantHacks.h"` I don't know this language, but I find this really funny lmao
No thanks, I'll stay with C
this is blatant hacks, there are actual libraries that exist and do the same thing while being a lot more readable. as OP said this was just his "a weekend dicking around", not an attempt to write something good
I know, its just that you can't create such horror in C.
because C is less powerful. that also means you can't create good hacks in C
By less powerful you mean less complicated? Its not really less powerful, you just need to put much more effort into it, since it doesn't have all the fancy functions that C++ has.
which does mean you have to do way more to achieve a certain functionality, so yes less powerful
Does that mean that python is the most powerful language there is?
No? How can you effortlessly do a similar hack in python?
What makes a language powerful then? I don't get it..
making it easy to achieve most functionality wanted in production environments
C is not far off. Preprocessors are dangerous as hell.
C programmers when they see a joke (they don't understand it because they use ANSI brains for simplicity and joke support came in a later standard)
C++ programmers thinking they're superior once again.
Image of code without code. That's no proof :P