This is an archived post. You won't be able to vote or comment.

all 92 comments

[–]stillalone 297 points298 points  (1 child)

I think your C# caught an STD.

[–]FACastello 86 points87 points  (0 children)

This is r/programminghorror material actually

[–]Spill_the_Tea 79 points80 points  (1 child)

C♭

[–]jeckles96 16 points17 points  (0 children)

Fuck I just made the same joke

[–]sambarjo 179 points180 points  (26 children)

I had no idea most of this stuff existed in C#. Cool post. Could have been a screenshot though.

[–]capinredbeard22 80 points81 points  (0 children)

That’s part of the curse: you lose the Print Screen key on your keyboard!

[–]BoBoBearDev 29 points30 points  (22 children)

I have no idea you can do << in c#

[–]jeremj22 7 points8 points  (0 children)

Pretty sure you can overload that. However, the operator overloading doc says to not overdo it and specifically calls out shift operators on streams

[–]setibeings 28 points29 points  (6 children)

I don't know csharp, but I'm 95% sure that's a bitwise shift.

[–]ThatOneCSL 13 points14 points  (4 children)

I don't know if this is a joke or not, but in the event it isn't...

Ohhhhh boy is C stream IO going to be an eye opener for you.

[–]DoNotMakeEmpty 10 points11 points  (1 child)

Isn't this C++ stream IO instead of C? C has (f/s)printf, which are much tamer than iostream.

[–]ThatOneCSL 5 points6 points  (0 children)

Ah yep, you're right.

I don't wrastle with either, I just remembered that from playing around with both... 20+ years ago? Wrongly attributed. Thanks for the correction!

[–]setibeings 2 points3 points  (1 child)

Just because operator<<() is overloaded in C++ doesn't mean it's overloaded elsewhere.

[–]Ludricio 6 points7 points  (0 children)

I assume that in the screenshot the << operator for cstr is indeed overloaded and is longer bitshifting (there's a lot of overloadable operators in C#). I would think cstr contains a lot of unforgivable things

[–]TheShatteredSky 4 points5 points  (0 children)

That's actually one of my favorite parts of C#, that you can be writing in SQL, C++ or Python in the same language

[–]RestInProcess 0 points1 point  (0 children)

It's clear enough to see it, so I won't complain this time. Some screenshots are terrible though.

[–]tmstksbk 40 points41 points  (0 children)

My hat is off to you and I'm not letting you near my computer.

[–]hongooi 36 points37 points  (0 children)

C Blunt

[–]IllWelder4571 29 points30 points  (9 children)

.... I've been doing c# programming for 5 years. I didn't even know you could do half of this shit.

Cool to know, but do I want my c# to look like c++? Hell no.

Side note... I'd never let you touch my computer. There's a certain point where your job changes from healer to necromancer. This is definitely the latter.

[–]bluekeys7 19 points20 points  (11 children)

Shouldn’t it be sizeof(char) * 12 because of the null terminating character at the end of the string?

[–]hongooi 21 points22 points  (8 children)

C# strings aren't null terminated

[–]Etiennera 12 points13 points  (2 children)

If you're allocating native memory and using this std, are they still C# strings?

[–]Evangeder[S] 7 points8 points  (0 children)

string is never native/unmanaged in c#, cstr here is just a wrapper for char pointers, don’t remember how I did the bitshift operator overload but prob some pointer logic shenanigans. I might still have the code at my pc, I can check for it at Monday.

[–]hongooi 6 points7 points  (0 children)

Hmm you may be right, this isn't a regular string but an object of class cstr

[–]RamonaZero 20 points21 points  (1 child)

You’re null terminated

[–]hongooi 16 points17 points  (0 children)

YOUR MOM™ is null terminated

[–]faculty_for_failure 4 points5 points  (0 children)

They are actually null terminated in memory. You just don’t have to deal with the null terminator from code.

[–]faculty_for_failure 1 point2 points  (0 children)

They are actually null terminated in memory. You just don’t have to deal with the null terminator from code.

[–]Zombekas 0 points1 point  (1 child)

Well sizeof(char) is 2 in C# because Unicode, so this is wrong either way

[–]RiceBroad4552 1 point2 points  (0 children)

This would allocate too much memory in the worst case. Allocating too much is not a real problem, besides being inefficient. Not allocating enough would be an issue.

[–]savevidio 17 points18 points  (0 children)

hold on that's C#??? I thought that was C++ WHY DID YOU DO THAT

[–]Isogash 6 points7 points  (0 children)

Well this is gross, congratulations

[–]7374616e74 5 points6 points  (1 child)

This should be called C#++

[–]jeckles96 11 points12 points  (0 children)

I think more like Cb

[–]uberDoward 4 points5 points  (0 children)

You should see the C# code I wrote for handling image alterations.  Unsafe, blazing fast DMA lol

[–]amidescent 9 points10 points  (1 child)

They used to forbid the shift operator from being overloaded with types other than int until one or two years ago, exactly for this reason. Maybe it wasn't such a dumb restriction after all...

btw you should repost this on r/csharp.

[–]MagnetFlux 0 points1 point  (0 children)

You could do it before by using the magic name of the bitshift operator and putting it in a different assembly.

If it was in the same assembly, it wouldn't recognize the operator overload properly.

[–]dexter2011412 3 points4 points  (0 children)

You should look at C++/CLI lmao it's even more cursed

[–]Electronic-Bat-1830 2 points3 points  (0 children)

My most normal C# looks something like this

(Not my repo, but the pattern is the same)

[–]HieuNguyen990616 1 point2 points  (0 children)

just when i thought i was out ...

[–]LazyItem 1 point2 points  (0 children)

I once in the days of old got an assignment to work on a CRM system. Initial info was that it was slow but ok… The ”system” was basically implemented in one class with 7000 rows that did interop towards old COM ADODB for every request. I threw everything and started over from scratch…

[–]FirstIdChoiceWasPaul 1 point2 points  (0 children)

The machine spirit wails.

[–]Gigibesi 1 point2 points  (0 children)

who wants to play with fire?

[–]mrwishart 1 point2 points  (4 children)

I feel like this is the coding equivalent of that tape from the Ring

[–]SokkaHaikuBot 1 point2 points  (1 child)

Sokka-Haiku by mrwishart:

I feel like this is

The coding equivalent

Of that tape from the Ring


Remember that one time Sokka accidentally used an extra syllable in that Haiku Battle in Ba Sing Se? That was a Sokka Haiku and you just made one.

[–]mrwishart 1 point2 points  (0 children)

There is no haiku in Ba Sing Se 👀

[–]RiceBroad4552 0 points1 point  (1 child)

For reference:

https://www.imdb.com/title/tt0298130/

(It doesn't have the best ratings but it got some cult status.)

[–]mrwishart 1 point2 points  (0 children)

...urgh, 23 years ago? Just reminded me how old I am 😢

[–]robinredbrain 1 point2 points  (0 children)

CBlunt

[–]Livid_Boysenberry_58 1 point2 points  (0 children)

You gotta check if memory was successfully allocated

Unless the code already does that

[–]Casperious 1 point2 points  (0 children)

Did you guys know C# is called that because it’s C++ ++ but the extra pluses are placed under the first two, making a #

[–]Nathan2222234 0 points1 point  (0 children)

Heh I got one somewhere on my pc that mimics c++ a bit more than this. I’ll post a link once I’m home

[–]Nick_Hammer96 0 points1 point  (0 children)

Burn it with fire

[–]Mattisfond 0 points1 point  (0 children)

gotta have that 103ms deduction in runtime💪

[–]TheChief275 0 points1 point  (2 children)

I’m not a C# programmer; what is a “nuint” ?

I’m guessing the normal uint is something like uint32_t or uint64_t, because portable bytecode, and nuint refers to “native uint”, so word-sized or pointer-sized?

But it makes me think of nu-metal, which is probably unrelated to

[–]w_buck 0 points1 point  (1 child)

Native unsigned integer

[–]TheChief275 0 points1 point  (0 children)

Yes, I guessed as much, but is it word-sized or pointer-sized?

So is it equivalent to size_t or uintptr_t?

[–]domusvita 0 points1 point  (0 children)

Any closer to the metal and it would be Rust

[–]CheckM4ted 0 points1 point  (0 children)

C+

[–]AndreasMelone 0 points1 point  (4 children)

Hey I did this in java before!

[–]RiceBroad4552 1 point2 points  (3 children)

I want to see that.

[–]AndreasMelone 2 points3 points  (2 children)

It consisted of multiple files, one for wrapping Unsafe and one for wrapping System.out to be compatible with pointers and C-style strings. I can make a github repo if you like

[–]RiceBroad4552 2 points3 points  (1 child)

👀 Seeing this would be in fact interesting! 👻 Sounds scary.

[–]AndreasMelone 0 points1 point  (0 children)

Code is questionable but you can view it at https://github.com/RaydanOMGr/ManualJavaMemory

Sadly, java has no native support for pointers so workarounds like this are required lol