ProgrammerHumor

cursedCsharp

cursedCsharp

Old photo of mine, tried my best to do most cursed hello world in C#

https://i.redd.it/jew9forvmpdf1.jpeg
Reddit

Discussion

stillalone

I think your C# caught an STD.

1 day ago
Evangeder OP
:cs:

r/angryupvote

1 day ago
FACastello
:c::cp::cs::j::js::ts:

This is r/programminghorror material actually

1 day ago
Spill_the_Tea

C♭

1 day ago
jeckles96

Fuck I just made the same joke

1 day ago
sambarjo
:cp: :cs:

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

1 day ago
capinredbeard22

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

1 day ago
BoBoBearDev

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

1 day ago
setibeings
:rust::cp::js::ru::ts::j:

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

1 day ago
otac0n
:cs::ts::js::powershell::re::lua:

It's overloadable, just like in C++

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/operator-overloading#overloadable-operators

13 hours ago
ThatOneCSL

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.

1 day ago
DoNotMakeEmpty
:c::lua:

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

1 day ago
ThatOneCSL

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!

1 day ago
setibeings
:rust::cp::js::ru::ts::j:

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

23 hours ago
Ludricio
:c::p::cs::ts:

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

16 hours ago
jeremj22

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

20 hours ago
Temporary_Equal_1821

Many languages support operator overloading, a form of polymorphism. I've never worked with C# (thankfully), but that's how << works with output streams (e.g., cout) in C++.

1 day ago
joske79

What is it you don't like about C#?

1 day ago
CreepyDadd

I agree, too many C# haters. From someone who has coded in, Java, C, C++, ObjectiveC++, Swift, JS and C#. C++ and C# are tied first for my favorite languages to code in

1 day ago
Narfi1

If you do enterprise software, there is nothing better than modern C#

20 hours ago
RiceBroad4552
:s:

That must be the reason why almost all enterprise software runs on the JVM…

(Yes, there are some companies very deep in M$ ass who in fact use C# for their internal Sharepoint / ASP development, but that's thankfully the big exception by now.)

20 hours ago
Dealiner
:cs:

That must be the reason why almost all enterprise software runs on the JVM…

"Almost all" being a huge stretch here.

17 hours ago
Narfi1

Right, because enterprises are known for low inertia and always make sure to refactor the codebase and not have a bunch of legacy projects

Also, Php is the best web backend language since it powers most of the web

20 hours ago
cherrycode420

You should try C# if you have some use case and you'd like a pleasant development experience, assuming you can use Visual Studio or Rider. the Language itself is really great, it's just some frameworks and projects that are not fun to use or work at, but to be fair, every language has those

22 hours ago
TheShatteredSky

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

23 hours ago
RestInProcess

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

22 hours ago
tmstksbk

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

1 day ago
hongooi
:r::cp:

C Blunt

1 day ago
IllWelder4571

.... 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.

1 day ago
RiceBroad4552
:s:

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

I've used C# once a little bit in a side project.

I knew all the stuff shown in this screenshot (and I know quite some more).

So I'm wondering: What do people actually do when they claim to "learn" a language?

Not even once skimming the docs? (Especially as C# docs aren't even such bad. Had to work with orders of magnitude worse stuff in the past.)

20 hours ago
IllWelder4571

They learn what a language is best at, and in c#'s case it's absolutely not this. If I needed to use the functionality depicted by the op I'd use c++ instead. As that sort of thing is exactly what it's best at.

C# shines at being simplistic and non-cryptic. If you used it once in a side project and ended up doing stuff like the op.... You were using it in a way that goes against its strengths.

20 hours ago
HMS-Fizz

But any c# fundamentals course would go over manual memory allocation and pointers?

9 hours ago
PLEXT0RA
:cs::cp::js:

C# is actually a pretty good option for working with lower level stuff, but its not as flexible as C++

18 hours ago
Alternative-Ebb-2549

It was literally designed to avoid that. The fact that to use pointers you have to mark the code as unsafe says all you need to know about the design philosphy of C#.

11 hours ago
PLEXT0RA
:cs::cp::js:

I meant to say decent in that comment since its not actually that good for things like systems development, but if you're working with the windows api for example its better than most other languages.

11 hours ago
IllWelder4571

Yeah I can agree it's possible and not necessarily horrible at doing that kind of thing.I just wouldn't recommend doing it, especially when there's a much better tool (c++) available for that purpose.

It goes back to that "use the right tool for the job" saying. Sure, for most people that just means "whatever you're most familiar with" but even though I'm most familiar with c# I still wouldn't lol.

My go to is use c# for everything except for instances where low level control / performance is needed. Use C++ for those specific portions. Granted most of my work is web based, so I hardly ever need c++. There have been a couple multi-threaded report builders that absolutely benefitted from c++ over c#.

Something that took 8 hours to pour over millions of records got knocked down to about 3 and a half with that change. I don't doubt I could have made it better in c# if I had taken that dive but it's an issue of knowing it can be made vastly faster vs a maybe + more time learning.

11 hours ago
maqcky

You don't need to do unsafe stuff in C# in most applications, so there is no need of learning any of this. Especially nowadays, with Span, you can have pretty efficient "low level" memory management if you want to, without the risks of manual allocations.

6 hours ago
bluekeys7

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

1 day ago
hongooi
:r::cp:

C# strings aren't null terminated

1 day ago
Etiennera

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

1 day ago
hongooi
:r::cp:

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

1 day ago
Evangeder OP
:cs:

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.

1 day ago
RamonaZero

You’re null terminated

1 day ago
hongooi
:r::cp:

YOUR MOM™ is null terminated

1 day ago
faculty_for_failure
:cs::c::ru::py::ts:

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

1 day ago
faculty_for_failure
:cs::c::ru::py::ts:

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

1 day ago
Zombekas

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

21 hours ago
RiceBroad4552
:s:

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.

20 hours ago
savevidio

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

1 day ago
Isogash

Well this is gross, congratulations

1 day ago
uberDoward
:cs::cp::py::ts::powershell::asm:

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

1 day ago
7374616e74

This should be called C#++

1 day ago
jeckles96

I think more like Cb

1 day ago
amidescent

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.

1 day ago
MagnetFlux

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.

3 hours ago
dexter2011412
:cp::py::rust:

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

1 day ago
Antlool
:cp::c::rust::asm:
#include <stdio.h>
#include <stdlib.h>

__SLONG32_TYPE main(void) {
  __uint8_t* str = (__uint8_t*)malloc(11);
  __u_char i = *str^*str;
  __U64_TYPE l = 4946144450195624;
  void** poi = (void*)malloc(1<<4);
  *poi = &&is; *(poi+1) = &&not;
  is: *(str+i) = (char)((l&31|64)%95+32);
  l>>=5; goto **(poi+(!(++i^11)));
  not: puts((const char*)str); free((void*)str); free(poi);
  return 0xe&(1<<0x1b);
}

tested it and works (C)
edit: probably made it gcc-only but it's even more cursed now (thanks goto)
edit 2: the hardcoded string isn't as readable now, it's getting worse

23 hours ago
RiceBroad4552
:s:

Dear kids reading that, don't do that at home.

20 hours ago
Electronic-Bat-1830
:cs::cp::ts::powershell:

My most normal C# looks something like this

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

1 day ago
LazyItem

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…

1 day ago
FirstIdChoiceWasPaul

The machine spirit wails.

1 day ago
mrwishart
:cs:

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

1 day ago
SokkaHaikuBot

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.

1 day ago
mrwishart
:cs:

There is no haiku in Ba Sing Se 👀

1 day ago
RiceBroad4552
:s:

For reference:

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

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

20 hours ago
mrwishart
:cs:

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

19 hours ago
robinredbrain

CBlunt

23 hours ago
Livid_Boysenberry_58

You gotta check if memory was successfully allocated

Unless the code already does that

22 hours ago
Casperious

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

19 hours ago
HieuNguyen990616

just when i thought i was out ...

1 day ago
Gigibesi

who wants to play with fire?

1 day ago
Nathan2222234
:unity::cs:

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

16 hours ago
AndreasMelone

Hey I did this in java before!

1 day ago
RiceBroad4552
:s:

I want to see that.

20 hours ago
AndreasMelone

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

20 hours ago
RiceBroad4552
:s:

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

13 hours ago